Search in sources :

Example 26 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)

Example 27 with User

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

the class PlayQueueController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    Player player = playerService.getPlayer(request, response);
    Map<String, Object> map = new HashMap<>();
    map.put("user", user);
    map.put("player", player);
    map.put("players", playerService.getPlayersForUserAndClientId(user.getUsername(), null));
    map.put("visibility", userSettings.getPlaylistVisibility());
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("notify", userSettings.isSongNotificationEnabled());
    map.put("autoHide", userSettings.isAutoHidePlayQueue());
    return new ModelAndView("playQueue", "model", map);
}
Also used : Player(org.libresonic.player.domain.Player) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) UserSettings(org.libresonic.player.domain.UserSettings) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with User

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

the class PlaylistsController method doGet.

@RequestMapping(method = RequestMethod.GET)
public String doGet(HttpServletRequest request, Model model) throws Exception {
    Map<String, Object> map = new HashMap<>();
    User user = securityService.getCurrentUser(request);
    List<Playlist> playlists = playlistService.getReadablePlaylistsForUser(user.getUsername());
    map.put("playlists", playlists);
    model.addAttribute("model", map);
    return "playlists";
}
Also used : Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with User

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

the class RESTController method getPlaylists.

@RequestMapping(value = "/rest/getPlaylists", method = { RequestMethod.GET, RequestMethod.POST })
public void getPlaylists(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    String authenticatedUsername = user.getUsername();
    String requestedUsername = request.getParameter("username");
    if (requestedUsername == null) {
        requestedUsername = authenticatedUsername;
    } else if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, authenticatedUsername + " is not authorized to get playlists for " + requestedUsername);
        return;
    }
    Playlists result = new Playlists();
    for (Playlist playlist : playlistService.getReadablePlaylistsForUser(requestedUsername)) {
        result.getPlaylist().add(createJaxbPlaylist(new org.libresonic.restapi.Playlist(), playlist));
    }
    Response res = createResponse();
    res.setPlaylists(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with User

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

the class RESTController method createPodcastChannel.

@RequestMapping(value = "/rest/createPodcastChannel", method = { RequestMethod.GET, RequestMethod.POST })
public void createPodcastChannel(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;
    }
    String url = getRequiredStringParameter(request, "url");
    podcastService.createChannel(url);
    writeEmptyResponse(request, response);
}
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