36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using MauiApp.Core.Business.Contracts;
|
|
using MauiApp.Core.RestClient.IntegryApi.Contracts;
|
|
using MauiApp.Core.System.Device.Contracts;
|
|
|
|
namespace MauiApp.Core.Business;
|
|
|
|
public class AccountService(IUserSessionService userSessionService, IDeviceService deviceService,
|
|
IIntegryLoginRestClient loginRestClient) : IAccountService
|
|
{
|
|
public bool IsLoggedIn => userSessionService?.Session != null;
|
|
|
|
public async Task Login(string username, string password)
|
|
{
|
|
string profileDb = "integry";
|
|
|
|
var response = await loginRestClient.Login(username, password, await deviceService.GetDeviceId(), profileDb);
|
|
|
|
await userSessionService.CreateNewSession(username, response.AccessToken, response.RefreshToken,
|
|
null, profileDb);
|
|
}
|
|
|
|
public async Task<bool> CheckAndRefreshLogin()
|
|
{
|
|
if (userSessionService.Session is null)
|
|
return false;
|
|
|
|
//TODO: Refresh token here
|
|
|
|
return true;
|
|
}
|
|
|
|
public async Task Logout()
|
|
{
|
|
await userSessionService.ClearStoredSession();
|
|
}
|
|
} |