code cleanup
This commit is contained in:
@@ -3,58 +3,57 @@ using OwnChar.Manager.Exceptions;
|
||||
using OwnChar.Model;
|
||||
using Pilz.Cryptography;
|
||||
|
||||
namespace OwnChar.Manager
|
||||
namespace OwnChar.Manager;
|
||||
|
||||
public class OwnCharManager
|
||||
{
|
||||
public class OwnCharManager
|
||||
// User
|
||||
public bool IsLoggedIn => CurrentUser != null;
|
||||
public UserAccount? CurrentUser { get; private set; }
|
||||
|
||||
// Data Provider
|
||||
public IDataManager? DataManager { get; set; }
|
||||
|
||||
// Manager
|
||||
public UserManager Users { get; }
|
||||
public GroupsManager Groups { get; }
|
||||
public CharacterManager Characters { get; }
|
||||
|
||||
public OwnCharManager()
|
||||
{
|
||||
// User
|
||||
public bool IsLoggedIn => CurrentUser != null;
|
||||
public UserAccount? CurrentUser { get; private set; }
|
||||
Users = new(this);
|
||||
Groups = new(this);
|
||||
Characters = new(this);
|
||||
}
|
||||
|
||||
// Data Provider
|
||||
public IDataManager? DataManager { get; set; }
|
||||
internal protected void CheckLogin()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
throw new LoginException("You are already logged in!");
|
||||
}
|
||||
|
||||
// Manager
|
||||
public UserManager Users { get; }
|
||||
public GroupsManager Groups { get; }
|
||||
public CharacterManager Characters { get; }
|
||||
/// <summary>
|
||||
/// Tries to login on the given data provider.
|
||||
/// </summary>
|
||||
/// <returns>Returns <see cref="true"/> if the login was successfull and <see cref="false"/> if not.</returns>
|
||||
public bool Login(IDataManager? proxy, string? username, SecureString? password)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(proxy, nameof(proxy));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(username, nameof(username));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));
|
||||
|
||||
public OwnCharManager()
|
||||
{
|
||||
Users = new(this);
|
||||
Groups = new(this);
|
||||
Characters = new(this);
|
||||
}
|
||||
username = username.Trim().ToLower();
|
||||
CurrentUser = proxy.Login(username, Utils.HashPassword(username, password));
|
||||
|
||||
internal protected void CheckLogin()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
throw new LoginException("You are already logged in!");
|
||||
}
|
||||
return IsLoggedIn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to login on the given data provider.
|
||||
/// </summary>
|
||||
/// <returns>Returns <see cref="true"/> if the login was successfull and <see cref="false"/> if not.</returns>
|
||||
public bool Login(IDataManager? proxy, string? username, SecureString? password)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(proxy, nameof(proxy));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(username, nameof(username));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));
|
||||
|
||||
username = username.Trim().ToLower();
|
||||
CurrentUser = proxy.Login(username, Utils.HashPassword(username, password));
|
||||
|
||||
return IsLoggedIn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the session on the current data provider.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Logout()
|
||||
{
|
||||
return DataManager?.Logout(CurrentUser) ?? true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Closes the session on the current data provider.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Logout()
|
||||
{
|
||||
return DataManager?.Logout(CurrentUser) ?? true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user