diff options
Diffstat (limited to 'MediaBrowser.Controller/UserController.cs')
| -rw-r--r-- | MediaBrowser.Controller/UserController.cs | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/MediaBrowser.Controller/UserController.cs b/MediaBrowser.Controller/UserController.cs index 04ff6d215..7fac4392e 100644 --- a/MediaBrowser.Controller/UserController.cs +++ b/MediaBrowser.Controller/UserController.cs @@ -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
+ };
+
+ user.Path = Path.Combine(UsersPath, user.Id.ToString());
- string userFolder = Path.Combine(UsersPath, user.Id.ToString());
+ Directory.CreateDirectory(user.Path);
- Directory.CreateDirectory(userFolder);
+ JsonSerializer.SerializeToFile(user, Path.Combine(user.Path, "user.js"));
- JsonSerializer.SerializeToFile(user, Path.Combine(userFolder, "user.js"));
+ return user;
}
}
}
|
