Revision 51986
Added by Sofia Baltzi about 6 years ago
ForgotPasswordServlet.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.openaire.usermanagement; |
2 | 2 |
|
3 | 3 |
import com.unboundid.ldap.sdk.LDAPException; |
4 |
import eu.dnetlib.openaire.user.utils.EmailSender; |
|
5 |
import eu.dnetlib.openaire.user.utils.LDAPActions; |
|
6 |
import eu.dnetlib.openaire.user.utils.VerificationActions; |
|
7 |
import eu.dnetlib.openaire.user.utils.VerifyRecaptcha; |
|
4 |
import eu.dnetlib.openaire.user.utils.*; |
|
8 | 5 |
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor; |
9 | 6 |
import org.apache.commons.validator.routines.EmailValidator; |
10 | 7 |
import org.apache.log4j.Logger; |
... | ... | |
62 | 59 |
if (formEmail == null) { |
63 | 60 |
request.getSession().setAttribute("message", "Error reading email."); |
64 | 61 |
response.sendRedirect("./forgotPassword.jsp"); |
65 |
} else if (formEmail.isEmpty()) { |
|
66 |
request.getSession().setAttribute("message", "Please enter your email."); |
|
67 |
response.sendRedirect("./remindUsername.jsp"); |
|
68 |
|
|
62 |
} else if (formEmail.isEmpty()) { |
|
63 |
request.getSession().setAttribute("message", "Please enter your email."); |
|
64 |
response.sendRedirect("./remindUsername.jsp"); |
|
69 | 65 |
} else if (!EmailValidator.getInstance().isValid(formEmail)) { |
70 |
request.getSession().setAttribute("message", "Please enter a valid email."); |
|
71 |
response.sendRedirect("./remindUsername.jsp"); |
|
72 |
|
|
66 |
request.getSession().setAttribute("message", "Please enter a valid email."); |
|
67 |
response.sendRedirect("./remindUsername.jsp"); |
|
73 | 68 |
} else if (!VerifyRecaptcha.verify(gRecaptchaResponse, secret)) { |
74 | 69 |
request.getSession().setAttribute("message", "You missed the reCAPTCHA validation!"); |
75 | 70 |
response.sendRedirect("./remindUsername.jsp"); |
76 |
|
|
77 | 71 |
} else { |
78 |
|
|
79 | 72 |
try { |
80 |
|
|
81 | 73 |
String username = ldapActions.getUsername(formEmail); |
82 | 74 |
if (username == null || username.isEmpty()) { |
83 |
request.getSession().setAttribute("message", "User does not exist.");
|
|
75 |
request.getSession().setAttribute("message", "There is no user registered with that email.");
|
|
84 | 76 |
response.sendRedirect("./forgotPassword.jsp"); |
85 |
|
|
86 | 77 |
} else { |
87 | 78 |
UUID verificationCode = UUID.randomUUID(); |
88 | 79 |
Date creationDate = new Date(); |
... | ... | |
120 | 111 |
} catch (LDAPException ldape) { |
121 | 112 |
logger.error("LDAP error", ldape); |
122 | 113 |
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp")); |
123 |
|
|
124 | 114 |
} catch (MessagingException e) { |
125 | 115 |
logger.error("Error in sending email", e); |
126 | 116 |
request.getSession().setAttribute("message", "Error sending email."); |
127 | 117 |
response.sendRedirect("./forgotPassword.jsp"); |
128 | 118 |
} |
129 | 119 |
} |
130 |
|
|
131 | 120 |
} |
132 |
|
|
133 |
|
|
134 | 121 |
} |
Also available in: Unified diff
Use InputValidator from user management project and Replace regular expressions. Fix user messages for unused email.