public bool LoginUser(ref UserLogin user)
 {
     if (user.IsValid)
     {
         User logged = this.repository.GetUser(user.UserName, user.Password);
         if (logged == null)
         {
             user.AddError("Błędne dane logowania");
             return false;
         }
         user.UserId = logged.UserID;
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
         // Login button event
        private void bLogin_Click(object sender, EventArgs e)
        {
            if (!_anonymous)
            {
                lErrors.Text = "";

                UserLogin login = new UserLogin()
                                      {
                                          UserName = tUsername.Text,
                                          Password = tPassword.Text
                                      };

                // if user is valid and exists in databse
                if (AccountController.Instance.LoginUser(ref login))
                {
                    UserLastActive updateActive = new UserLastActive()
                                                      {
                                                          LastActiveDate = DateTime.Now,
                                                          UserID = login.UserId
                                                      };

                    //set new last login time
                    AccountController.Instance.UpdateLastActiveUser(updateActive);
                    StudiesPlans.Program.user = AccountController.Instance.GetUser(login);
                    this.DialogResult = DialogResult.OK;
                }
                else // if user is not valid show errors
                    foreach (string error in login.Errors)
                        lErrors.Text += error + "\n";
            }
            else
            {
                User u = new User()
                             {
                                 Name = "Anonim",
                                 Role = new Role()
                                            {
                                                Name = "Anonim"
                                            }
                             };
                Privilage p = RoleController.Instance.GetPrivilage("Przegl¹danie");
                u.Role.Privilages.Add(p);
                StudiesPlans.Program.user = u;
                this.DialogResult = DialogResult.OK;
            }
        }
 public User GetUser(UserLogin login)
 {
     return this.repository.GetUser(login.UserName, login.Password);
 }