use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class RESTController method getUsers.
@RequestMapping(value = "/rest/getUsers", method = { RequestMethod.GET, RequestMethod.POST })
public void getUsers(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
User currentUser = securityService.getCurrentUser(request);
if (!currentUser.isAdminRole()) {
error(request, response, ErrorCode.NOT_AUTHORIZED, currentUser.getUsername() + " is not authorized to get details for other users.");
return;
}
Users result = new Users();
for (User user : securityService.getAllUsers()) {
result.getUser().add(createJaxbUser(user));
}
Response res = createResponse();
res.setUsers(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class RESTController method download.
@RequestMapping(value = "/rest/download", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView download(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
User user = securityService.getCurrentUser(request);
if (!user.isDownloadRole()) {
error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to download files.");
return null;
}
long ifModifiedSince = request.getDateHeader("If-Modified-Since");
long lastModified = downloadController.getLastModified(request);
if (ifModifiedSince != -1 && lastModified != -1 && lastModified <= ifModifiedSince) {
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
return null;
}
if (lastModified != -1) {
response.setDateHeader("Last-Modified", lastModified);
}
return downloadController.handleRequest(request, response);
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class RESTController method createJaxbUser.
private org.libresonic.restapi.User createJaxbUser(User user) {
UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
org.libresonic.restapi.User result = new org.libresonic.restapi.User();
result.setUsername(user.getUsername());
result.setEmail(user.getEmail());
result.setScrobblingEnabled(userSettings.isLastFmEnabled());
result.setAdminRole(user.isAdminRole());
result.setSettingsRole(user.isSettingsRole());
result.setDownloadRole(user.isDownloadRole());
result.setUploadRole(user.isUploadRole());
// Since 1.8.0
result.setPlaylistRole(true);
result.setCoverArtRole(user.isCoverArtRole());
result.setCommentRole(user.isCommentRole());
result.setPodcastRole(user.isPodcastRole());
result.setStreamRole(user.isStreamRole());
result.setJukeboxRole(user.isJukeboxRole());
result.setShareRole(user.isShareRole());
TranscodeScheme transcodeScheme = userSettings.getTranscodeScheme();
if (transcodeScheme != null && transcodeScheme != TranscodeScheme.OFF) {
result.setMaxBitRate(transcodeScheme.getMaxBitRate());
}
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
for (MusicFolder musicFolder : musicFolders) {
result.getFolder().add(musicFolder.getId());
}
return result;
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class PasswordSettingsController method displayForm.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView displayForm(HttpServletRequest request) throws Exception {
PasswordSettingsCommand command = new PasswordSettingsCommand();
User user = securityService.getCurrentUser(request);
command.setUsername(user.getUsername());
command.setLdapAuthenticated(user.isLdapAuthenticated());
return new ModelAndView("passwordSettings", "command", command);
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class PasswordSettingsController method doSubmitAction.
@RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute("command") @Validated PasswordSettingsCommand command, BindingResult bindingResult, RedirectAttributes redirectAttributes) throws Exception {
if (!bindingResult.hasErrors()) {
User user = securityService.getUserByName(command.getUsername());
user.setPassword(command.getPassword());
securityService.updateUser(user);
command.setPassword(null);
command.setConfirmPassword(null);
redirectAttributes.addFlashAttribute("settings_toast", true);
return "redirect:passwordSettings.view";
} else {
return "passwordSettings";
}
}
Aggregations