diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java
index 4a913f9f..adc91939 100644
--- a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java
+++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java
@@ -30,8 +30,16 @@ import org.libresonic.player.service.TranscodingService;
import org.libresonic.player.util.Util;
import org.apache.commons.lang.StringUtils;
+import org.libresonic.player.validator.UserSettingsValidator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.SimpleFormController;
import javax.servlet.http.HttpServletRequest;
@@ -45,14 +53,27 @@ import java.util.List;
*
* @author Sindre Mehus
*/
-public class UserSettingsController extends SimpleFormController {
+@Controller
+@RequestMapping("/userSettings")
+@SessionAttributes(value = "command")
+public class UserSettingsController {
+ @Autowired
private SecurityService securityService;
+ @Autowired
private SettingsService settingsService;
+ @Autowired
private TranscodingService transcodingService;
+ @Autowired
+ private UserSettingsValidator userSettingsValidator;
- @Override
- protected Object formBackingObject(HttpServletRequest request) throws Exception {
+ @InitBinder
+ protected void initBinder(WebDataBinder binder) {
+ binder.addValidators(userSettingsValidator);
+ }
+
+ @RequestMapping(method = RequestMethod.GET)
+ protected String formBackingObject(HttpServletRequest request,Model model) throws Exception {
UserSettingsCommand command = new UserSettingsCommand();
User user = getUser(request);
@@ -77,7 +98,8 @@ public class UserSettingsController extends SimpleFormController {
command.setAllMusicFolders(settingsService.getAllMusicFolders());
command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user)));
- return command;
+ model.addAttribute("command",command);
+ return "userSettings";
}
private User getUser(HttpServletRequest request) throws ServletRequestBindingException {
@@ -103,18 +125,21 @@ public class UserSettingsController extends SimpleFormController {
return result;
}
- @Override
- protected void doSubmitAction(Object comm) throws Exception {
- UserSettingsCommand command = (UserSettingsCommand) comm;
+ @RequestMapping(method = RequestMethod.POST)
+ protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command,final BindingResult binding) throws Exception {
- if (command.isDeleteUser()) {
- deleteUser(command);
- } else if (command.isNewUser()) {
- createUser(command);
- } else {
- updateUser(command);
+ if (!binding.hasErrors()) {
+ if (command.isDeleteUser()) {
+ deleteUser(command);
+ } else if (command.isNewUser()) {
+ createUser(command);
+ } else {
+ updateUser(command);
+ }
}
resetCommand(command);
+
+ return "userSettings";
}
private void deleteUser(UserSettingsCommand command) {
@@ -176,15 +201,4 @@ public class UserSettingsController extends SimpleFormController {
command.setReload(true);
}
- public void setSecurityService(SecurityService securityService) {
- this.securityService = securityService;
- }
-
- public void setSettingsService(SettingsService settingsService) {
- this.settingsService = settingsService;
- }
-
- public void setTranscodingService(TranscodingService transcodingService) {
- this.transcodingService = transcodingService;
- }
}
diff --git a/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java b/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java
index 3686e8c6..755ae0ea 100644
--- a/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java
+++ b/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java
@@ -24,6 +24,8 @@ import org.libresonic.player.controller.UserSettingsController;
import org.libresonic.player.service.SecurityService;
import org.libresonic.player.service.SettingsService;
import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
@@ -32,9 +34,12 @@ import org.springframework.validation.Validator;
*
* @author Sindre Mehus
*/
+@Component
public class UserSettingsValidator implements Validator {
+ @Autowired
private SecurityService securityService;
+ @Autowired
private SettingsService settingsService;
/**
@@ -82,11 +87,4 @@ public class UserSettingsValidator implements Validator {
}
- public void setSecurityService(SecurityService securityService) {
- this.securityService = securityService;
- }
-
- public void setSettingsService(SettingsService settingsService) {
- this.settingsService = settingsService;
- }
}
\ No newline at end of file
diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml
index afbf083e..a649d1f3 100644
--- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml
+++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml
@@ -13,7 +13,7 @@
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
-
+
@@ -203,16 +203,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -364,10 +354,6 @@
-
-
-
-
@@ -412,7 +398,6 @@
internetRadioSettingsController
personalSettingsController
avatarUploadController
- userSettingsController
passwordSettingsController
premiumSettingsController
allmusicController