Index: lams_central/conf/language/lams/ApplicationResources.properties
===================================================================
diff -u -r8e454f8298f642d44db16ee5ade01b0c0afde504 -r9004121c5aab7ccdf967fa5ceef247c8950e92f8
--- lams_central/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 8e454f8298f642d44db16ee5ade01b0c0afde504)
+++ lams_central/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 9004121c5aab7ccdf967fa5ceef247c8950e92f8)
@@ -197,14 +197,18 @@
label.ok =OK
title.forgot.password =LAMS :: Forgot Password
label.forgot.password.confirm =Password Request
-label.forgot.password.instructions =Please enter your user name and email below. An email will be sent to you shortly with a link that will allow you to change your password. If you do not know your email address in LAMS, please contact your System Administrator.
+label.forgot.password.instructions =Please enter your user name or email below. An email will be sent to you shortly with a link that will allow you to change your password. You only need to enter one value.
If you do not know your email address in LAMS, please contact your System Administrator.
+label.forgot.password.email =Check Email
+label.forgot.password.username =Check Username
forgot.password.email.subject =LAMS server - Forgot password response
forgot.password.email.body =Click the link below to and it will take you to a page where you can change your password.
forgot.password.email.sent =An email has been sent to your email address.
+error.forgot.password.email =Please enter an email address.
+error.forgot.password.username =Please enter a username.
error.user.not.found =Unable to find the username in LAMS. Please check your username and try again.
-error.email.does.not.match =The email address does not match your saved email address. Please try again.
+error.email.not.found =Unable to find a user that matches the given email. Please check your email and try again.
+error.multiple.emails =There are multiple users in LAMS with the given email. Email could not be sent. Please try again using your username, or contact your System Administrator.
error.support.email.not.set =Email could not be sent. The LAMS server has not been configured to handle emails. Please contact your System Administrator.
error.password.request.expired =This request for a new password has expired. Please click the "Forgot your Password" link again to make a new request.
-error.forgot.password.fields =Both fields are required. Please try again.
#======= End labels: Exported 199 labels for en AU =====
Index: lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java
===================================================================
diff -u -r8e454f8298f642d44db16ee5ade01b0c0afde504 -r9004121c5aab7ccdf967fa5ceef247c8950e92f8
--- lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java (.../ForgotPasswordServlet.java) (revision 8e454f8298f642d44db16ee5ade01b0c0afde504)
+++ lams_central/src/java/org/lamsfoundation/lams/web/ForgotPasswordServlet.java (.../ForgotPasswordServlet.java) (revision 9004121c5aab7ccdf967fa5ceef247c8950e92f8)
@@ -4,6 +4,7 @@
import java.util.Date;
import java.util.Calendar;
import java.util.Properties;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -45,11 +46,12 @@
// states
public static String SMTP_SERVER_NOT_SET = "error.support.email.not.set";
- public static String EMAIL_DOES_NOT_MATCH = "error.email.does.not.match";
public static String USER_NOT_FOUND = "error.user.not.found";
public static String PASSWORD_REQUEST_EXPIRED = "error.password.request.expired";
public static String SUCCESS_REQUEST_EMAIL = "forgot.password.email.sent";
public static String SUCCESS_CHANGE_PASS = "heading.password.changed.screen";
+ public static String EMAIL_NOT_FOUND = "error.email.not.found";
+ public static String MULTIPLE_EMAILS = "error.multiple.emails";
public static int MILLISECONDS_IN_A_DAY = 86400000;
@@ -63,14 +65,26 @@
if (method.equals("requestEmail"))
{
- String login = request.getParameter("login");
- String email = request.getParameter("email");
- handleEmailRequest(login, email, response);
+ String selectType = request.getParameter("selectType");
+ Boolean findByEmail = false;
+ String param = "";
+ if (selectType.equals("radioEmail"))
+ {
+ findByEmail = true;
+ param = request.getParameter("email");
+ }
+ else
+ {
+ param = request.getParameter("login");
+ }
+
+
+ handleEmailRequest(findByEmail, param, response);
}
else if (method.equals("requestPasswordChange"))
{
- String newPassword = request.getParameter("newPassword");
- String key = request.getParameter("key");
+ String newPassword = request.getParameter("newPassword");
+ String key = request.getParameter("key");
handlePasswordChange(newPassword, key, response);
}
else
@@ -83,24 +97,22 @@
/**
* Handles the first step of the forgot login process, sending the email to the user.
* An email is sent with a link and key attached to identify the forgot login request
- * @param login
- * @param email
+ * @param findByEmail true if the forgot login request was for an email, false if it was for a login
+ * @param param the param for which the user password will be searched
* @param response
* @throws ServletException
* @throws IOException
*/
- public void handleEmailRequest(String login, String email, HttpServletResponse response)
+ public void handleEmailRequest(Boolean findByEmail, String param, HttpServletResponse response)
throws ServletException, IOException
{
int success=0;
String languageKey = "";
-
-
boolean err = false;
- if (login==null||login.equals("")||email==null||email.equals(""))
+ if (param==null||param.equals(""))
{
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
@@ -109,8 +121,7 @@
String SMPTServer = Configuration.get("SMTPServer");
String supportEmail = Configuration.get("LamsSupportEmail");
-
-
+
if (SMPTServer==null||SMPTServer.equals("")||supportEmail==null||supportEmail.equals(""))
{
// Validate SMTP not set up
@@ -122,78 +133,104 @@
IUserManagementService userService = (IUserManagementService) ctx.getBean("userManagementService");
MessageService messageService = (MessageService)ctx.getBean("centralMessageService");
- if (userService.getUserByLogin(login)!=null)
+
+ User user = null;
+
+ // get the user by email or login
+ if (!findByEmail)
{
- User user = userService.getUserByLogin(login);
-
- if (user.getEmail().equals(email))
+ if (userService.getUserByLogin(param)!=null)
{
- // generate a key for the request
- String key = generateUniqueKey();
-
- // all good, save the request in the db
- ForgotPasswordRequest fp = new ForgotPasswordRequest();
- fp.setRequestDate(new Date());
- fp.setUserId(user.getUserId());
- fp.setRequestKey(key);
- userService.save(fp);
-
- // Constructing the body of the email
- String body = messageService.getMessage("forgot.password.email.body")
- + "\n\n"
- + Configuration.get("ServerURL")
- + "forgotPasswordChange.jsp?key="
- + key;
-
- // send the email
- try{
- Emailer.sendFromSupportEmail(
- messageService.getMessage("forgot.password.email.subject"),
- email,
- body
- );
- languageKey = this.SUCCESS_REQUEST_EMAIL;
- success = 1;
- }
- catch (AddressException e)
- {
- // failure handling
- log.debug(e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- catch (MessagingException e)
- {
- // failure handling
- log.debug(e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- catch (Exception e)
- {
- // failure handling
- log.debug(e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
-
+ user = userService.getUserByLogin(param);
}
else
{
- // validate email does not match user
- languageKey = this.EMAIL_DOES_NOT_MATCH;
+ // validate user is not found
+ languageKey = this.USER_NOT_FOUND;
+ err = true;
}
-
}
else
{
- // validate user is not found
- languageKey = this.USER_NOT_FOUND;
+ List users = userService.getAllUsersWithEmail(param);
+
+ if (users.size()==1)
+ {
+ user = (User)users.get(0);
+ }
+ else if (users.size()==0)
+ {
+ // validate no user with email found
+ languageKey = this.EMAIL_NOT_FOUND;
+ err = true;
+ }
+ else
+ {
+ // validate multiple users with email found
+ languageKey = this.MULTIPLE_EMAILS;
+ err = true;
+ }
}
+
+
+ if (!err)
+ {
+ // generate a key for the request
+ String key = generateUniqueKey();
+
+ // all good, save the request in the db
+ ForgotPasswordRequest fp = new ForgotPasswordRequest();
+ fp.setRequestDate(new Date());
+ fp.setUserId(user.getUserId());
+ fp.setRequestKey(key);
+ userService.save(fp);
+
+ // Constructing the body of the email
+ String body = messageService.getMessage("forgot.password.email.body")
+ + "\n\n"
+ + Configuration.get("ServerURL")
+ + "forgotPasswordChange.jsp?key="
+ + key;
+
+ // send the email
+ try{
+ Emailer.sendFromSupportEmail(
+ messageService.getMessage("forgot.password.email.subject"),
+ user.getEmail(),
+ body
+ );
+ languageKey = this.SUCCESS_REQUEST_EMAIL;
+ success = 1;
+ }
+ catch (AddressException e)
+ {
+ // failure handling
+ log.debug(e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (MessagingException e)
+ {
+ // failure handling
+ log.debug(e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (Exception e)
+ {
+ // failure handling
+ log.debug(e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+
}
+
+
response.sendRedirect(Configuration.get("ServerURL") + "forgotPasswordProc.jsp?" +
- STATE +
- success +
- LANGUAGE_KEY +
- languageKey);
+ STATE +
+ success +
+ LANGUAGE_KEY +
+ languageKey);
}
Index: lams_central/web/forgotPassword.jsp
===================================================================
diff -u -r8e454f8298f642d44db16ee5ade01b0c0afde504 -r9004121c5aab7ccdf967fa5ceef247c8950e92f8
--- lams_central/web/forgotPassword.jsp (.../forgotPassword.jsp) (revision 8e454f8298f642d44db16ee5ade01b0c0afde504)
+++ lams_central/web/forgotPassword.jsp (.../forgotPassword.jsp) (revision 9004121c5aab7ccdf967fa5ceef247c8950e92f8)
@@ -21,52 +21,83 @@
function toHome() {window.location="