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.Xml.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace PlexRequests.Api.Models.Plex namespace PlexRequests.Api.Models.Plex
{ {

@ -54,7 +54,7 @@ namespace PlexRequests.Api.Models.Plex
[XmlElement(ElementName = "Server")] [XmlElement(ElementName = "Server")]
public Server Server { get; set; } public Server Server { get; set; }
[XmlAttribute(AttributeName = "id")] [XmlAttribute(AttributeName = "id")]
public string Id { get; set; } public int Id { get; set; }
[XmlAttribute(AttributeName = "title")] [XmlAttribute(AttributeName = "title")]
public string Title { get; set; } public string Title { get; set; }
[XmlAttribute(AttributeName = "username")] [XmlAttribute(AttributeName = "username")]

@ -2,7 +2,7 @@
var controller = function ($scope, userManagementService) { var controller = function ($scope, userManagementService) {
$scope.user = {}; // The local user to create $scope.user = {}; // The local user
$scope.users = []; // list of users $scope.users = []; // list of users
$scope.error = false; $scope.error = false;
@ -16,9 +16,6 @@
}; };
$scope.addUser = function () { $scope.addUser = function () {
if ($scope.users.length === 0) {
$scope.getUsers();
}
userManagementService.addUser($scope.user).then(function (data) { userManagementService.addUser($scope.user).then(function (data) {
if (data.message) { if (data.message) {
$scope.error = true; $scope.error = true;

@ -2,6 +2,8 @@
var userManagementService = function ($http) { var userManagementService = function ($http) {
$http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; // Set default headers
var getUsers = function () { var getUsers = function () {
return $http.get('/usermanagement/users'); return $http.get('/usermanagement/users');
}; };
@ -11,10 +13,7 @@
return $http({ return $http({
url: '/usermanagement/createuser', url: '/usermanagement/createuser',
method: "POST", method: "POST",
data: $.param(user), data: $.param(user)
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}); });
} }

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -29,6 +30,8 @@ namespace PlexRequests.UI.Modules
Get["/users", true] = async (x, ct) => await LoadUsers(); Get["/users", true] = async (x, ct) => await LoadUsers();
Post["/createuser"] = x => CreateUser(Request.Form["userName"].ToString(), Request.Form["password"].ToString()); 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; } private ICustomUserMapper UserMapper { get; }
@ -72,7 +75,7 @@ namespace PlexRequests.UI.Modules
{ {
Username = u.Username, Username = u.Username,
Type = UserType.PlexUser, Type = UserType.PlexUser,
//Alias = Id = u.Id,
Claims = "Requestor", Claims = "Requestor",
EmailAddress = u.Email EmailAddress = u.Email
}); });
@ -99,6 +102,36 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not save user" }); 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 <script src="~/Content/app/controllers/userManagement/userManagementController.js"></script>
<script src="~/Content/app/services/userManagement/userManagementService.js"></script>
@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>
<div ng-controller="userManagementController" ng-init="getUsers()"> <div ng-controller="userManagementController" ng-init="getUsers()">
<br> <br>
@ -24,7 +13,7 @@
<th>Id</th> <th>Id</th>
<th>Username</th> <th>Username</th>
<th>Email</th> <th>Email</th>
<th>User T</th> <th>User Type</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

Loading…
Cancel
Save