bool IEmployeesHelper.CheckLogin(LoginModel model) { var dbEmployee = _employeeRepository.Employees .Where(x => x.Email.Equals(model.Login)) .FirstOrDefault(); if (dbEmployee != null) { var decryptedPassword = PasswordHelper.Decrypt(dbEmployee.Password); if (String.Equals(decryptedPassword, model.Password)) return true; } return false; }
employees IEmployeesHelper.GetEmployeeModel(LoginModel model) { var dbEmployee = _employeeRepository.Employees .Where(x => x.Email.Equals(model.Login)) .FirstOrDefault(); return dbEmployee; }
public ActionResult Login(LoginModel loginModel) { if (_employeesHelper.CheckLogin(loginModel)) { FormsAuthentication.SetAuthCookie(loginModel.Login, false); var model = _employeesHelper.GetEmployeeModel(loginModel); this.Session["Employee"] = model; return RedirectToAction("Index"); } else { ModelState.AddModelError("", "Nieprawidłowa nazwa użytkownika lub hasło!"); return View(); } }