Пример #1
0
 public UserLogHistory Add(UserLogHistory inUser)
 {
     DB.UserLogHistories.Add(inUser);
     DB.SaveChanges();
     return(inUser);
 }
Пример #2
0
        private void VerifyUser(User user)
        {
            MainWindow main = new MainWindow();

            if (user != null)
            {
                if (user.isNewUser == false || user.isNewUser == null)
                {
                    //Data Validation - Empty PasswordBox
                    if (LoginPassword == null)
                    {
                        txtPassword.Clear();
                        txtPassword.WatermarkContent = "Wrong Password. Try Again.";
                    }
                    ;

                    var passwordEntered = GetSaltedPasswordHash(user.userName, LoginPassword);

                    if (passwordEntered.SequenceEqual(TrimZerosOnEnd(user.password)))
                    {
                        globals.CurrentUser = user;
                        UserLogHistory newLog = new UserLogHistory();
                        newLog.loginTime = DateTime.Now;
                        newLog.userID    = globals.CurrentUser.UserID;
                        UserLogRepository.Instance.Service.Add(newLog);

                        main.Show();
                        this.Close();
                    }
                    else
                    {
                        //Data Validation - Incorrect PasswordBox
                        txtPassword.Clear();
                        txtPassword.WatermarkContent = "Wrong Password. Try Again.";
                    }
                }
                else
                {
                    if (ConfirmPassword == SetupPassword)
                    {
                        user.isNewUser = false;
                        user.password  = GetSaltedPasswordHash(user.userName, SetupPassword);
                        UserRespository.Instance.Service.SaveChanges();
                        globals.CurrentUser = user;
                        UserLogHistory newLog = new UserLogHistory();
                        newLog.loginTime = DateTime.Now;
                        newLog.userID    = globals.CurrentUser.UserID;
                        UserLogRepository.Instance.Service.Add(newLog);
                        main.Show();
                        this.Close();
                    }
                    else
                    {
                        //Data Validation - Incorrect Password Setup
                    }
                }
            }
            else
            {
                //Data Validation - Incorrect Email
                txtEmail.Text             = null;
                txtEmail.WatermarkContent = "Wrong Email. Try Again.";
            }
        }