yea boy, now I got it!
This commit is contained in:
@@ -8,11 +8,11 @@ namespace OwnChar.Manager
|
||||
public class OwnCharManager
|
||||
{
|
||||
// User
|
||||
public bool IsLoggedIn => DataProvider != null && DataProvider.IsLoggedIn;
|
||||
public UserAccount? CurrentUser => DataProvider?.CurrentUserAccount;
|
||||
public bool IsLoggedIn => CurrentUser != null;
|
||||
public UserAccount? CurrentUser { get; private set; }
|
||||
|
||||
// Data Provider
|
||||
public IDataProvider? DataProvider { get; set; }
|
||||
public IDataProxy? DataProxy { get; set; }
|
||||
|
||||
// Manager
|
||||
public UserManager Users { get; }
|
||||
@@ -26,7 +26,7 @@ namespace OwnChar.Manager
|
||||
Characters = new(this);
|
||||
}
|
||||
|
||||
private void CheckLogin()
|
||||
internal protected void CheckLogin()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
throw new LoginException("You are already logged in!");
|
||||
@@ -36,11 +36,15 @@ namespace OwnChar.Manager
|
||||
/// 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(IDataProvider? dataProvider, string username, SecureString password)
|
||||
public bool Login(IDataProxy? proxy, string? username, SecureString? password)
|
||||
{
|
||||
CheckLogin();
|
||||
ArgumentNullException.ThrowIfNull(dataProvider);
|
||||
return dataProvider.Login(username, password) != null;
|
||||
ArgumentNullException.ThrowIfNull(proxy, nameof(proxy));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(username, nameof(username));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));
|
||||
|
||||
CurrentUser = proxy.Login(username, password);
|
||||
|
||||
return IsLoggedIn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,9 +53,7 @@ namespace OwnChar.Manager
|
||||
/// <returns></returns>
|
||||
public bool Logout()
|
||||
{
|
||||
if (DataProvider != null)
|
||||
return DataProvider.Logout();
|
||||
return true;
|
||||
return DataProxy?.Logout(CurrentUser) ?? true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user