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";
}
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class LoginController method login.
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Auto-login if "user" and "password" parameters are given.
String username = request.getParameter("user");
String password = request.getParameter("password");
if (username != null && password != null) {
username = StringUtil.urlEncode(username);
password = StringUtil.urlEncode(password);
return new ModelAndView(new RedirectView("/login?" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY + "=" + username + "&" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + "=" + password));
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("logout", request.getParameter("logout") != null);
map.put("error", request.getParameter("error") != null);
map.put("brand", settingsService.getBrand());
map.put("loginMessage", settingsService.getLoginMessage());
User admin = securityService.getUserByName(User.USERNAME_ADMIN);
if (User.USERNAME_ADMIN.equals(admin.getPassword())) {
map.put("insecure", true);
}
return new ModelAndView("login", "model", map);
}
Aggregations