sharee.bike-App/TINKLib/Model/User/Account/Account.cs
2022-05-15 19:56:03 +02:00

103 lines
4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace TINK.Model.User.Account
{
/// <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,
}
/// <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
}
/// <summary>
/// Holds account data.
/// </summary>
public class Account : IAccount
{
public const bool DEFAULTISAGBACKNOWLEDGED = false;
/// <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.");
}
public Account(IAccount source) : this(source?.Mail, source?.Pwd, source?.IsAgbAcknowledged ?? DEFAULTISAGBACKNOWLEDGED, source?.SessionCookie, source?.Group, source?.DebugLevel ?? Permissions.None)
{
}
/// <summary>Mail address of the account holder.</summary>
public string Mail { get; }
/// <summary>Password of to authenticate.</summary>
public string Pwd { get; }
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged { get; }
/// <summary>Session cookie used to sign in to copri.</summary>
public string SessionCookie { get; }
/// <summary>Debug level used to determine which features are available.</summary>
public Permissions DebugLevel { get; }
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
public IEnumerable<string> Group { get; }
}
}