예제 #1
0
        private void SwitchToTheMainApplication(IClosableScreen thisLoginScreen, Person connectedUser)
        {
            ApplicationMainWindow appMainWindow = new ApplicationMainWindow();
            ApplicationViewModel  context       = new ApplicationViewModel(connectedUser, _messageBoxService);

            appMainWindow.DataContext = context;
            appMainWindow.Show();

            // Close this Login Window
            thisLoginScreen.CloseScreen();
        }
예제 #2
0
        /// <summary>
        /// Closes the application and returns to the login menu
        /// </summary>
        /// <param name="thisApplicationScreen">ICloseableScreen object to close the application</param>
        private void LogoutUser(IClosableScreen thisApplicationScreen)
        {
            // Launch the login window
            LoginWindow    appLoginWindow = new LoginWindow();
            LoginViewModel context        = new LoginViewModel(_messageBoxService);

            appLoginWindow.DataContext = context;
            appLoginWindow.Show();

            // Close this Window
            thisApplicationScreen.CloseScreen();
        }
예제 #3
0
        /// <summary>
        /// Try to login with the input username and password.
        /// </summary>
        /// <param name="parameter">IHavePassword object that contains the SecureString input password, and that is also IClosableScreen</param>
        private void AttemptLoginCommand(object parameter)
        {
            SecureString password   = (parameter as IHavePassword).SecurePassword;
            var          validInput = CheckLoginInputValidity(Username, password);

            IClosableScreen thisScreen = (parameter as IClosableScreen);

            if (validInput.Valid)
            {
                // Unsecure the password to compare it to the DB - in a proper implementation, the hashed passwords would be compared, but for simplicity
                // we check it unsecured (and the DB holds passwords in plain text for the same reason).
                var unsecuredPassword = password.Unsecure();

                // Search for the user in the DB.
                User connectedAccount = _mySchoolModel.Users.SingleOrDefault(user => user.username == Username && user.password == unsecuredPassword);

                // If the user is found, connect as it and open the application.
                if (connectedAccount != null && !connectedAccount.isDisabled)
                {
                    // Ask the user to change his password before continuing
                    if (connectedAccount.hasToChangePassword)
                    {
                        NewPasswordWindow    newPasswordDialog   = new NewPasswordWindow();
                        NewPasswordViewModel newPasswordDialogVM = new NewPasswordViewModel(_mySchoolModel, connectedAccount);
                        newPasswordDialog.DataContext = newPasswordDialogVM;
                        newPasswordDialog.ShowDialog();
                    }

                    // Launch the application main window with the connected user account
                    SwitchToTheMainApplication(thisScreen, connectedAccount.Person.Single());
                }
                // Report incorrect user credentials error.
                else
                {
                    _messageBoxService.ShowMessage("שם המשתמש ו/או הסיסמא שגויים!", "Login Failed!", MessageType.OK_MESSAGE, MessagePurpose.ERROR);
                }
            }
            // Report invalid credentials error.
            else
            {
                _messageBoxService.ShowMessage(validInput.ErrorReport, "Login Failed!", MessageType.OK_MESSAGE, MessagePurpose.ERROR);
            }
        }