/// <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; }
/// <summary> /// Check if the current user credentials are valid with the server or not /// in a background task. /// </summary> /// <returns>The OperationReturnMessage from the server.</returns> public static async Task <OperationReturnMessage> CheckLoginStatusAsync() { string username = await SecureStorage.GetAsync("username"); Username = username; if (CrossConnectivity.Current.IsConnected) { if ((username != null) && (username != "")) { OperationReturnMessage message = ServerOperations.LoginAccount(username, await SecureStorage.GetAsync("password")); if (message != OperationReturnMessage.FalseFailedConnection) { if (message == OperationReturnMessage.True) { IsLoggedIn = true; EmailConfirmed = true; } else if (message == OperationReturnMessage.TrueConfirmEmail) { IsLoggedIn = true; EmailConfirmed = false; } else { IsLoggedIn = false; EmailConfirmed = false; Username = "******"; await SecureStorage.SetAsync("password", ""); } return(message); } else { return(CannotConnectToServer(username)); } } else { Username = "******"; IsLoggedIn = false; EmailConfirmed = false; Username = "******"; return(OperationReturnMessage.False); } } else // If the user is offline { return(CannotConnectToServer(username)); } }