Restore PasswordSettingsController

This commit is contained in:
Rémi Cocula
2017-01-05 23:23:47 +01:00
parent 884826b3b8
commit 4c49c77641
3 changed files with 12 additions and 24 deletions
@@ -31,7 +31,6 @@ public class PasswordSettingsCommand {
private String password; private String password;
private String confirmPassword; private String confirmPassword;
private boolean ldapAuthenticated; private boolean ldapAuthenticated;
private boolean toast;
public String getUsername() { public String getUsername() {
return username; return username;
@@ -65,11 +64,4 @@ public class PasswordSettingsCommand {
this.ldapAuthenticated = ldapAuthenticated; this.ldapAuthenticated = ldapAuthenticated;
} }
public boolean isToast() {
return toast;
}
public void setToast(boolean toast) {
this.toast = toast;
}
} }
@@ -43,7 +43,7 @@ import javax.servlet.http.*;
*/ */
@org.springframework.stereotype.Controller @org.springframework.stereotype.Controller
@RequestMapping("/passwordSettings") @RequestMapping("/passwordSettings")
@SessionAttributes( value="command", types={PasswordSettingsCommand.class} ) //@SessionAttributes( value="command", types={PasswordSettingsCommand.class} )
public class PasswordSettingsController { public class PasswordSettingsController {
@Autowired @Autowired
@@ -56,14 +56,6 @@ public class PasswordSettingsController {
binder.addValidators(passwordSettingsValidator); binder.addValidators(passwordSettingsValidator);
} }
/* @ModelAttribute
protected Object formBackingObject(HttpServletRequest request) throws Exception {
PasswordSettingsCommand command = new PasswordSettingsCommand();
User user = securityService.getCurrentUser(request);
command.setUsername(user.getUsername());
command.setLdapAuthenticated(user.isLdapAuthenticated());
return command;
}*/
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
protected ModelAndView displayForm(HttpServletRequest request) throws Exception { protected ModelAndView displayForm(HttpServletRequest request) throws Exception {
@@ -75,14 +67,17 @@ public class PasswordSettingsController {
} }
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute("command") @Validated PasswordSettingsCommand command) throws Exception { protected String doSubmitAction(HttpServletRequest request,@ModelAttribute("command") @Validated PasswordSettingsCommand command,BindingResult bindingResult) throws Exception {
User user = securityService.getUserByName(command.getUsername()); if (!bindingResult.hasErrors()) {
user.setPassword(command.getPassword()); User user = securityService.getUserByName(command.getUsername());
securityService.updateUser(user); user.setPassword(command.getPassword());
securityService.updateUser(user);
command.setPassword(null); command.setPassword(null);
command.setConfirmPassword(null); command.setConfirmPassword(null);
command.setToast(true); request.setAttribute("settings_toast",true);
}
return "passwordSettings"; return "passwordSettings";
} }
@@ -23,6 +23,7 @@
<fmt:message key="passwordsettings.title" var="title"><fmt:param>${command.username}</fmt:param></fmt:message> <fmt:message key="passwordsettings.title" var="title"><fmt:param>${command.username}</fmt:param></fmt:message>
<h2>${fn:escapeXml(title)}</h2> <h2>${fn:escapeXml(title)}</h2>
<form:form method="post" action="passwordSettings.view" commandName="command"> <form:form method="post" action="passwordSettings.view" commandName="command">
<form:hidden path="username"/>
<table class="indent"> <table class="indent">
<tr> <tr>
<td><fmt:message key="usersettings.newpassword"/></td> <td><fmt:message key="usersettings.newpassword"/></td>