|  |  |  | @ -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; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |