Skip to content

Commit

Permalink
get user refactored and made overwritable
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed May 11, 2012
1 parent 94e7dc2 commit 96a3532
Showing 1 changed file with 30 additions and 16 deletions.
Expand Up @@ -277,29 +277,43 @@ private String generateForgotPasswordRequest(String email) throws Exception {
} else if (! EmailValidator.getInstance().isValid(email)) {
exceptionMsg = email + " is not a valid E-mail address.";
} else {
log.warn("TODO: Checking every user by her/his email does not scale!");
User[] userList = realm.getIdentityManager().getUserManager().getUsers(true);
for(int i=0; i< userList.length; i++) {
if (userList[i].getEmail().equals(email)) {
String uuid = UUID.randomUUID().toString();
uuid = sendEmail(uuid, userList[i].getEmail());
if (uuid != null) {
ResetPWExpire pwexp = new ResetPWExpire(userList[i].getID(), new Date().getTime(), uuid, userList[i].getEmail());
writeXMLOutput(getPersistentRequestPath(uuid), generateXML(pwexp));
return uuid;
} else {
exceptionMsg = "No forgot password request UUID was generated (please check log file to check what went wrong)";
log.warn(exceptionMsg);
throw new Exception(exceptionMsg);
}
User user = getUser(email);
if (user == null) {
exceptionMsg = "Unable to find user based on the " + email + " E-mail address.";
} else {
String uuid = UUID.randomUUID().toString();
uuid = sendEmail(uuid, user.getEmail());
if (uuid != null) {
ResetPWExpire pwexp = new ResetPWExpire(user.getID(), new Date().getTime(), uuid, user.getEmail());
writeXMLOutput(getPersistentRequestPath(uuid), generateXML(pwexp));
return uuid;
} else {
exceptionMsg = "No forgot password request UUID was generated (please check log file to check what went wrong)";
log.warn(exceptionMsg);
throw new Exception(exceptionMsg);
}
}
exceptionMsg = "Unable to find user based on the " + email + " E-mail address.";
}
log.warn(exceptionMsg);
throw new Exception(exceptionMsg);
}

/**
* Get user which is associated with an email address
* @param email Email address of user
*/
protected User getUser(String email) throws Exception {
log.warn("TODO: Checking every user by her/his email does not scale!");
User[] userList = realm.getIdentityManager().getUserManager().getUsers(true);
for(int i=0; i< userList.length; i++) {
if (userList[i].getEmail().equals(email)) {
return userList[i];
}
}
log.warn("No user found with email addres: " + email);
return null;
}

/**
* Generate XML containing request information which will be saved persistently
*/
Expand Down

0 comments on commit 96a3532

Please sign in to comment.