}
public static class SaveActionListener extends EventListener<UIAccountChangePass> {
public void execute(Event<UIAccountChangePass> event) throws Exception {
UIAccountChangePass uiForm = event.getSource();
OrganizationService service = uiForm.getApplicationComponent(OrganizationService.class);
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
UIApplication uiApp = context.getUIApplication();
String username = Util.getPortalRequestContext().getRemoteUser();
User user = service.getUserHandler().findUserByName(username);
String currentPass = uiForm.getUIStringInput("currentpass").getValue();
String newPass = uiForm.getUIStringInput("newpass").getValue();
String confirmnewPass = uiForm.getUIStringInput("confirmnewpass").getValue();
Authenticator authenticator = uiForm.getApplicationComponent(Authenticator.class);
boolean authenticated;
try {
UsernameCredential usernameCred = new UsernameCredential(username);
PasswordCredential passwordCred = new PasswordCredential(currentPass);
authenticator.validateUser(new Credential[] { usernameCred, passwordCred });
authenticated = true;
} catch (Exception ex) {
authenticated = false;
}
if (!authenticated) {
uiApp.addMessage(new ApplicationMessage("UIAccountChangePass.msg.currentpassword-is-not-match", null, 1));
uiForm.reset();
event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
return;
}
if (!newPass.equals(confirmnewPass)) {
uiApp.addMessage(new ApplicationMessage("UIAccountChangePass.msg.password-is-not-match", null, 1));
uiForm.reset();
event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
return;
}
user.setPassword(newPass);
uiApp.addMessage(new ApplicationMessage("UIAccountChangePass.msg.change.pass.success", null));
service.getUserHandler().saveUser(user, true);
uiForm.reset();
event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
UIAccountSetting ui = uiForm.getParent();
ui.getChild(UIAccountProfiles.class).setRendered(true);
ui.getChild(UIAccountChangePass.class).setRendered(false);