Пример #1
0
        private void ChangePasswordButton_Click(object sender, RoutedEventArgs e)
        {
            // Show reset password content dialog.
            ContentDialog resetPassDialog = new ResetPasswordContentDialog(false, Data.Instance.LoggedInUser.Id);

            App.ShowContentDialog(resetPassDialog, null);
        }
Пример #2
0
        /// <summary>
        /// Check if everything is filled and check if credentials are correct.
        /// </summary>
        private async Task VerifyLoginData()
        {
            SigningInTextBlock.Visibility  = Visibility.Visible;
            SigningInProgressRing.IsActive = true;

            string username = UsernameTextBox.Text;
            string password = PasswordBox.Password;

            // Check if all values have been filled.
            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                // Verify if user exists in the database.
                User loggedUser = await Data.Instance.GetUserDataFromDBAsync(username, password);

                // Check if any user was found.
                if (loggedUser != null)
                {
                    // Check if user has valid flag enabled.
                    if (loggedUser.Valid)
                    {
                        // Check if user is logging in for the first time or has had it's password reset.
                        if (loggedUser.FirstTimeLogin)
                        {
                            // Show reset password content dialog.
                            ContentDialog resetPassDialog = new ResetPasswordContentDialog(true, loggedUser.Id);

                            // Create callback to be called when ContentDialog closes.
                            Action <ContentDialogResult> callback = async(result) =>
                            {
                                if (result == ContentDialogResult.Primary)
                                {
                                    SigningInTextBlock.Visibility  = Visibility.Collapsed;
                                    SigningInProgressRing.IsActive = false;

                                    LoginUser(loggedUser);
                                }
                                else
                                {
                                    ContentDialog errorMsg = new ContentDialog
                                    {
                                        Title           = "Canceled",
                                        Content         = "You must reset your password to continue.",
                                        CloseButtonText = "OK"
                                    };

                                    App.ShowContentDialog(errorMsg, null);
                                }
                            };

                            App.ShowContentDialog(resetPassDialog, callback);

                            SigningInTextBlock.Visibility  = Visibility.Collapsed;
                            SigningInProgressRing.IsActive = false;
                        }
                        else
                        {
                            SigningInTextBlock.Visibility  = Visibility.Collapsed;
                            SigningInProgressRing.IsActive = false;

                            LoginUser(loggedUser);
                        }
                    }
                    else
                    {
                        ContentDialog errorDialog = new ContentDialog
                        {
                            Title           = "Disabled user",
                            Content         = "User has it's account deactivated.\nPlease contact the administrator to reactivate your account.",
                            CloseButtonText = "Ok"
                        };

                        App.ShowContentDialog(errorDialog, null);

                        SigningInTextBlock.Visibility  = Visibility.Collapsed;
                        SigningInProgressRing.IsActive = false;
                    }
                }
                else
                {
                    ContentDialog errorDialog = new ContentDialog
                    {
                        Title           = "Incorrect credentials",
                        Content         = "Login informations are incorrect.\nIf you have forgotten your login details, please contact your administrator to get new login details.",
                        CloseButtonText = "Ok"
                    };

                    App.ShowContentDialog(errorDialog, null);

                    UsernameTextBox.Text = "";
                    PasswordBox.Password = "";

                    SigningInTextBlock.Visibility  = Visibility.Collapsed;
                    SigningInProgressRing.IsActive = false;
                }
            }
            else
            {
                ContentDialog errorDialog = new ContentDialog
                {
                    Title           = "Error",
                    Content         = "All fields must be filled.",
                    CloseButtonText = "Ok"
                };

                App.ShowContentDialog(errorDialog, null);

                SigningInTextBlock.Visibility  = Visibility.Collapsed;
                SigningInProgressRing.IsActive = false;
            }
        }