@Transactional
public String validate() throws LoginException {
String returnUrl = "/home.xhtml";
if (activationKey != null && !activationKey.isEmpty()) {
HPersonEmailValidationKey entry =
emailChangeService.getActivationKey(activationKey);
if (entry == null) {
throw new KeyNotFoundException("activation key: "
+ activationKey);
}
String checkResult = checkExpiryDate(entry.getCreationDate());
if (StringUtils.isEmpty(checkResult)) {
HPerson person = entry.getPerson();
HAccount account = person.getAccount();
if (!account.getUsername().equals(
identity.getCredentials().getUsername())) {
throw new LoginException();
}
person.setEmail(entry.getEmail());
account.setEnabled(true);
personDAO.makePersistent(person);
personDAO.flush();
emailChangeService.removeEntry(entry);
FacesMessages.instance().add(
"You have successfully changed your email account.");
log.info("update email address to {} successfully",
entry.getEmail());
} else {
returnUrl = checkResult;
}
}
return returnUrl;