String confirmnewpassword = uiForm.getUIStringInput(CONFIRM_NEW_PASSWORD).getValue();
WebuiRequestContext request = event.getRequestContext();
UIApplication uiApp = request.getUIApplication();
UIMaskWorkspace uiMaskWorkspace = uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
OrganizationService orgService = uiForm.getApplicationComponent(OrganizationService.class);
RemindPasswordTokenService tokenService = uiForm.getApplicationComponent(RemindPasswordTokenService.class);
uiForm.reset();
boolean setPassword = true;
if (!newpassword.equals(confirmnewpassword))
{
uiApp.addMessage(new ApplicationMessage("UIResetPassword.msg.password-is-not-match", null));
setPassword = false;
}
Token token = tokenService.getToken(tokenId);
// Making sure a token exist
if (token == null || token.isExpired())
{
uiApp.addMessage(new ApplicationMessage("UIForgetPassword.msg.expration", null));
setPassword = false;
}
if (setPassword)
{
user_.setPassword(newpassword);
orgService.getUserHandler().saveUser(user_, true);
uiMaskWorkspace.setUIComponent(null);
uiMaskWorkspace.setWindowSize(-1, -1);
uiApp.addMessage(new ApplicationMessage("UIResetPassword.msg.change-password-successfully", null));
tokenService.deleteToken(tokenId);
}
event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWorkspace);
}