rework model to have a client and server variant
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
using OwnChar.Api.Exceptions;
|
||||
using OwnChar.Api.Managers;
|
||||
using OwnChar.Data;
|
||||
using OwnChar.Manager.Modules;
|
||||
using OwnChar.Model;
|
||||
using Pilz.Cryptography;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace OwnChar;
|
||||
|
||||
public class OwnCharManager : IOwnCharManager
|
||||
{
|
||||
// User
|
||||
public bool IsLoggedIn => CurrentUser != null;
|
||||
public UserAccount? CurrentUser { get; private set; }
|
||||
|
||||
// Data Provider
|
||||
public IDataManager? DataManager { get; set; }
|
||||
|
||||
// Manager
|
||||
public IUserManager Users { get; }
|
||||
public IGroupsManager Groups { get; }
|
||||
public ICharacterManager Characters { get; }
|
||||
|
||||
public OwnCharManager()
|
||||
{
|
||||
Users = new UserManager(this);
|
||||
Groups = new GroupsManager(this);
|
||||
Characters = new CharacterManager(this);
|
||||
}
|
||||
|
||||
[MemberNotNull(nameof(CurrentUser), nameof(DataManager))]
|
||||
internal protected void CheckLogin()
|
||||
{
|
||||
if (!IsLoggedIn || DataManager == null)
|
||||
throw new LoginException("You are already logged in!");
|
||||
}
|
||||
|
||||
/// <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, OwnCharUtils.HashPassword(username, password));
|
||||
DataManager = proxy;
|
||||
|
||||
return IsLoggedIn;
|
||||
}
|
||||
|
||||
/// <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