sharee.bike-App/TINKLib/Model/User/Account/Account.cs
2021-06-26 20:57:55 +02:00

93 lines
3.5 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.
All = PickCopriServer +
ManageCopriCacheExpiration +
ManagePolling +
PickLockServiceImplementation +
PickLocationServiceImplementation +
PickLoggingLevel +
ShowDiagnostics +
SwitchNoSiteCaching +
ReportLevel,
}
/// <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
{
/// <summary> Constructs an account object.</summary>
/// <param name="mail">Mail addresss.</param>
/// <param name="password">Password.</param>
/// <param name="sessionCookie">Session cookie from copri.</param>
/// <param name="group">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,
string sessionCookie,
IEnumerable<string> group,
Permissions debugLevel = Permissions.None)
{
Mail = mail;
Pwd = password;
SessionCookie = sessionCookie;
DebugLevel = debugLevel;
Group = group != null
? new HashSet<string>(group).ToList()
: throw new ArgumentException("Can not instantiate account object. Reference to group list must not be empty.");
}
public Account(IAccount p_oSource) : this(p_oSource?.Mail, p_oSource?.Pwd, p_oSource?.SessionCookie, p_oSource?.Group, p_oSource?.DebugLevel ?? Permissions.None)
{
}
/// <summary>Mail address.</summary>
public string Mail { get; }
/// <summary>Password of the account.</summary>
public string Pwd { 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; }
}
}