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.
jellyfin/MediaBrowser.Controller/UserController.cs

61 lines
1.5 KiB

13 years ago
using System;
using System.Collections.Generic;
using System.IO;
using MediaBrowser.Common.Json;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Controller
{
public class UserController
{
public string UsersPath { get; set; }
public UserController(string usersPath)
{
UsersPath = usersPath;
}
public IEnumerable<User> GetAllUsers()
{
if (!Directory.Exists(UsersPath))
{
Directory.CreateDirectory(UsersPath);
}
List<User> list = new List<User>();
foreach (string folder in Directory.GetDirectories(UsersPath, "*", SearchOption.TopDirectoryOnly))
{
User item = GetFromDirectory(folder);
if (item != null)
{
list.Add(item);
}
}
return list;
}
private User GetFromDirectory(string path)
{
string file = Path.Combine(path, "user.js");
return JsonSerializer.DeserializeFromFile<User>(file);
13 years ago
}
public void CreateUser(User user)
{
user.Id = Guid.NewGuid();
user.DateCreated = user.DateModified = DateTime.Now;
string userFolder = Path.Combine(UsersPath, user.Id.ToString());
Directory.CreateDirectory(userFolder);
JsonSerializer.SerializeToFile(user, Path.Combine(userFolder, "user.js"));
13 years ago
}
}
}