2021-06-26 20:57:55 +02:00
|
|
|
|
using Serilog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xamarin.Essentials;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.User.Account
|
|
|
|
|
{
|
|
|
|
|
public class Store : IStore
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Holds id of the debug level key. </summary>
|
|
|
|
|
private const string KEY_DEBUGLEVEL = "DebugLevel";
|
|
|
|
|
|
|
|
|
|
/// <summary> Holds the id of the session. </summary>
|
|
|
|
|
private const string KEY_SESSIONCOOKIE = "SessionCookie";
|
|
|
|
|
|
|
|
|
|
/// <summary> Holds id of the mail address key. </summary>
|
|
|
|
|
private const string KEY_MAILADDRESS = "MailAddress";
|
|
|
|
|
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <summary> Holds key for flag is agb acknowledged. </summary>
|
|
|
|
|
private const string KEY_ISAGBACKNOWLEDGED = "IsAgbAcknowledged";
|
|
|
|
|
|
2021-06-26 20:57:55 +02:00
|
|
|
|
public IAccount Delete(IAccount account)
|
|
|
|
|
{
|
|
|
|
|
SecureStorage.RemoveAll();
|
|
|
|
|
return new EmptyAccount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IAccount> Load()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var mail = string.Empty;
|
2022-01-04 18:59:16 +01:00
|
|
|
|
var isAgbAcknowledged = Account.DEFAULTISAGBACKNOWLEDGED;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
var sessionCookie = string.Empty;
|
|
|
|
|
var debugLevel = Permissions.None;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bool.TryParse(await SecureStorage.GetAsync(KEY_ISAGBACKNOWLEDGED), out isAgbAcknowledged);
|
2021-06-26 20:57:55 +02:00
|
|
|
|
sessionCookie = await SecureStorage.GetAsync(KEY_SESSIONCOOKIE);
|
|
|
|
|
Enum.TryParse(await SecureStorage.GetAsync(KEY_DEBUGLEVEL), out debugLevel);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Log.ForContext<Store>().Error("Loading account from store failed. {Exception}", exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Account(
|
|
|
|
|
mail,
|
|
|
|
|
string.Empty,
|
2022-01-04 18:59:16 +01:00
|
|
|
|
isAgbAcknowledged,
|
2021-06-26 20:57:55 +02:00
|
|
|
|
sessionCookie,
|
|
|
|
|
new List<string>(),
|
|
|
|
|
debugLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Save(IAccount mailAndPwd)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
|
2022-01-04 18:59:16 +01:00
|
|
|
|
await SecureStorage.SetAsync(KEY_ISAGBACKNOWLEDGED, mailAndPwd.IsAgbAcknowledged.ToString());
|
2021-06-26 20:57:55 +02:00
|
|
|
|
await SecureStorage.SetAsync(KEY_SESSIONCOOKIE, mailAndPwd.SessionCookie);
|
|
|
|
|
await SecureStorage.SetAsync(KEY_DEBUGLEVEL, mailAndPwd.DebugLevel.ToString());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Log.ForContext<Store>().Error("Saving account from store failed. {Exception}", exception);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|