Search in sources :

Example 41 with User

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);
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with User

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;
}
Also used : User(org.libresonic.player.domain.User) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder)

Example 43 with User

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);
}
Also used : User(org.libresonic.player.domain.User) PasswordSettingsCommand(org.libresonic.player.command.PasswordSettingsCommand) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with User

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";
    }
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with User

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);
}
Also used : User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (org.libresonic.player.domain.User)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 ModelAndView (org.springframework.web.servlet.ModelAndView)10 HashMap (java.util.HashMap)8 Test (org.junit.Test)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Share (org.libresonic.player.domain.Share)6 UserSettings (org.libresonic.player.domain.UserSettings)6 MusicFolder (org.libresonic.player.domain.MusicFolder)5 Player (org.libresonic.player.domain.Player)4 UserSettingsCommand (org.libresonic.player.command.UserSettingsCommand)3 Playlist (org.libresonic.player.domain.Playlist)3 org.libresonic.restapi (org.libresonic.restapi)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 File (java.io.File)2 Date (java.util.Date)2 MediaFile (org.libresonic.player.domain.MediaFile)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 LinkedHashMap (java.util.LinkedHashMap)1 ReCaptcha (net.tanesha.recaptcha.ReCaptcha)1