|
|
@ -30,8 +30,16 @@ import org.libresonic.player.service.TranscodingService; |
|
|
|
import org.libresonic.player.util.Util; |
|
|
|
import org.libresonic.player.util.Util; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
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.ServletRequestBindingException; |
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
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 org.springframework.web.servlet.mvc.SimpleFormController; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
@ -45,14 +53,27 @@ import java.util.List; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Sindre Mehus |
|
|
|
* @author Sindre Mehus |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class UserSettingsController extends SimpleFormController { |
|
|
|
@Controller |
|
|
|
|
|
|
|
@RequestMapping("/userSettings") |
|
|
|
|
|
|
|
@SessionAttributes(value = "command") |
|
|
|
|
|
|
|
public class UserSettingsController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SecurityService securityService; |
|
|
|
private SecurityService securityService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SettingsService settingsService; |
|
|
|
private SettingsService settingsService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TranscodingService transcodingService; |
|
|
|
private TranscodingService transcodingService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private UserSettingsValidator userSettingsValidator; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@InitBinder |
|
|
|
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
|
|
|
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(); |
|
|
|
UserSettingsCommand command = new UserSettingsCommand(); |
|
|
|
|
|
|
|
|
|
|
|
User user = getUser(request); |
|
|
|
User user = getUser(request); |
|
|
@ -77,7 +98,8 @@ public class UserSettingsController extends SimpleFormController { |
|
|
|
command.setAllMusicFolders(settingsService.getAllMusicFolders()); |
|
|
|
command.setAllMusicFolders(settingsService.getAllMusicFolders()); |
|
|
|
command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user))); |
|
|
|
command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user))); |
|
|
|
|
|
|
|
|
|
|
|
return command; |
|
|
|
model.addAttribute("command",command); |
|
|
|
|
|
|
|
return "userSettings"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private User getUser(HttpServletRequest request) throws ServletRequestBindingException { |
|
|
|
private User getUser(HttpServletRequest request) throws ServletRequestBindingException { |
|
|
@ -103,10 +125,10 @@ public class UserSettingsController extends SimpleFormController { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@RequestMapping(method = RequestMethod.POST) |
|
|
|
protected void doSubmitAction(Object comm) throws Exception { |
|
|
|
protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command,final BindingResult binding) throws Exception { |
|
|
|
UserSettingsCommand command = (UserSettingsCommand) comm; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!binding.hasErrors()) { |
|
|
|
if (command.isDeleteUser()) { |
|
|
|
if (command.isDeleteUser()) { |
|
|
|
deleteUser(command); |
|
|
|
deleteUser(command); |
|
|
|
} else if (command.isNewUser()) { |
|
|
|
} else if (command.isNewUser()) { |
|
|
@ -114,7 +136,10 @@ public class UserSettingsController extends SimpleFormController { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
updateUser(command); |
|
|
|
updateUser(command); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
resetCommand(command); |
|
|
|
resetCommand(command); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "userSettings"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void deleteUser(UserSettingsCommand command) { |
|
|
|
private void deleteUser(UserSettingsCommand command) { |
|
|
@ -176,15 +201,4 @@ public class UserSettingsController extends SimpleFormController { |
|
|
|
command.setReload(true); |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|