public LoginWindow() { InitializeComponent(); _staffBusiness = new StaffBusiness(); _loginStaffViewModel = new LoginStaffViewModel() { AcceptValidModel = false }; this.DataContext = _loginStaffViewModel; }
public ActionResult CheckLoginStaff(LoginStaffViewModel loginStaff) { var staff = _authProvider.AuthenticateStaff(loginStaff); if (staff != null) { return(RedirectToAction("Main", "Account")); } ModelState.AddModelError("", ""); return(View("ViewLoginStaff", loginStaff)); }
public CurrentStaffViewModel GetStaffViewModel(LoginStaffViewModel loginStaffViewModel) { var passwordHash = EncodeUtilities.GetPasswordHash(loginStaffViewModel.Password); var staff = _staffRepository.Find(filter: s => s.Account == loginStaffViewModel.Account && s.PasswordHash == passwordHash && s.IsActive); //StaffViewModel staffViewModel = Mapper.Map<StaffViewModel>(staff); if (staff == null) { return(null); } var staffViewModel = new CurrentStaffViewModel() { StaffId = staff.StaffId, Account = staff.Account, StaffRole = staff.StaffRole }; return(staffViewModel); }
public Staff AuthenticateStaff(LoginStaffViewModel staff) { if (staff == null) { return(null); } Staff staffInDb = _context.Staffs.FirstOrDefault(u => u.StaffEmployeeId.Equals(staff.StaffEmployeeId) && u.StaffUsername.Equals(staff.StaffUsername) && u.StaffPassword.Equals(staff.StaffPassword)); if (staffInDb == null) { return(null); } FormsAuthentication.SetAuthCookie(staffInDb.StaffUsername, false); return(staffInDb); }
public void Test_CheckLoginStaff_Return_ViewLoginStaff_When_Login_False() { //Arrage var loginStaff = new LoginStaffViewModel() { StaffEmployeeId = "E1234", StaffUsername = "******", StaffPassword = "******" }; var staff = new Staff { StaffId = 1, StaffEmployeeId = "E0001", StaffUsername = "******", StaffPassword = "******", StaffConfirmPassword = "******", StaffFullname = "Thanapon", StaffCitizenId = "15799900617731", StaffGender = "Male", StaffAddress = "264 Chiang Saen Chiang Rai", StaffBirthdate = new DateTime(2010, 3, 11).ToString(CultureInfo.InvariantCulture), StaffEmail = "*****@*****.**", StaffTelephoneNo = "0970747125" }; var authProvider = new Mock <IAuthProvider>(); authProvider.Setup(a => a.AuthenticateStaff(loginStaff)).Returns(staff); var controller = new AccountController(authProvider.Object); controller.ModelState.AddModelError("", ""); // Act var result = controller.CheckLoginStaff(null) as ViewResult; var redirectViewName = result.ViewName; // Assert Assert.AreEqual(redirectViewName, "ViewLoginStaff"); }
private void Login(object sender, RoutedEventArgs e) { _loginStaffViewModel = (LoginStaffViewModel)this.DataContext; if (_loginStaffViewModel.IsValidModel()) { var currentStaff = _staffBusiness.GetStaffViewModel(_loginStaffViewModel); if (currentStaff == null) { MessageBox.Show("Đăng nhập không thành công", "Login", MessageBoxButton.OK, MessageBoxImage.Error); } else { StaffGlobal.CurrentStaff = currentStaff; MessageBox.Show("Đăng nhập thành công", "Login", MessageBoxButton.OK, MessageBoxImage.Information); switch (StaffGlobal.CurrentStaff.StaffRole) { case (int)EStaffRole.Administrator: MainManagementWindow mainManagementWindow = new MainManagementWindow(); this.Hide(); mainManagementWindow.Show(); this.Close(); break; case (int)EStaffRole.SaleStaff: SalesWindow salesWindow = new SalesWindow(); this.Hide(); salesWindow.Show(); this.Close(); break; default: break; } } } else { MessageBox.Show("Dữ liệu không hợp lệ!", "Login", MessageBoxButton.OK, MessageBoxImage.Error); } }