mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Serilog;
|
|
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";
|
|
|
|
/// <summary> Holds key for flag is agb acknowledged. </summary>
|
|
private const string KEY_ISAGBACKNOWLEDGED = "IsAgbAcknowledged";
|
|
|
|
public IAccount Delete(IAccount account)
|
|
{
|
|
SecureStorage.RemoveAll();
|
|
return new EmptyAccount();
|
|
}
|
|
|
|
public async Task<IAccount> Load()
|
|
{
|
|
|
|
var mail = string.Empty;
|
|
var isAgbAcknowledged = Account.DEFAULTISAGBACKNOWLEDGED;
|
|
var sessionCookie = string.Empty;
|
|
var debugLevel = Permissions.None;
|
|
|
|
try
|
|
{
|
|
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
|
|
bool.TryParse(await SecureStorage.GetAsync(KEY_ISAGBACKNOWLEDGED), out isAgbAcknowledged);
|
|
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,
|
|
isAgbAcknowledged,
|
|
sessionCookie,
|
|
new List<string>(),
|
|
debugLevel);
|
|
}
|
|
|
|
public async Task Save(IAccount mailAndPwd)
|
|
{
|
|
try
|
|
{
|
|
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
|
|
await SecureStorage.SetAsync(KEY_ISAGBACKNOWLEDGED, mailAndPwd.IsAgbAcknowledged.ToString());
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|