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

103 lines
4 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
{
/// <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
2021-06-26 20:57:55 +02:00
ReportLevel = 2048, // Allows extent to show error messages.
2022-05-15 19:56:03 +02:00
SwitchTheme = 4096, // Allows user to switch theme (sharee.bike, Meinkonrad, Lastenrad Bayern)
2021-05-13 20:03:07 +02:00
All = PickCopriServer +
ManageCopriCacheExpiration +
ManagePolling +
PickLockServiceImplementation +
PickLocationServiceImplementation +
PickLoggingLevel +
ShowDiagnostics +
2021-06-26 20:57:55 +02:00
SwitchNoSiteCaching +
2022-05-15 19:56:03 +02:00
ReportLevel +
SwitchTheme,
2021-05-13 20:03:07 +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
}
/// <summary>
/// Holds account data.
/// </summary>
public class Account : IAccount
{
2022-01-04 18:59:16 +01:00
public const bool DEFAULTISAGBACKNOWLEDGED = false;
2021-05-13 20:03:07 +02:00
/// <summary> Constructs an account object.</summary>
2021-11-07 19:42:59 +01:00
/// <param name="mail">Mail address of the account holder.</param>
2021-06-26 20:57:55 +02:00
/// <param name="password">Password.</param>
/// <param name="sessionCookie">Session cookie from copri.</param>
2021-11-07 19:42:59 +01:00
/// <param name="bikeGroup">Group holdig info about Group (TINK, Konrad, ...)</param>
2021-05-13 20:03:07 +02:00
/// <param name="p_iDebugLevel">Flag which controls display of debug settings.</param>
public Account(
2022-08-30 15:42:25 +02:00
string mail,
string password,
2022-01-04 18:59:16 +01:00
bool isAgbAcknowledged,
2021-06-26 20:57:55 +02:00
string sessionCookie,
2021-11-07 19:42:59 +01:00
IEnumerable<string> bikeGroup,
2021-05-13 20:03:07 +02:00
Permissions debugLevel = Permissions.None)
{
2021-06-26 20:57:55 +02:00
Mail = mail;
Pwd = password;
2022-01-04 18:59:16 +01:00
IsAgbAcknowledged = isAgbAcknowledged;
2021-06-26 20:57:55 +02:00
SessionCookie = sessionCookie;
2021-05-13 20:03:07 +02:00
DebugLevel = debugLevel;
2021-11-07 19:42:59 +01:00
Group = bikeGroup != null
2022-08-30 15:42:25 +02:00
? new HashSet<string>(bikeGroup).ToList()
2021-05-13 20:03:07 +02:00
: throw new ArgumentException("Can not instantiate account object. Reference to group list must not be empty.");
}
2022-01-04 18:59:16 +01: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
{
}
2021-11-07 19:42:59 +01:00
/// <summary>Mail address of the account holder.</summary>
2021-05-13 20:03:07 +02:00
public string Mail { get; }
2021-11-07 19:42:59 +01:00
/// <summary>Password of to authenticate.</summary>
2021-05-13 20:03:07 +02:00
public string Pwd { get; }
2022-01-04 18:59:16 +01:00
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged { get; }
2021-05-13 20:03:07 +02:00
/// <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; }
}
}