sharee.bike-App/TINKLib/Model/User/Account/Account.cs

103 lines
3.5 KiB
C#
Raw Normal View History

2021-05-13 20:03:07 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
namespace TINK.Model.User.Account
{
2022-09-06 16:08:19 +02:00
/// <summary> Specifies extra user permissions. </summary>
[Flags]
public enum Permissions
{
None = 0, // No extra permissions.
PickCopriServer = 2, // Allows user to switch COPRI server.
ManageCopriCacheExpiration = 4, // Allows to manage the livetime of COPRI cache entries.
ManagePolling = 8, // Turn polling off or on and set pollig frequency.
PickLockServiceImplementation = 16, // Allows to pick the implementation which controls bluetooth lock mangement.
PickLocationServiceImplementation = 32, // Allows to pick the implementation which gets location information.
PickLoggingLevel = 64, // Allows to select the logging level.
ShowDiagnostics = 128, // Turns on display of diagnostics.
SwitchNoSiteCaching = 1024, // Allows to turn off/ on caching of sites displayed in app hosted by COPRI
ReportLevel = 2048, // Allows extent to show error messages.
SwitchTheme = 4096, // Allows user to switch theme (sharee.bike, Meinkonrad, Lastenrad Bayern)
All = PickCopriServer +
ManageCopriCacheExpiration +
ManagePolling +
PickLockServiceImplementation +
PickLocationServiceImplementation +
PickLoggingLevel +
ShowDiagnostics +
SwitchNoSiteCaching +
ReportLevel +
SwitchTheme,
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Specifies parts of account data.
/// </summary>
/// <remarks>
/// Usage: Account can be valid (user and password set) partly valid or completely invalid.
/// </remarks>
[Flags]
public enum Elements
{
None = 0,
Mail = 1,
Password = 2,
Account = Mail + Password
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds account data.
/// </summary>
public class Account : IAccount
{
public const bool DEFAULTISAGBACKNOWLEDGED = false;
2022-01-04 18:59:16 +01:00
2022-09-06 16:08:19 +02:00
/// <summary> Constructs an account object.</summary>
/// <param name="mail">Mail address of the account holder.</param>
/// <param name="password">Password.</param>
/// <param name="sessionCookie">Session cookie from copri.</param>
/// <param name="bikeGroup">Group holdig info about Group (TINK, Konrad, ...)</param>
/// <param name="p_iDebugLevel">Flag which controls display of debug settings.</param>
public Account(
string mail,
string password,
bool isAgbAcknowledged,
string sessionCookie,
IEnumerable<string> bikeGroup,
Permissions debugLevel = Permissions.None)
{
Mail = mail;
Pwd = password;
IsAgbAcknowledged = isAgbAcknowledged;
SessionCookie = sessionCookie;
DebugLevel = debugLevel;
Group = bikeGroup != null
? new HashSet<string>(bikeGroup).ToList()
: throw new ArgumentException("Can not instantiate account object. Reference to group list must not be empty.");
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public Account(IAccount source) : this(source?.Mail, source?.Pwd, source?.IsAgbAcknowledged ?? DEFAULTISAGBACKNOWLEDGED, source?.SessionCookie, source?.Group, source?.DebugLevel ?? Permissions.None)
{
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Mail address of the account holder.</summary>
public string Mail { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Password of to authenticate.</summary>
public string Pwd { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged { get; }
2022-01-04 18:59:16 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>Session cookie used to sign in to copri.</summary>
public string SessionCookie { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Debug level used to determine which features are available.</summary>
public Permissions DebugLevel { get; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
public IEnumerable<string> Group { get; }
}
2021-05-13 20:03:07 +02:00
}