コード例 #1
0
        private void Button_Click_Submit(object sender, RoutedEventArgs e)
        {
            Validator validator = new Validator();

            if (validator.IsEmpty(this.SecretPinTextBox) ||
                !validator.SecretPinIsCorrect(this.SecretPinTextBox) ||
                validator.IsEmpty(this.NewPasswordTextBox) ||
                validator.IsEmpty(this.NewPasswordConfirmTextBox) ||
                !validator.PasswordIsCorrect(this.NewPasswordTextBox) ||
                !validator.ConfirmIsSame(this.NewPasswordConfirmTextBox, this.NewPasswordTextBox))
            {
                Logger.Debug("User information is incorrect. Forgot password Failed");
            }
            else
            {
                Books365.BLL.User u = new Books365.BLL.User();
                bool answer         = u.ChangePassword(this.EmailTextBox.Text, this.SecretPinTextBox, this.NewPasswordTextBox);
                if (!answer)
                {
                    MessageBox.Show("Wrong secret pin or email", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Logger.Debug($"User {u.Email} - enter a wrong secret pin");
                }
                else
                {
                    this.Close();
                    Window1 w1 = new Window1();
                    w1.Show();
                    Logger.Debug($"Secret Pin was successfully changed");
                }
            }
        }
コード例 #2
0
ファイル: TestUser.cs プロジェクト: PE-Pmi-32-2020/Books-365
        public void TestChangePassword()
        {
            TextBox     testFirstNameBox = new TextBox();
            TextBox     testLastNameBox  = new TextBox();
            PasswordBox testPasswordBox  = new PasswordBox();
            TextBox     testEmailBox     = new TextBox();
            TextBox     testSecretPinBox = new TextBox();

            testFirstNameBox.Text    = "name";
            testLastNameBox.Text     = "surname";
            testPasswordBox.Password = "******";
            testEmailBox.Text        = "*****@*****.**";
            testSecretPinBox.Text    = "1234";

            Books365.BLL.User user = new Books365.BLL.User();
            using (Books365.AppContext db = new Books365.AppContext())
            {
                TextBox testNewPasswordBox = new TextBox();
                testNewPasswordBox.Text = "NewPassword";
                user.AddNewUser(testFirstNameBox, testLastNameBox, testPasswordBox, testEmailBox, testSecretPinBox);
                user.ChangePassword(testEmailBox.Text, testSecretPinBox, testNewPasswordBox);
                Assert.Equal(testNewPasswordBox.Text, db.Users.Where(u => u.Email == testEmailBox.Text).FirstOrDefault().Password);
                db.Users.RemoveRange(db.Users.Where(u => u.Email == testEmailBox.Text));
                db.EmailCurrentUser.RemoveRange(db.EmailCurrentUser.Where(u => u.Email == testEmailBox.Text));
                db.SaveChanges();
            }
        }