small changes around the user management

pull/470/head
tidusjar 8 years ago
parent c0641460f6
commit ffe6bc41ac

@ -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
{

@ -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; }
}
}

@ -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;

@ -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)
});
}

@ -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<Response> 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;
}
}
}

@ -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;
}
}
<script src="/Content/app/controllers/userManagement/userManagementController.js"></script>
<script src="/Content/app/services/userManagement/userManagementService.js"></script>
<script src="~/Content/app/controllers/userManagement/userManagementController.js"></script>
<script src="~/Content/app/services/userManagement/userManagementService.js"></script>
<div ng-controller="userManagementController" ng-init="getUsers()">
<br>
@ -24,7 +13,7 @@
<th>Id</th>
<th>Username</th>
<th>Email</th>
<th>User T</th>
<th>User Type</th>
</tr>
</thead>
<tbody>

Loading…
Cancel
Save