public AuthenticationModel Login(LoginModel model) { var user = _userRepository.GetByUsername(model.Username); if(user == null || !PasswordHash.ValidatePassword(model.Password, user.Password)) { throw new ValidationException("", "Username or Password is incorrect"); } return new AuthenticationModel { Admin = user.Admin, Name = user.Username, UserId = user.Id }; }
public ActionResult Login(LoginModel model) { if(ModelState.IsValid) { try { _authenticationService.Login(_userService.Login(model), false); return RedirectToAction("Index", "Dashboard"); } catch (ValidationException e) { ModelState.AddModelError(e.Key, e.Description); } } return View("Login", model); }