/// <summary> /// Handle when the account is successfully created. /// </summary> /// <param name="emailConfirmed"></param> protected async void OnAccountCreated(bool emailConfirmed) { await CredentialManager.SaveCredentialAsync(this.username, this.password, emailConfirmed); this.AccountCreated?.Invoke(this, new AccountCreatedEventArgs { EmailConfirmed = emailConfirmed, Username = this.EntryUsername.Text.Trim() }); }
/// <summary> /// Change the password of the user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonChangePassword_Clicked(object sender, EventArgs e) { if (this.SetupFrameBegin(this.FrameChangePassword, this.StackLayoutChangePasswordContent)) { string oldPassword = this.EntryCurrentPasswordChangePassword.Text.Trim(); string newPassword = this.EntryNewPasswordChangePassword.Text.Trim(); string newPasswordReenter = this.EntryReenterNewPasswordChangePassword.Text.Trim(); if (newPassword == newPasswordReenter) { if (!(newPassword.Length < 8 || newPassword.Length > 16)) { if (!(newPassword.Contains(" ") || newPassword.Contains(".") || newPassword.Contains("/") || newPassword.Contains("`"))) { OperationReturnMessage message = await Task.Run(() => this.ChangePassword(oldPassword, newPassword)); if (message == OperationReturnMessage.True) { this.LabelChangePasswordMessage.Text = "Password changed successfully."; await CredentialManager.SaveCredentialAsync(CredentialManager.Username, newPassword, CredentialManager.EmailConfirmed); } else if (message == OperationReturnMessage.FalseInvalidCredentials) { this.LabelChangePasswordMessage.Text = "Incorrect current password."; } else if (message == OperationReturnMessage.FalseNoConnection) { this.LabelDeleteAccountMessage.Text = "Failed to connect to server. Please try again."; } else { this.LabelChangePasswordMessage.Text = "Password change failed - Please try again."; } } else { this.LabelChangePasswordMessage.Text = "New password must not contain empty space, \'.\', \'/\', or \'`\'"; } } else { this.LabelChangePasswordMessage.Text = "New password must be greater than 8 characters and less than 16 characters long."; } } else { this.LabelChangePasswordMessage.Text = "New passwords do not match."; } } this.SetupFrameEnd(this.StackLayoutChangePasswordContent); }
/// <summary> /// when the login button is clicked, attempt to login /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonLogin_Clicked(object sender, EventArgs e) { this.LabelMessage.Text = ""; this.ButtonLogin.IsEnabled = false; this.ButtonToCreateAccountPage.IsEnabled = false; string username = this.EntryUsername.Text.Trim(); string password = this.EntryPassword.Text; this.ActivityIndicator.IsVisible = true; this.ActivityIndicator.IsRunning = true; OperationReturnMessage response = await Task.Run(() => ServerOperations.LoginAccount(username, password)); if (response != OperationReturnMessage.FalseFailedConnection) { if (response == OperationReturnMessage.True) { await CredentialManager.SaveCredentialAsync(username, password, true); this.OnLoggedIn(); } else if (response == OperationReturnMessage.TrueConfirmEmail) { var confirmationPage = new EmailConfirmationPage(username, password); confirmationPage.EmailConfirmed += this.OnEmailConfirmed; await this.Navigation.PushModalAsync(confirmationPage); await CredentialManager.SaveCredentialAsync(username, password, false); this.OnLoggedIn(); } else if (response == OperationReturnMessage.FalseInvalidCredentials) { this.LabelMessage.Text = "Login Failed - Username and/or Password are Incorrect."; } else { this.LabelMessage.Text = "Login Failed."; } } else { this.LabelMessage.Text = "Connection failed: Please try again."; } this.ButtonToCreateAccountPage.IsEnabled = true; this.ActivityIndicator.IsRunning = false; this.ActivityIndicator.IsVisible = false; this.EntryPassword.Text = ""; this.ButtonLogin.IsEnabled = true; }