public static async Task <string> LogInAsync() { LoginResponse loginResponse = await NetworkHandler.LoginAsync(); if (loginResponse == LoginResponse.Success) { IsLoggedIn = true; await UserData.SaveUser(); NetworkHandler.Initialize(); await NetworkHandler.LoadAllNotesAsync(); return(null); } else if (loginResponse == LoginResponse.Unauthanticated) { IsLoggedIn = false; return("Password or username is wrong"); } else { IsLoggedIn = false; return("Error login you in. Try again later."); } }
private async void InitializeUser() { var userLoggedInLocal = await UserData.LoadUser(); if (userLoggedInLocal) { UpdateUIAfterLogin(); NetworkHandler.Initialize(); } else { LoginWindow loginWindow = new LoginWindow(); loginWindow.Show(); } }
private async void RegisterButton_Click(object sender, RoutedEventArgs e) { if (Password.Password == PasswordConfirm.Password && Username.Text.Length > 4 && Password.Password.Length > 4) { User.username = Username.Text; User.password = Password.Password; NetworkHandler.Initialize(); string response = await User.RegisterAsync(); if (response == null) { await UserData.SaveUser(); Close(); } else { WarningText.Text = response; WarningText.Visibility = Visibility.Visible; } } else if (Password.Password != PasswordConfirm.Password) { WarningText.Text = "Passwords do not match!"; WarningText.Visibility = Visibility.Visible; } else if (Username.Text.Length <= 4) { WarningText.Text = "Username is too short!"; WarningText.Visibility = Visibility.Visible; } else { WarningText.Text = "Password is too short!"; WarningText.Visibility = Visibility.Visible; } }