2using System.Text.RegularExpressions;
3using CommunityToolkit.Mvvm.ComponentModel;
4using CommunityToolkit.Mvvm.Input;
22 await base.DoAssignProperties();
31 await base.OnInitialize();
33 ServiceRef.XmppService.ConnectionStateChanged += this.XmppService_ConnectionStateChanged;
39 ServiceRef.XmppService.ConnectionStateChanged -= this.XmppService_ConnectionStateChanged;
41 await base.OnDispose();
44 private Task XmppService_ConnectionStateChanged(
object _,
XmppState NewState)
47 this.CreateAccountCommand.NotifyCanExecuteChanged();
48 return Task.CompletedTask;
52 private string? username;
54 partial
void OnUsernameChanged(
string? value)
56 this.UsernameIsValid = IsValidUsernameString(value);
57 this.OnPropertyChanged(nameof(this.CanCreateAccount));
59 if (this.UsernameIsValid)
61 this.AlternativeName =
string.Empty;
62 this.LocalizedValidationMessage =
string.Empty;
66 this.LocalizedValidationMessage =
ServiceRef.
Localizer[nameof(AppResources.InvalidUsernameCharacters)];
69 this.CreateAccountCommand.NotifyCanExecuteChanged();
73 private string? alternativeName;
76 [NotifyCanExecuteChangedFor(nameof(CreateAccountCommand))]
77 private bool usernameIsValid;
80 private string? localizedValidationMessage;
87 public bool CanCreateAccount => this.UsernameIsValid && !
string.IsNullOrEmpty(this.Username) &&
string.IsNullOrEmpty(this.AlternativeName) && !this.IsBusy;
89 [RelayCommand(CanExecute = nameof(CanCreateAccount))]
90 private async Task CreateAccount()
95 string? account = this.Username;
97 if (
string.IsNullOrEmpty(account))
116 typeof(
App).Assembly, OnConnected);
122 if (Alternatives is not
null && Alternatives.Length > 0)
124 Random rnd =
new Random();
126 this.UsernameIsValid =
false;
127 this.AlternativeName = Alternatives[rnd.Next(0, Alternatives.Length)];
128 this.LocalizedValidationMessage =
ServiceRef.
Localizer[nameof(AppResources.UsernameNameAlreadyTaken)];
130 else if (ErrorMessage is not
null)
151 private void SelectName(
string? name)
153 if (
string.IsNullOrEmpty(name))
155 this.Username = name;
156 this.AlternativeName =
string.Empty;
166 if (
string.IsNullOrWhiteSpace(source))
170 string normalizedSource = source.Normalize(NormalizationForm.FormC).ToLowerInvariant();
173 IEnumerable<string?> processedParts = normalizedSource
174 .Split(
' ', StringSplitOptions.RemoveEmptyEntries)
175 .Select(ReplaceInvalidUsernameCharacters)
176 .Where(processedPart => !
string.IsNullOrEmpty(processedPart));
178 if (!processedParts.Any())
182 string result =
string.Join(
".", processedParts);
185 string randomDigits =
new Random().Next(0, 10000).ToString(
"D4");
186 result += randomDigits;
189 result = Regex.Replace(result,
@"\.+",
".");
195 internal static bool IsValidUsernameString(
string? input)
197 if (
string.IsNullOrEmpty(input))
199 foreach (
char c
in input)
257 private static string ReplaceInvalidUsernameCharacters(
string input)
259 StringBuilder sb =
new(input.Length);
260 foreach (
char c
in input)
319 return sb.ToString();
The Application class, representing an instance of the Neuro-Access app.
const string Default
The default language code.
A set of never changing property constants and helpful values.
Base class that references services in the app.
static ILogService LogService
Log service.
static INetworkService NetworkService
Network service.
static IUiService UiService
Service serializing and managing UI-related tasks.
static ITagProfile TagProfile
TAG Profile service.
static ICryptoService CryptoService
Crypto service.
static IStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
bool IsXmppConnected
If App is connected to the XMPP network.
override async Task DoAssignProperties()
string GenerateUsername(string? source)
Generates a username based on a source string.
override async Task OnDispose()
override async Task OnInitialize()
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
string PasswordHashMethod
Password hash method.
string PasswordHash
Hash value of password. Depends on method used to authenticate user.
string? Account
The account name for this profile
string? ApiKey
API Key, for creating new account.
string? ApiSecret
API Secret, for creating new account.
bool NeedsUpdating()
Returns true if the current ITagProfile needs to have its values updated, false otherwise.
void SetAccount(string AccountName, string ClientPasswordHash, string ClientPasswordHashMethod)
Set the account name and password for a new account.
string? Domain
The domain this profile is connected to.
RegistrationStep
The different steps of a TAG Profile registration journey.
XmppState
State of XMPP connection.