UIResetPassword uiForm = event.getSource();
String newpassword = uiForm.getUIStringInput(NEW_PASSWORD).getValue();
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.deleteToken(uiForm.getTokenId());
if (token == null || token.isExpired()) {
uiApp.addMessage(new ApplicationMessage("UIForgetPassword.msg.expration", null));
setPassword = false;
}
if (setPassword) {
try {
user_.setPassword(newpassword);
orgService.getUserHandler().saveUser(user_, true);
uiMaskWorkspace.createEvent("Close", Phase.DECODE, request).broadcast();
uiApp.addMessage(new ApplicationMessage("UIResetPassword.msg.change-password-successfully", null));
} catch (Exception e) {
uiApp.addMessage(new ApplicationMessage("UIResetPassword.msg.change-password-fail", null, ApplicationMessage.ERROR));
}
}