You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/PlexRequests.UI/Modules/UserManagementModule.cs

70 lines
2.1 KiB

using System.Collections.Generic;
using Nancy;
using Nancy.Responses.Negotiation;
using Nancy.Security;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
{
9 years ago
public class UserManagementModule : BaseModule
{
public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m) : base("usermanagement",pr)
9 years ago
{
this.RequiresClaims(UserClaims.Admin);
Get["/"] = x => Load();
9 years ago
Get["/users"] = x => LoadUsers();
UserMapper = m;
9 years ago
}
private ICustomUserMapper UserMapper { get; }
9 years ago
private Negotiator Load()
{
return View["Index"];
}
9 years ago
private Response LoadUsers()
{
var users = UserMapper.GetUsers();
var model = new List<UserManagementUsersViewModel>();
foreach (var user in users)
{
model.Add(new UserManagementUsersViewModel
{
//Claims = ByteConverterHelper.ReturnObject<string[]>(user.Claims),
Claims = "test",
Id = user.Id,
Username = user.UserName,
//Type = UserType.LocalUser
});
}
return Response.AsJson(users);
}
9 years ago
private Response CreateUser(string username, string password, string claims)
{
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
{
return Response.AsJson(new JsonResponseModel
{
Result = true,
Message = "Please enter in a valid Username and Password"
});
}
var user = UserMapper.CreateUser(username, password, new string[] {claims});
if (user.HasValue)
{
return Response.AsJson(new JsonResponseModel {Result = true});
}
9 years ago
return Response.AsJson(new JsonResponseModel {Result = false, Message = "Could not save user"});
}
}
}