Esempio n. 1
0
        private void BtnChangePassword_Click(object sender, RoutedEventArgs e)
        {
            var updatePassword = new frmUpdatePassword(_user, _userManager);

            if (updatePassword.ShowDialog() == true)
            {
                _makeUserLogout = true;
            }
        }
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            var email    = txtEmail.Text;
            var password = pwdPassword.Password;

            if (btnLogin.Content.ToString() == "Logout")
            {
                forceUserLogout();
                return;
            }

            if (email.Length < 7 || password.Length < 7)
            {
                MessageBox.Show("Invalid Email or Password", "Invalid Login!",
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
                txtEmail.Text        = "";
                pwdPassword.Password = "";
                txtEmail.Focus();

                return;
            }

            try
            {
                // goes to catch block if not authenticated
                _user = _userManager.AuthenticateUser(email, password);

                // get user's roles and put into a string
                string roles = "";
                for (int i = 0; i < _user.Roles.Count; i++)
                {
                    roles += _user.Roles[i];
                    if (i < _user.Roles.Count - 1)
                    {
                        roles += ", ";
                    }
                }

                lblStatusMessage.Content = "Hello, " + _user.FirstName
                                           + " \nYou are logged in as: " + roles;

                if (pwdPassword.Password.ToString() == "newuser") // first time logging in
                {
                    // force a password reset
                    var resetPassword = new frmUpdatePassword(_user, _userManager);
                    if (resetPassword.ShowDialog() == true)
                    {
                        // password reset successful
                        hideLoginFields();
                        showUserTabsAndButtons();
                    }
                    else
                    {
                        // password reset failed
                        showLoginFields();
                        lblStatusMessage.Content = "Password reset failed! \nPlease login to try again.";
                        return;
                    }
                }
                else // not a first time login
                {
                    hideLoginFields();
                    showUserTabsAndButtons();
                }

                //Shows the Row Definition containing Data
                DataRow.Height  = new GridLength(1, GridUnitType.Star);
                DummyRow.Height = new GridLength(0);

                btnAccountSettings.Visibility = Visibility.Visible;
            }
            catch (Exception ex) // not authenticated
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message,
                                "Login Failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }