mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-19 15:33:03 +03:00
Moved the http server to it's own assembly. added comments and made other minor re-organizations.
This commit is contained in:
parent
6fbd5cf464
commit
80b3ad7bd2
@@ -6,8 +6,14 @@ using MediaBrowser.Model.Users;
|
||||
|
||||
namespace MediaBrowser.Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages users within the system
|
||||
/// </summary>
|
||||
public class UserController
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the path to folder that contains data for all the users
|
||||
/// </summary>
|
||||
public string UsersPath { get; set; }
|
||||
|
||||
public UserController(string usersPath)
|
||||
@@ -15,6 +21,9 @@ namespace MediaBrowser.Controller
|
||||
UsersPath = usersPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all users within the system
|
||||
/// </summary>
|
||||
public IEnumerable<User> GetAllUsers()
|
||||
{
|
||||
if (!Directory.Exists(UsersPath))
|
||||
@@ -37,6 +46,9 @@ namespace MediaBrowser.Controller
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a User from it's directory
|
||||
/// </summary>
|
||||
private User GetFromDirectory(string path)
|
||||
{
|
||||
string file = Path.Combine(path, "user.js");
|
||||
@@ -44,17 +56,28 @@ namespace MediaBrowser.Controller
|
||||
return JsonSerializer.DeserializeFromFile<User>(file);
|
||||
}
|
||||
|
||||
public void CreateUser(User user)
|
||||
/// <summary>
|
||||
/// Creates a User with a given name
|
||||
/// </summary>
|
||||
public User CreateUser(string name)
|
||||
{
|
||||
user.Id = Guid.NewGuid();
|
||||
var now = DateTime.Now;
|
||||
|
||||
user.DateCreated = user.DateModified = DateTime.Now;
|
||||
User user = new User()
|
||||
{
|
||||
Name = name,
|
||||
Id = Guid.NewGuid(),
|
||||
DateCreated = now,
|
||||
DateModified = now
|
||||
};
|
||||
|
||||
string userFolder = Path.Combine(UsersPath, user.Id.ToString());
|
||||
user.Path = Path.Combine(UsersPath, user.Id.ToString());
|
||||
|
||||
Directory.CreateDirectory(userFolder);
|
||||
Directory.CreateDirectory(user.Path);
|
||||
|
||||
JsonSerializer.SerializeToFile(user, Path.Combine(userFolder, "user.js"));
|
||||
JsonSerializer.SerializeToFile(user, Path.Combine(user.Path, "user.js"));
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user