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);
}
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));
}
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());
}
}
}
}
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);
}
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);
}
Aggregations