Example #1
0
        private void Login()
        {
            // Null check.
            if (User.IsNull())
            {
                Dialog.ShowDefaultErrorMessage("Please select a valid username before trying to log in.");
                return;
            }

            if (Password.IsNullOrEmpty())
            {
                Dialog.ShowDefaultErrorMessage("Please enter a password before trying to log in.");
                return;
            }

            // Hash the password.
            var hashedPassword = Passwords.HashString(Password);

            // Validate the password.
            if (User.PasswordHashed != hashedPassword)
            {
                Dialog.ShowDefaultErrorMessage("You entered an incorrect password.");
                return;
            }

            // Set the current user and current events.
            App.CurrentUser  = User;
            App.CurrentEvent = Event.GetCurrentOrNextEvent();

            // If a password change is required, show the change password form.
            if (User.IsPasswordResetRequired)
            {
                // Force the user to change their password.
                var window = new ChangePasswordWindow(User);

                // Return if the window returns false.
                if (window.ShowDialog() == false)
                {
                    return;
                }
            }

            // Save the user in the app settings.
            Settings.Default.LastUser = User.ToString();
            Settings.Default.Save();

            // Show the main window.
            var mainWindow = new MainWindow();

            mainWindow.Show();

            CloseAction();
        }