diff --git a/PlexRequests.Api.Models/Plex/PlexAccount.cs b/PlexRequests.Api.Models/Plex/PlexAccount.cs index be1fbef24..45204e3c2 100644 --- a/PlexRequests.Api.Models/Plex/PlexAccount.cs +++ b/PlexRequests.Api.Models/Plex/PlexAccount.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Serialization; +using System.Xml.Serialization; namespace PlexRequests.Api.Models.Plex { diff --git a/PlexRequests.Api.Models/Plex/PlexFriends.cs b/PlexRequests.Api.Models/Plex/PlexFriends.cs index 886b12dbf..6d253d53d 100644 --- a/PlexRequests.Api.Models/Plex/PlexFriends.cs +++ b/PlexRequests.Api.Models/Plex/PlexFriends.cs @@ -1,87 +1,87 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: PlexFriends.cs -// Created By: Jamie Rees -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ************************************************************************/ -#endregion - -using System.Xml.Serialization; - -namespace PlexRequests.Api.Models.Plex -{ - [XmlRoot(ElementName = "Server")] - public class Server - { - [XmlAttribute(AttributeName = "id")] - public string Id { get; set; } - [XmlAttribute(AttributeName = "serverId")] - public string ServerId { get; set; } - [XmlAttribute(AttributeName = "machineIdentifier")] - public string MachineIdentifier { get; set; } - [XmlAttribute(AttributeName = "name")] - public string Name { get; set; } - [XmlAttribute(AttributeName = "lastSeenAt")] - public string LastSeenAt { get; set; } - [XmlAttribute(AttributeName = "numLibraries")] - public string NumLibraries { get; set; } - [XmlAttribute(AttributeName = "owned")] - public string Owned { get; set; } - } - - [XmlRoot(ElementName = "User")] - public class UserFriends - { - [XmlElement(ElementName = "Server")] - public Server Server { get; set; } - [XmlAttribute(AttributeName = "id")] - public string Id { get; set; } - [XmlAttribute(AttributeName = "title")] - public string Title { get; set; } - [XmlAttribute(AttributeName = "username")] - public string Username { get; set; } - [XmlAttribute(AttributeName = "email")] - public string Email { get; set; } - [XmlAttribute(AttributeName = "recommendationsPlaylistId")] - public string RecommendationsPlaylistId { get; set; } - [XmlAttribute(AttributeName = "thumb")] - public string Thumb { get; set; } - } - - [XmlRoot(ElementName = "MediaContainer")] - public class PlexFriends - { - [XmlElement(ElementName = "User")] - public UserFriends[] User { get; set; } - [XmlAttribute(AttributeName = "friendlyName")] - public string FriendlyName { get; set; } - [XmlAttribute(AttributeName = "identifier")] - public string Identifier { get; set; } - [XmlAttribute(AttributeName = "machineIdentifier")] - public string MachineIdentifier { get; set; } - [XmlAttribute(AttributeName = "totalSize")] - public string TotalSize { get; set; } - [XmlAttribute(AttributeName = "size")] - public string Size { get; set; } - } - -} +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: PlexFriends.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion + +using System.Xml.Serialization; + +namespace PlexRequests.Api.Models.Plex +{ + [XmlRoot(ElementName = "Server")] + public class Server + { + [XmlAttribute(AttributeName = "id")] + public string Id { get; set; } + [XmlAttribute(AttributeName = "serverId")] + public string ServerId { get; set; } + [XmlAttribute(AttributeName = "machineIdentifier")] + public string MachineIdentifier { get; set; } + [XmlAttribute(AttributeName = "name")] + public string Name { get; set; } + [XmlAttribute(AttributeName = "lastSeenAt")] + public string LastSeenAt { get; set; } + [XmlAttribute(AttributeName = "numLibraries")] + public string NumLibraries { get; set; } + [XmlAttribute(AttributeName = "owned")] + public string Owned { get; set; } + } + + [XmlRoot(ElementName = "User")] + public class UserFriends + { + [XmlElement(ElementName = "Server")] + public Server Server { get; set; } + [XmlAttribute(AttributeName = "id")] + public int Id { get; set; } + [XmlAttribute(AttributeName = "title")] + public string Title { get; set; } + [XmlAttribute(AttributeName = "username")] + public string Username { get; set; } + [XmlAttribute(AttributeName = "email")] + public string Email { get; set; } + [XmlAttribute(AttributeName = "recommendationsPlaylistId")] + public string RecommendationsPlaylistId { get; set; } + [XmlAttribute(AttributeName = "thumb")] + public string Thumb { get; set; } + } + + [XmlRoot(ElementName = "MediaContainer")] + public class PlexFriends + { + [XmlElement(ElementName = "User")] + public UserFriends[] User { get; set; } + [XmlAttribute(AttributeName = "friendlyName")] + public string FriendlyName { get; set; } + [XmlAttribute(AttributeName = "identifier")] + public string Identifier { get; set; } + [XmlAttribute(AttributeName = "machineIdentifier")] + public string MachineIdentifier { get; set; } + [XmlAttribute(AttributeName = "totalSize")] + public string TotalSize { get; set; } + [XmlAttribute(AttributeName = "size")] + public string Size { get; set; } + } + +} diff --git a/PlexRequests.UI/Content/app/controllers/userManagement/userManagementController.js b/PlexRequests.UI/Content/app/controllers/userManagement/userManagementController.js index 85bf40d0f..eb07c2f7b 100644 --- a/PlexRequests.UI/Content/app/controllers/userManagement/userManagementController.js +++ b/PlexRequests.UI/Content/app/controllers/userManagement/userManagementController.js @@ -2,7 +2,7 @@ var controller = function ($scope, userManagementService) { - $scope.user = {}; // The local user to create + $scope.user = {}; // The local user $scope.users = []; // list of users $scope.error = false; @@ -16,9 +16,6 @@ }; $scope.addUser = function () { - if ($scope.users.length === 0) { - $scope.getUsers(); - } userManagementService.addUser($scope.user).then(function (data) { if (data.message) { $scope.error = true; diff --git a/PlexRequests.UI/Content/app/services/userManagement/userManagementService.js b/PlexRequests.UI/Content/app/services/userManagement/userManagementService.js index c9de3272f..8608ef9ec 100644 --- a/PlexRequests.UI/Content/app/services/userManagement/userManagementService.js +++ b/PlexRequests.UI/Content/app/services/userManagement/userManagementService.js @@ -2,6 +2,8 @@ var userManagementService = function ($http) { + $http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; // Set default headers + var getUsers = function () { return $http.get('/usermanagement/users'); }; @@ -11,10 +13,7 @@ return $http({ url: '/usermanagement/createuser', method: "POST", - data: $.param(user), - headers: { - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' - } + data: $.param(user) }); } diff --git a/PlexRequests.UI/Modules/UserManagementModule.cs b/PlexRequests.UI/Modules/UserManagementModule.cs index 83e4db8b3..76d2239b0 100644 --- a/PlexRequests.UI/Modules/UserManagementModule.cs +++ b/PlexRequests.UI/Modules/UserManagementModule.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -29,6 +30,8 @@ namespace PlexRequests.UI.Modules Get["/users", true] = async (x, ct) => await LoadUsers(); Post["/createuser"] = x => CreateUser(Request.Form["userName"].ToString(), Request.Form["password"].ToString()); + Get["/local/{id}"] = x => LocalDetails((Guid)x.id); + Get["/plex/{id}", true] = async (x,ct) => await PlexDetails((int)x.id); } private ICustomUserMapper UserMapper { get; } @@ -72,7 +75,7 @@ namespace PlexRequests.UI.Modules { Username = u.Username, Type = UserType.PlexUser, - //Alias = + Id = u.Id, Claims = "Requestor", EmailAddress = u.Email }); @@ -99,6 +102,36 @@ namespace PlexRequests.UI.Modules return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save user" }); } + + private Response LocalDetails(Guid id) + { + var localUser = UserMapper.GetUser(id); + if (localUser != null) + { + return Response.AsJson(localUser); + } + + return Nancy.Response.NoBody; + } + + private async Task PlexDetails(int id) + { + var authSettings = await AuthSettings.GetSettingsAsync(); + if (!string.IsNullOrEmpty(authSettings.PlexAuthToken)) + { + //Get Plex Users + var plexUsers = PlexApi.GetUsers(authSettings.PlexAuthToken); + + var selectedUser = plexUsers.User?.FirstOrDefault(x => x.Id == id); + if (selectedUser != null) + { + return Response.AsJson(selectedUser); + } + + } + + return Nancy.Response.NoBody; + } } } diff --git a/PlexRequests.UI/Views/UserManagement/Index.cshtml b/PlexRequests.UI/Views/UserManagement/Index.cshtml index 784c7cee0..300b34748 100644 --- a/PlexRequests.UI/Views/UserManagement/Index.cshtml +++ b/PlexRequests.UI/Views/UserManagement/Index.cshtml @@ -1,18 +1,7 @@ -@using PlexRequests.UI.Helpers +@inherits PlexRequests.UI.Helpers.AngularViewBase -@inherits PlexRequests.UI.Helpers.AngularViewBase - -@Html.LoadTableAssets() -@{ - var baseUrl = Html.GetBaseUrl().ToHtmlString(); - var url = string.Empty; - if (!string.IsNullOrEmpty(baseUrl)) - { - url = "/" + baseUrl; - } -} - - + +

@@ -24,7 +13,7 @@ Id Username Email - User T + User Type