Search in sources :

Example 21 with User

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

Example 22 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 23 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 24 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 25 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)

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