Version 3.0.338

This commit is contained in:
Anja Müller-Meißner 2022-09-06 16:08:19 +02:00 committed by Anja
parent 573fe77e12
commit 0468955d49
751 changed files with 62747 additions and 60672 deletions

View file

@ -4,99 +4,99 @@ 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 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>
/// 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>
/// 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.");
}
/// <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)
{
}
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>Mail address of the account holder.</summary>
public string Mail { get; }
/// <summary>Password of to authenticate.</summary>
public string Pwd { get; }
/// <summary>Password of to authenticate.</summary>
public string Pwd { get; }
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged { 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>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>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; }
}
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
public IEnumerable<string> Group { get; }
}
}

View file

@ -3,32 +3,32 @@ using TINK.Model.Connector.Filter;
namespace TINK.Model.User.Account
{
public static class AccountExtensions
{
/// <summary> Gets information whether user is logged in or not from account object. </summary>
/// <param name="account">Object to get information from.</param>
/// <returns>True if user is logged in, false if not.</returns>
public static bool GetIsLoggedIn(this IAccount account)
{
return !string.IsNullOrEmpty(account.Mail)
&& !string.IsNullOrEmpty(account.SessionCookie);
}
public static class AccountExtensions
{
/// <summary> Gets information whether user is logged in or not from account object. </summary>
/// <param name="account">Object to get information from.</param>
/// <returns>True if user is logged in, false if not.</returns>
public static bool GetIsLoggedIn(this IAccount account)
{
return !string.IsNullOrEmpty(account.Mail)
&& !string.IsNullOrEmpty(account.SessionCookie);
}
/// <summary>
/// Filters bike groups depending on whether user has access to all groups of bikes.
/// Some user may be "TINK"- user only, some "Konrad" and some may be "TINK" and "Konrad" users.
/// </summary>
/// <param name="account">Account to filter with.</param>
/// <param name="filter">Groups to filter.</param>
/// <returns>Filtered bike groups.</returns>
public static IEnumerable<string> DoFilter(
this IAccount account,
IEnumerable<string> filter)
{
/// <summary>
/// Filters bike groups depending on whether user has access to all groups of bikes.
/// Some user may be "TINK"- user only, some "Konrad" and some may be "TINK" and "Konrad" users.
/// </summary>
/// <param name="account">Account to filter with.</param>
/// <param name="filter">Groups to filter.</param>
/// <returns>Filtered bike groups.</returns>
public static IEnumerable<string> DoFilter(
this IAccount account,
IEnumerable<string> filter)
{
return GetIsLoggedIn(account)
? GroupFilterFactory.Create(account.Group).DoFilter(filter) // Filter if user is logged in.
: new NullGroupFilter().DoFilter(filter); // Do not filter if no user is logged in.
}
}
return GetIsLoggedIn(account)
? GroupFilterFactory.Create(account.Group).DoFilter(filter) // Filter if user is logged in.
: new NullGroupFilter().DoFilter(filter); // Do not filter if no user is logged in.
}
}
}

View file

