use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class TopController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
Map<String, Object> map = new HashMap<>();
User user = securityService.getCurrentUser(request);
UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
map.put("user", user);
map.put("showSideBar", userSettings.isShowSideBar());
map.put("showAvatar", userSettings.getAvatarScheme() != AvatarScheme.NONE);
return new ModelAndView("top", "model", map);
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class UploadController method handleRequestInternal.
@RequestMapping(method = { RequestMethod.POST })
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<>();
List<File> uploadedFiles = new ArrayList<>();
List<File> unzippedFiles = new ArrayList<>();
TransferStatus status = null;
try {
status = statusService.createUploadStatus(playerService.getPlayer(request, response, false, false));
status.setBytesTotal(request.getContentLength());
request.getSession().setAttribute(UPLOAD_STATUS, status);
// Check that we have a file upload request
if (!ServletFileUpload.isMultipartContent(request)) {
throw new Exception("Illegal request.");
}
File dir = null;
boolean unzip = false;
UploadListener listener = new UploadListenerImpl(status);
FileItemFactory factory = new MonitoredDiskFileItemFactory(listener);
ServletFileUpload upload = new ServletFileUpload(factory);
List<?> items = upload.parseRequest(request);
// First, look for "dir" and "unzip" parameters.
for (Object o : items) {
FileItem item = (FileItem) o;
if (item.isFormField() && "dir".equals(item.getFieldName())) {
dir = new File(item.getString());
} else if (item.isFormField() && "unzip".equals(item.getFieldName())) {
unzip = true;
}
}
if (dir == null) {
throw new Exception("Missing 'dir' parameter.");
}
// Look for file items.
for (Object o : items) {
FileItem item = (FileItem) o;
if (!item.isFormField()) {
String fileName = item.getName();
if (fileName.trim().length() > 0) {
File targetFile = new File(dir, new File(fileName).getName());
if (!securityService.isUploadAllowed(targetFile)) {
throw new Exception("Permission denied: " + StringUtil.toHtml(targetFile.getPath()));
}
if (!dir.exists()) {
dir.mkdirs();
}
item.write(targetFile);
uploadedFiles.add(targetFile);
LOG.info("Uploaded " + targetFile);
if (unzip && targetFile.getName().toLowerCase().endsWith(".zip")) {
unzip(targetFile, unzippedFiles);
}
}
}
}
} catch (Exception x) {
LOG.warn("Uploading failed.", x);
map.put("exception", x);
} finally {
if (status != null) {
statusService.removeUploadStatus(status);
request.getSession().removeAttribute(UPLOAD_STATUS);
User user = securityService.getCurrentUser(request);
securityService.updateUserByteCounts(user, 0L, 0L, status.getBytesTransfered());
}
}
map.put("uploadedFiles", uploadedFiles);
map.put("unzippedFiles", unzippedFiles);
return new ModelAndView("upload", "model", map);
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class UserChartController method createDataset.
private CategoryDataset createDataset(String type) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
List<User> users = securityService.getAllUsers();
for (User user : users) {
double value;
if ("stream".equals(type)) {
value = user.getBytesStreamed();
} else if ("download".equals(type)) {
value = user.getBytesDownloaded();
} else if ("upload".equals(type)) {
value = user.getBytesUploaded();
} else if ("total".equals(type)) {
value = user.getBytesStreamed() + user.getBytesDownloaded() + user.getBytesUploaded();
} else {
throw new RuntimeException("Illegal chart type: " + type);
}
value /= BYTES_PER_MB;
dataset.addValue(value, "Series", user.getUsername());
}
return dataset;
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class UserSettingsController method displayForm.
@RequestMapping(method = RequestMethod.GET)
protected String displayForm(HttpServletRequest request, Model model) throws Exception {
UserSettingsCommand command;
if (!model.containsAttribute("command")) {
command = new UserSettingsCommand();
User user = getUser(request);
if (user != null) {
command.setUser(user);
command.setEmail(user.getEmail());
UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
command.setTranscodeSchemeName(userSettings.getTranscodeScheme().name());
command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user)));
} else {
command.setNewUser(true);
command.setStreamRole(true);
command.setSettingsRole(true);
}
} else {
command = (UserSettingsCommand) model.asMap().get("command");
}
command.setAdmin(User.USERNAME_ADMIN.equals(command.getUsername()));
command.setUsers(securityService.getAllUsers());
command.setTranscodingSupported(transcodingService.isDownsamplingSupported(null));
command.setTranscodeDirectory(transcodingService.getTranscodeDirectory().getPath());
command.setTranscodeSchemes(TranscodeScheme.values());
command.setLdapEnabled(settingsService.isLdapEnabled());
command.setAllMusicFolders(settingsService.getAllMusicFolders());
model.addAttribute("command", command);
return "userSettings";
}
use of org.libresonic.player.domain.User in project libresonic by Libresonic.
the class RESTController method stream.
@RequestMapping(value = "/rest/stream", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView stream(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
User user = securityService.getCurrentUser(request);
if (!user.isStreamRole()) {
error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to play files.");
return null;
}
streamController.handleRequest(request, response);
return null;
}
Aggregations