}
@Override
@Transactional("blTransactionManager")
public GenericResponse resetPasswordUsingToken(String username, String token, String password, String confirmPassword) {
GenericResponse response = new GenericResponse();
AdminUser user = null;
if (username != null) {
user = adminUserDao.readAdminUserByUserName(username);
}
checkUser(user, response);
checkPassword(password, confirmPassword, response);
if (token == null || "".equals(token)) {
response.addErrorCode("invalidToken");
}
ForgotPasswordSecurityToken fpst = null;
if (! response.getHasErrors()) {
token = token.toLowerCase();
fpst = forgotPasswordSecurityTokenDao.readToken(passwordEncoder.encodePassword(token, null));
if (fpst == null) {
response.addErrorCode("invalidToken");
} else if (fpst.isTokenUsedFlag()) {
response.addErrorCode("tokenUsed");
} else if (isTokenExpired(fpst)) {
response.addErrorCode("tokenExpired");
}
}
if (! response.getHasErrors()) {
user.setUnencodedPassword(password);
saveAdminUser(user);
fpst.setTokenUsedFlag(true);
forgotPasswordSecurityTokenDao.saveToken(fpst);
}