/// <summary> /// Handles requsts accepted by the Run method. Returns a LoginRequestResult as an IRequestresult. /// </summary> /// <param name="credentials">The credentials to match in the database.</param> /// <returns> Returns a LoginRequestResult indicating the result of the request.</returns> internal LoginRequestResult HandleLogInRequest(UserCredentials credentials) { User user = dbLoginHandler.GetUser(credentials); LogInRequestStatus status = default(LogInRequestStatus); if (user != null) { status = LogInRequestStatus.Success; } else { status = LogInRequestStatus.WrongCredentials; } return(new LoginRequestResult(status, user)); }
/// <summary> /// Attempts server login. If success, the window belonging to the user type is opened. /// </summary> /// <param name="sender">The button control.</param> /// <param name="e">Not used.</param> private void LogInButton_Click(object sender, RoutedEventArgs e) { errorMessageLabel.Content = "Logging in..."; UserCredentials credentials = new UserCredentials(usernameTextBox.Text, passwordBox.Password); User user = null; LogInRequestStatus loginResult = LogInRequestStatus.Default; try { loginResult = controller.TryLogin(credentials, out user); } catch (ArgumentException) { // Maybe log locally and transmit to server when possible. } switch (loginResult) { case LogInRequestStatus.Success: if (user == null) { throw new NullReferenceException("The instance reference to the logged in user was null"); } else if (user is TestUserType) { TestWindow newWindowForTestUsers = new TestWindow(user); newWindowForTestUsers.Show(); this.Close(); } // else if user is secretary, chairman etc.: Open the appropriate window. break; case LogInRequestStatus.WrongCredentials: errorMessageLabel.Content = "Username or password incorrect. Please try again."; break; //case LoginAttemptResult.NetworkError: // errorMessageLabel.Content = "Could not contact server du to a network error. Please try again later."; // break; case LogInRequestStatus.Default: // Fall through: default: errorMessageLabel.Content = "An unexpected error occurred. Please try again."; break; } }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="status">The status of the log in attempt.</param> /// <param name="user">[OPTIONAL] The user to log in.</param> public LoginRequestResult(LogInRequestStatus status, User user = null) { this.status = status; this.user = user; }