/// <summary> /// Change the email of the account. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonChangeEmail_Clicked(object sender, EventArgs e) { if (this.SetupFrameBegin(this.FrameChangeEmail, this.StackLayoutChangeEmailContent)) { OperationReturnMessage message = await Task.Run(() => this.ChangeEmail( this.EntryEnterPasswordChangeEmail.Text, this.EntryEnterNewEmailChangeEmail.Text)); if (message == OperationReturnMessage.TrueConfirmEmail) { this.LabelChangeEmailMessage.Text = "Email Changed. Please Confirm Email."; EmailConfirmationPage emailConfirmationPage = new EmailConfirmationPage( CredentialManager.Username, this.EntryEnterPasswordChangeEmail.Text); emailConfirmationPage.EmailConfirmed += this.OnEmailConfirmed; emailConfirmationPage.ConfirmLaterSelected += this.OnConfirmLaterSelected; await this.Navigation.PushModalAsync(emailConfirmationPage, true); } else if (message == OperationReturnMessage.FalseInvalidCredentials) { this.LabelChangeEmailMessage.Text = "Incorrect password."; } else if (message == OperationReturnMessage.FalseInvalidEmail) { this.LabelChangeEmailMessage.Text = "Invalid email. Please check the email and try again."; } else if (message == OperationReturnMessage.FalseNoConnection) { this.LabelDeleteAccountMessage.Text = "Failed to connect to server. Please try again."; } } this.SetupFrameEnd(this.StackLayoutChangeEmailContent); }
/// <summary> /// Create a new account. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonCreateAccount_Clicked(object sender, EventArgs e) { this.ButtonCreateAccount.IsEnabled = false; this.EntryEmail.IsEnabled = false; this.EntryPassword.IsEnabled = false; this.EntryUsername.IsEnabled = false; this.ActivityIndicator.IsVisible = true; this.ActivityIndicator.IsRunning = true; string username = this.EntryUsername.Text.Trim(); string password = this.EntryPassword.Text.Trim(); string email = this.EntryEmail.Text.Trim(); // Connect to the server in a background task and await a response. OperationReturnMessage response = await Task.Run(() => ServerOperations.RegisterAccount(username, password, email)); if (response != OperationReturnMessage.FalseFailedConnection) { if (response == OperationReturnMessage.TrueConfirmEmail) { this.LabelMessage.Text = "Account successfully created."; this.username = username; this.password = password; var confirmationPage = new EmailConfirmationPage(username, password); confirmationPage.EmailConfirmed += this.OnEmailConfirmed; confirmationPage.ConfirmLaterSelected += this.OnConfirmLaterSelected; await this.Navigation.PushModalAsync(confirmationPage); } else if (response == OperationReturnMessage.FalseUsernameAlreadyExists) { this.LabelMessage.Text = $"Account could not be created - Username already exists."; } else if (response == OperationReturnMessage.FalseInvalidEmail) { this.LabelMessage.Text = $"Account could not be created - Invalid Email."; } else { this.LabelMessage.Text = $"Account could not be created."; } } else { this.LabelMessage.Text = "Connection failed: Please try again."; } this.ButtonCreateAccount.IsEnabled = true; this.EntryEmail.IsEnabled = true; this.EntryPassword.IsEnabled = true; this.EntryUsername.IsEnabled = true; this.ActivityIndicator.IsVisible = false; this.ActivityIndicator.IsRunning = false; }
/// <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; }