public ActionResult Login(AuthenticationModel model) { var operationResult = accountService.Authenticate(model); if (operationResult.IsValid) { FormsAuthentication.SetAuthCookie(model.UserName, true); return RedirectToAction("Index", "Character"); } operationResult.ToModelErrors(ModelState); return View(model); }
ValidationResult IAccountService.Authenticate(AuthenticationModel model) { var validaitonErrors = validationService.Validate(model); if (validaitonErrors.Any()) { return new ValidationResult(validaitonErrors); } var account = accountDao.Load(model.UserName); if (account == null) { return new ValidationResult("UserName", validationMessageProvider.Get(ValidationMessageKeys.Authentication_Invalid_Credentials)); } if (!encryptionService.IsValidPassword(model.Password, account.Password)) { return new ValidationResult("UserName", validationMessageProvider.Get(ValidationMessageKeys.Authentication_Invalid_Credentials)); } return ValidationResult.Ok; }
ICollection<ValidationError> IValidationService.Validate(AuthenticationModel model) { return authenticationValidator.Validate(model).Errors.ToValidationResultItem(); }