StringBuffer urlBuffered = request.getRequestURL();
String url = urlBuffered.append("?string=").append(uniqueString)
.toString().replace("logIn.xhtml", "reseter.xhtml");
UserAccount userAccount = userAccountDAO.findByMail(enteredMail);
if(userAccount == null) {
FacesContext.getCurrentInstance().addMessage("logInForm:enteredPassword", new FacesMessage(FacesMessage.SEVERITY_FATAL,
"Aw!", "It wasn't funny."));
return null;
}
try {
userAccount.setPasswordRecoveryString(uniqueString);
userAccountDAO.update(userAccount);
} catch(Exception e) {
FacesContext.getCurrentInstance().addMessage("logInForm:enteredPassword", new FacesMessage(FacesMessage.SEVERITY_FATAL,
"Ups!", "Something went terribly wrong. We're working on that."));
return null;
}
passwordRecoverer.sendMailViaSSL(userAccount.getMail(), url);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
"Hey!", "Check Your mail."));
return adressToRedirect;