Search in sources :

Example 11 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class UserSettingsController method createUser.

public void createUser(UserSettingsCommand command) {
    User user = new User(command.getUsername(), command.getPassword(), StringUtils.trimToNull(command.getEmail()));
    user.setLdapAuthenticated(command.isLdapAuthenticated());
    securityService.createUser(user);
    updateUser(command);
}
Also used : User(org.libresonic.player.domain.User)

Example 12 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class SettingsController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    User user = securityService.getCurrentUser(request);
    // Redirect to music folder settings if admin.
    String view = user.isAdminRole() ? "musicFolderSettings" : "personalSettings";
    return new ModelAndView(new RedirectView(view));
}
Also used : User(org.libresonic.player.domain.User) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class ShareSettingsController method handleParameters.

private void handleParameters(HttpServletRequest request) {
    User user = securityService.getCurrentUser(request);
    for (Share share : shareService.getSharesForUser(user)) {
        int id = share.getId();
        String description = getParameter(request, "description", id);
        boolean delete = getParameter(request, "delete", id) != null;
        String expireIn = getParameter(request, "expireIn", id);
        if (delete) {
            shareService.deleteShare(id);
        } else {
            if (expireIn != null) {
                share.setExpires(parseExpireIn(expireIn));
            }
            share.setDescription(description);
            shareService.updateShare(share);
        }
    }
    boolean deleteExpired = ServletRequestUtils.getBooleanParameter(request, "deleteExpired", false);
    if (deleteExpired) {
        Date now = new Date();
        for (Share share : shareService.getSharesForUser(user)) {
            Date expires = share.getExpires();
            if (expires != null && expires.before(now)) {
                shareService.deleteShare(share.getId());
            }
        }
    }
}
Also used : User(org.libresonic.player.domain.User) Share(org.libresonic.player.domain.Share)

Example 14 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method refreshPodcasts.

@RequestMapping(value = "/rest/refreshPodcasts", method = { RequestMethod.GET, RequestMethod.POST })
public void refreshPodcasts(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isPodcastRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to administrate podcasts.");
        return;
    }
    podcastService.refreshAllChannels(true);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method jukeboxControl.

@RequestMapping(value = "/rest/jukeboxControl", method = { RequestMethod.GET, RequestMethod.POST })
public void jukeboxControl(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request, true);
    User user = securityService.getCurrentUser(request);
    if (!user.isJukeboxRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to use jukebox.");
        return;
    }
    boolean returnPlaylist = false;
    String action = getRequiredStringParameter(request, "action");
    if ("start".equals(action)) {
        playQueueService.doStart(request, response);
    } else if ("stop".equals(action)) {
        playQueueService.doStop(request, response);
    } else if ("skip".equals(action)) {
        int index = getRequiredIntParameter(request, "index");
        int offset = getIntParameter(request, "offset", 0);
        playQueueService.doSkip(request, response, index, offset);
    } else if ("add".equals(action)) {
        int[] ids = getIntParameters(request, "id");
        playQueueService.doAdd(request, response, ids, null);
    } else if ("set".equals(action)) {
        int[] ids = getIntParameters(request, "id");
        playQueueService.doSet(request, response, ids);
    } else if ("clear".equals(action)) {
        playQueueService.doClear(request, response);
    } else if ("remove".equals(action)) {
        int index = getRequiredIntParameter(request, "index");
        playQueueService.doRemove(request, response, index);
    } else if ("shuffle".equals(action)) {
        playQueueService.doShuffle(request, response);
    } else if ("setGain".equals(action)) {
        float gain = getRequiredFloatParameter(request, "gain");
        jukeboxService.setGain(gain);
    } else if ("get".equals(action)) {
        returnPlaylist = true;
    } else if ("status".equals(action)) {
    // No action necessary.
    } else {
        throw new Exception("Unknown jukebox action: '" + action + "'.");
    }
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Player jukeboxPlayer = jukeboxService.getPlayer();
    boolean controlsJukebox = jukeboxPlayer != null && jukeboxPlayer.getId().equals(player.getId());
    PlayQueue playQueue = player.getPlayQueue();
    int currentIndex = controlsJukebox && !playQueue.isEmpty() ? playQueue.getIndex() : -1;
    boolean playing = controlsJukebox && !playQueue.isEmpty() && playQueue.getStatus() == PlayQueue.Status.PLAYING;
    float gain = jukeboxService.getGain();
    int position = controlsJukebox && !playQueue.isEmpty() ? jukeboxService.getPosition() : 0;
    Response res = createResponse();
    if (returnPlaylist) {
        JukeboxPlaylist result = new JukeboxPlaylist();
        res.setJukeboxPlaylist(result);
        result.setCurrentIndex(currentIndex);
        result.setPlaying(playing);
        result.setGain(gain);
        result.setPosition(position);
        for (MediaFile mediaFile : playQueue.getFiles()) {
            result.getEntry().add(createJaxbChild(player, mediaFile, username));
        }
    } else {
        JukeboxStatus result = new JukeboxStatus();
        res.setJukeboxStatus(result);
        result.setCurrentIndex(currentIndex);
        result.setPlaying(playing);
        result.setGain(gain);
        result.setPosition(position);
    }
    jaxbWriter.writeResponse(request, response, res);
}
Also used : User(org.libresonic.player.domain.User) HttpServletResponse(javax.servlet.http.HttpServletResponse) PlayQueue(org.libresonic.player.domain.PlayQueue) 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