mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
small changes around the user management
This commit is contained in:
parent
c0641460f6
commit
ffe6bc41ac
6 changed files with 131 additions and 118 deletions
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,87 +1,87 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: PlexFriends.cs
|
// File: PlexFriends.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace PlexRequests.Api.Models.Plex
|
namespace PlexRequests.Api.Models.Plex
|
||||||
{
|
{
|
||||||
[XmlRoot(ElementName = "Server")]
|
[XmlRoot(ElementName = "Server")]
|
||||||
public class Server
|
public class Server
|
||||||
{
|
{
|
||||||
[XmlAttribute(AttributeName = "id")]
|
[XmlAttribute(AttributeName = "id")]
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
[XmlAttribute(AttributeName = "serverId")]
|
[XmlAttribute(AttributeName = "serverId")]
|
||||||
public string ServerId { get; set; }
|
public string ServerId { get; set; }
|
||||||
[XmlAttribute(AttributeName = "machineIdentifier")]
|
[XmlAttribute(AttributeName = "machineIdentifier")]
|
||||||
public string MachineIdentifier { get; set; }
|
public string MachineIdentifier { get; set; }
|
||||||
[XmlAttribute(AttributeName = "name")]
|
[XmlAttribute(AttributeName = "name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
[XmlAttribute(AttributeName = "lastSeenAt")]
|
[XmlAttribute(AttributeName = "lastSeenAt")]
|
||||||
public string LastSeenAt { get; set; }
|
public string LastSeenAt { get; set; }
|
||||||
[XmlAttribute(AttributeName = "numLibraries")]
|
[XmlAttribute(AttributeName = "numLibraries")]
|
||||||
public string NumLibraries { get; set; }
|
public string NumLibraries { get; set; }
|
||||||
[XmlAttribute(AttributeName = "owned")]
|
[XmlAttribute(AttributeName = "owned")]
|
||||||
public string Owned { get; set; }
|
public string Owned { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[XmlRoot(ElementName = "User")]
|
[XmlRoot(ElementName = "User")]
|
||||||
public class UserFriends
|
public class UserFriends
|
||||||
{
|
{
|
||||||
[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")]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
[XmlAttribute(AttributeName = "email")]
|
[XmlAttribute(AttributeName = "email")]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
[XmlAttribute(AttributeName = "recommendationsPlaylistId")]
|
[XmlAttribute(AttributeName = "recommendationsPlaylistId")]
|
||||||
public string RecommendationsPlaylistId { get; set; }
|
public string RecommendationsPlaylistId { get; set; }
|
||||||
[XmlAttribute(AttributeName = "thumb")]
|
[XmlAttribute(AttributeName = "thumb")]
|
||||||
public string Thumb { get; set; }
|
public string Thumb { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[XmlRoot(ElementName = "MediaContainer")]
|
[XmlRoot(ElementName = "MediaContainer")]
|
||||||
public class PlexFriends
|
public class PlexFriends
|
||||||
{
|
{
|
||||||
[XmlElement(ElementName = "User")]
|
[XmlElement(ElementName = "User")]
|
||||||
public UserFriends[] User { get; set; }
|
public UserFriends[] User { get; set; }
|
||||||
[XmlAttribute(AttributeName = "friendlyName")]
|
[XmlAttribute(AttributeName = "friendlyName")]
|
||||||
public string FriendlyName { get; set; }
|
public string FriendlyName { get; set; }
|
||||||
[XmlAttribute(AttributeName = "identifier")]
|
[XmlAttribute(AttributeName = "identifier")]
|
||||||
public string Identifier { get; set; }
|
public string Identifier { get; set; }
|
||||||
[XmlAttribute(AttributeName = "machineIdentifier")]
|
[XmlAttribute(AttributeName = "machineIdentifier")]
|
||||||
public string MachineIdentifier { get; set; }
|
public string MachineIdentifier { get; set; }
|
||||||
[XmlAttribute(AttributeName = "totalSize")]
|
[XmlAttribute(AttributeName = "totalSize")]
|
||||||
public string TotalSize { get; set; }
|
public string TotalSize { get; set; }
|
||||||
[XmlAttribute(AttributeName = "size")]
|
[XmlAttribute(AttributeName = "size")]
|
||||||
public string Size { get; set; }
|
public string Size { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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…
Add table
Add a link
Reference in a new issue