@ -2,72 +2,72 @@
namespace TINK.Model.User.Account
{
/// <summary>
/// Holds email address and password.
/// </summary>
public class AccountMutable : IAccount
{
/// <summary>
/// Holds the account data.
/// </summary>
private Account m_oAccount;
/// <summary>
/// Holds email address and password.
/// </summary>
public class AccountMutable : IAccount
{
/// <summary>
/// Holds the account data.
/// </summary>
private Account m_oAccount;
public AccountMutable(IAccount p_oSource)
{
m_oAccount = new Account(p_oSource);
}
public AccountMutable(IAccount p_oSource)
{
m_oAccount = new Account(p_oSource);
}
public void Copy(IAccount p_oSource)
{
m_oAccount = new Account(p_oSource);
}
public void Copy(IAccount p_oSource)
{
m_oAccount = new Account(p_oSource);
}
/// <summary>
/// Mail address.
/// </summary>
public string Mail
{
get { return m_oAccount.Mail; }
set { m_oAccount = new Account(value, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
/// Mail address.
/// </summary>
public string Mail
{
get { return m_oAccount.Mail; }
set { m_oAccount = new Account(value, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
/// Password of the account.
/// </summary>
public string Pwd
{
get { return m_oAccount.Pwd; }
set { m_oAccount = new Account(m_oAccount.Mail, value, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
/// Password of the account.
/// </summary>
public string Pwd
{
get { return m_oAccount.Pwd; }
set { m_oAccount = new Account(m_oAccount.Mail, value, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged => m_oAccount.IsAgbAcknowledged;
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged => m_oAccount.IsAgbAcknowledged;
/// <summary>
/// Session cookie used to sign in to copri.
/// </summary>
public string SessionCookie
{
get { return m_oAccount.SessionCookie; }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, value, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
/// Session cookie used to sign in to copri.
/// </summary>
public string SessionCookie
{
get { return m_oAccount.SessionCookie; }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, value, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
/// Holds the group of the bike (TINK, Konrad, ...).
/// </summary>
public IEnumerable<string> Group
{
get { return m_oAccount.Group; }
}
/// <summary>
/// Holds the group of the bike (TINK, Konrad, ...).
/// </summary>
public IEnumerable<string> Group
{
get { return m_oAccount.Group; }
}
/// <summary>
/// Debug level used to determine which features are available.
/// </summary>
public Permissions DebugLevel
{
get { return m_oAccount.DebugLevel; }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, value); }
}
}
/// <summary>
/// Debug level used to determine which features are available.
/// </summary>
public Permissions DebugLevel
{
get { return m_oAccount.DebugLevel; }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, value); }
}
}
}

View file

@ -2,19 +2,19 @@
namespace TINK.Model.User.Account
{
/// <summary> Represents an empty account.</summary>
public class EmptyAccount : IAccount
{
public string Mail => null;
/// <summary> Represents an empty account.</summary>
public class EmptyAccount : IAccount
{
public string Mail => null;
public string Pwd => null;
public string Pwd => null;
public bool IsAgbAcknowledged => false;
public bool IsAgbAcknowledged => false;
public string SessionCookie => null;
public string SessionCookie => null;
public Permissions DebugLevel => Permissions.None;
public Permissions DebugLevel => Permissions.None;
public IEnumerable<string> Group => new List<string>();
}
public IEnumerable<string> Group => new List<string>();
}
}

View file

@ -2,27 +2,27 @@
namespace TINK.Model.User.Account
{
/// <summary>
/// Holds account data.
/// </summary>
public interface IAccount
{
/// <summary>Mail address.</summary>
string Mail { get; }
/// <summary>
/// Holds account data.
/// </summary>
public interface IAccount
{
/// <summary>Mail address.</summary>
string Mail { get; }
/// <summary>Password of the account.</summary>
string Pwd { get; }
/// <summary>Password of the account.</summary>
string Pwd { get; }
/// <summary>True if user acknowleged agbs.</summary>
bool IsAgbAcknowledged { get; }
/// <summary>True if user acknowleged agbs.</summary>
bool IsAgbAcknowledged { get; }
/// <summary>Session cookie used to sign in to copri.</summary>
string SessionCookie { get; }
/// <summary>Session cookie used to sign in to copri.</summary>
string SessionCookie { get; }
/// <summary>Debug level used to determine which features are available.</summary>
Permissions DebugLevel { get; }
/// <summary>Debug level used to determine which features are available.</summary>
Permissions DebugLevel { get; }
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
IEnumerable<string> Group { get; }
}
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
IEnumerable<string> Group { get; }
}
}

View file

@ -2,25 +2,25 @@
namespace TINK.Model.User.Account
{
/// <summary>Interface to manage an account store.</summary>
public interface IStore
{
/// <summary>
/// Reads mail address and password from account store.
/// </summary>
/// <returns></returns>
Task<IAccount> Load();
/// <summary>Interface to manage an account store.</summary>
public interface IStore
{
/// <summary>
/// Reads mail address and password from account store.
/// </summary>
/// <returns></returns>
Task<IAccount> Load();
/// <summary>
/// Writes mail address and password to account store.
/// </summary>
/// <param name="mailAndPwd"></param>
Task Save(IAccount mailAndPwd);
/// <summary>
/// Writes mail address and password to account store.
/// </summary>
/// <param name="mailAndPwd"></param>
Task Save(IAccount mailAndPwd);
/// <summary>
/// Deletes mail address and password from account store.
/// </summary>
/// <returns> Empty account instance if deleting succeeded.</returns>
IAccount Delete(IAccount mailAndPwd);
}
/// <summary>
/// Deletes mail address and password from account store.
/// </summary>
/// <returns> Empty account instance if deleting succeeded.</returns>
IAccount Delete(IAccount mailAndPwd);
}
}

View file

@ -6,68 +6,68 @@ 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";
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 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";
/// <summary> Holds id of the mail address key. </summary>
private const string KEY_MAILADDRESS = "MailAddress";
/// <summary> Holds key for flag is agb acknowledged. </summary>
private const string KEY_ISAGBACKNOWLEDGED = "IsAgbAcknowledged";
/// <summary> Holds key for flag is agb acknowledged. </summary>
private const string KEY_ISAGBACKNOWLEDGED = "IsAgbAcknowledged";
public IAccount Delete(IAccount account)
{
SecureStorage.RemoveAll();
return new EmptyAccount();
}
public IAccount Delete(IAccount account)
{
SecureStorage.RemoveAll();
return new EmptyAccount();
}
public async Task<IAccount> Load()
{
public async Task<IAccount> Load()
{
var mail = string.Empty;
var isAgbAcknowledged = Account.DEFAULTISAGBACKNOWLEDGED;
var sessionCookie = string.Empty;
var debugLevel = Permissions.None;
var mail = string.Empty;
var isAgbAcknowledged = Account.DEFAULTISAGBACKNOWLEDGED;
var sessionCookie = string.Empty;
var debugLevel = Permissions.None;
try
{
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
bool.TryParse(await SecureStorage.GetAsync(KEY_ISAGBACKNOWLEDGED), out isAgbAcknowledged);
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);
}
try
{
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
bool.TryParse(await SecureStorage.GetAsync(KEY_ISAGBACKNOWLEDGED), out isAgbAcknowledged);
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,
isAgbAcknowledged,
sessionCookie,
new List<string>(),
debugLevel);
}
return new Account(
mail,
string.Empty,
isAgbAcknowledged,
sessionCookie,
new List<string>(),
debugLevel);
}
public async Task Save(IAccount mailAndPwd)
{
try
{
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
await SecureStorage.SetAsync(KEY_ISAGBACKNOWLEDGED, mailAndPwd.IsAgbAcknowledged.ToString());
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);
}
}
}
public async Task Save(IAccount mailAndPwd)
{
try
{
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
await SecureStorage.SetAsync(KEY_ISAGBACKNOWLEDGED, mailAndPwd.IsAgbAcknowledged.ToString());
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);
}
}
}
}

View file

@ -4,164 +4,164 @@ using System.Linq;
namespace TINK.Model.User.Account
{
/// <summary>
/// Holds the state of mail and password and information about some invalid parts if there are.
/// </summary>
public class State
{
/// <summary>
/// Consider state to be invalid after construction.
/// </summary>
private Elements m_eElements = Elements.None;
/// <summary>
/// Holds the state of mail and password and information about some invalid parts if there are.
/// </summary>
public class State
{
/// <summary>
/// Consider state to be invalid after construction.
/// </summary>
private Elements m_eElements = Elements.None;
private Dictionary<Elements, string> m_oDescription = new Dictionary<Elements, string>();
private Dictionary<Elements, string> m_oDescription = new Dictionary<Elements, string>();
/// <summary>
/// Constructs object to state all entries are valid.
/// </summary>
public State()
{
m_eElements = Elements.Account;
/// <summary>
/// Constructs object to state all entries are valid.
/// </summary>
public State()
{
m_eElements = Elements.Account;
m_oDescription = new Dictionary<Elements, string>
{
{ Elements.None, string.Empty },
{ Elements.Account, string.Empty }
};
}
m_oDescription = new Dictionary<Elements, string>
{
{ Elements.None, string.Empty },
{ Elements.Account, string.Empty }
};
}
/// <summary>
/// Constructs object to state some/ all elements are invalid.
/// </summary>
/// <param name="p_oValidParts">Specifies the parts which are invalid.</param>
/// <param name="p_oDescription">Description of invalid parts.</param>
public State(Elements p_oValidParts, Dictionary<Elements, string> p_oDescription)
{
m_eElements = p_oValidParts;
/// <summary>
/// Constructs object to state some/ all elements are invalid.
/// </summary>
/// <param name="p_oValidParts">Specifies the parts which are invalid.</param>
/// <param name="p_oDescription">Description of invalid parts.</param>
public State(Elements p_oValidParts, Dictionary<Elements, string> p_oDescription)
{
m_eElements = p_oValidParts;
m_oDescription = p_oDescription ?? new Dictionary<Elements, string>();
m_oDescription = p_oDescription ?? new Dictionary<Elements, string>();
// Ensure consistency
foreach (Elements l_oElement in Enum.GetValues(typeof(Elements)))
{
if (!m_oDescription.ContainsKey(l_oElement))
{
switch (l_oElement)
{
case Elements.Account:
case Elements.None:
continue;
// Ensure consistency
foreach (Elements l_oElement in Enum.GetValues(typeof(Elements)))
{
if (!m_oDescription.ContainsKey(l_oElement))
{
switch (l_oElement)
{
case Elements.Account:
case Elements.None:
continue;
}
}
m_oDescription.Add(l_oElement, string.Empty);
}
}
}
m_oDescription.Add(l_oElement, string.Empty);
}
}
}
/// <summary>
/// True if account is valid.
/// </summary>
public bool IsValid { get { return ValidElement == Elements.Account; } }
/// <summary>
/// True if account is valid.
/// </summary>
public bool IsValid { get { return ValidElement == Elements.Account; } }
/// <summary>
/// Specifies if both mail and password are valid, one of them or none.
/// </summary>
public Elements ValidElement
{
get
{
return m_eElements;
}
}
/// <summary>
/// Specifies if both mail and password are valid, one of them or none.
/// </summary>
public Elements ValidElement
{
get
{
return m_eElements;
}
}
/// <summary>
/// Holds the message about invalid elements.
/// </summary>
public Dictionary<Elements, string> Description
{
get
{
var l_oUserFriendlyDescription = new Dictionary<Elements, string>();
foreach (Elements l_oElement in Enum.GetValues(typeof(Elements)))
{
switch (l_oElement)
{
case Elements.Account:
case Elements.None:
continue;
/// <summary>
/// Holds the message about invalid elements.
/// </summary>
public Dictionary<Elements, string> Description
{
get
{
var l_oUserFriendlyDescription = new Dictionary<Elements, string>();
foreach (Elements l_oElement in Enum.GetValues(typeof(Elements)))
{
switch (l_oElement)
{
case Elements.Account:
case Elements.None:
continue;
}
}
l_oUserFriendlyDescription.Add(
l_oElement,
m_oDescription.ContainsKey(l_oElement) ? m_oDescription[l_oElement] : string.Empty);
}
l_oUserFriendlyDescription.Add(
l_oElement,
m_oDescription.ContainsKey(l_oElement) ? m_oDescription[l_oElement] : string.Empty);
}
l_oUserFriendlyDescription.Add(
Elements.Account,
string.Join(";", l_oUserFriendlyDescription.Where(x => x.Value.Length > 0).Select(x => x.Value).ToArray()));
l_oUserFriendlyDescription.Add(
Elements.Account,
string.Join(";", l_oUserFriendlyDescription.Where(x => x.Value.Length > 0).Select(x => x.Value).ToArray()));
return l_oUserFriendlyDescription;
}
}
}
return l_oUserFriendlyDescription;
}
}
}
/// <summary>
/// Verifies if a password is valid or not.
/// </summary>
/// <param name="p_strMail"></param>
/// <param name="p_strPassword"></param>
/// <returns></returns>
public delegate State PasswordValidator(string p_strMail, string p_strPassword);
/// <summary>
/// Verifies if a password is valid or not.
/// </summary>
/// <param name="p_strMail"></param>
/// <param name="p_strPassword"></param>
/// <returns></returns>
public delegate State PasswordValidator(string p_strMail, string p_strPassword);
public static class Validator
{
public static State ValidateMailAndPasswordDelegate(string p_strMail, string p_strPassword)
{
var l_oElements = Elements.None;
var l_oDescription = new Dictionary<Elements, string>();
public static class Validator
{
public static State ValidateMailAndPasswordDelegate(string p_strMail, string p_strPassword)
{
var l_oElements = Elements.None;
var l_oDescription = new Dictionary<Elements, string>();
// Validate mail address.
if (string.IsNullOrEmpty(p_strMail))
{
l_oDescription.Add(Elements.Mail, "Email Addresse darf nicht leer sein.");
}
else if (p_strMail.ToString().Split('@').Length < 2)
{
l_oDescription.Add(Elements.Mail, "Email Adresse mit Zeichen \"@\" enthalten.");
}
else if (p_strMail.ToString().Split('@')[0].Length <= 0)
{
l_oDescription.Add(Elements.Mail, "Benutzername in Email Adresse darf nicht leer sein.");
}
else if (p_strMail.ToString().Split('@')[1].Length <= 0)
{
// Data has been entered
l_oDescription.Add(Elements.Mail, "Domain- Name in Email Adresse darf nicht leer sein.");
}
else
{
// Input mail address is ok
l_oElements = Elements.Mail;
l_oDescription.Add(Elements.Mail, string.Empty);
}
// Validate mail address.
if (string.IsNullOrEmpty(p_strMail))
{
l_oDescription.Add(Elements.Mail, "Email Addresse darf nicht leer sein.");
}
else if (p_strMail.ToString().Split('@').Length < 2)
{
l_oDescription.Add(Elements.Mail, "Email Adresse mit Zeichen \"@\" enthalten.");
}
else if (p_strMail.ToString().Split('@')[0].Length <= 0)
{
l_oDescription.Add(Elements.Mail, "Benutzername in Email Adresse darf nicht leer sein.");
}
else if (p_strMail.ToString().Split('@')[1].Length <= 0)
{
// Data has been entered
l_oDescription.Add(Elements.Mail, "Domain- Name in Email Adresse darf nicht leer sein.");
}
else
{
// Input mail address is ok
l_oElements = Elements.Mail;
l_oDescription.Add(Elements.Mail, string.Empty);
}
// Validate password.
if (string.IsNullOrEmpty(p_strPassword) || p_strPassword.Length < 8)
{
// Data has been entered
l_oDescription.Add(Elements.Password, "Passwort is zu kurz.");
}
else
{
// Password is ok
l_oElements |= Elements.Password;
l_oDescription.Add(Elements.Password, string.Empty);
}
// Validate password.
if (string.IsNullOrEmpty(p_strPassword) || p_strPassword.Length < 8)
{
// Data has been entered
l_oDescription.Add(Elements.Password, "Passwort is zu kurz.");
}
else
{
// Password is ok
l_oElements |= Elements.Password;
l_oDescription.Add(Elements.Password, string.Empty);
}
return new State(l_oElements, l_oDescription);
}
}
return new State(l_oElements, l_oDescription);
}
}
}