mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-25 00:26:27 +01:00
68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
|
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";
|
|||
|
|
|||
|
public IAccount Delete(IAccount account)
|
|||
|
{
|
|||
|
SecureStorage.RemoveAll();
|
|||
|
return new EmptyAccount();
|
|||
|
}
|
|||
|
|
|||
|
public async Task<IAccount> Load()
|
|||
|
{
|
|||
|
|
|||
|
var mail = string.Empty;
|
|||
|
var sessionCookie = string.Empty;
|
|||
|
var debugLevel = Permissions.None;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
|
|||
|
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,
|
|||
|
sessionCookie,
|
|||
|
new List<string>(),
|
|||
|
debugLevel);
|
|||
|
}
|
|||
|
|
|||
|
public async Task Save(IAccount mailAndPwd)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|