public ActionConfirmation ValidateUser(UserDto userToValidate) { Person user; try { _securityProvider.Authenticate(userToValidate.UserName, userToValidate.Password); if (!_securityProvider.IsAuthenticated) { return ActionConfirmation.CreateFailureConfirmation("Invalid network user name or password"); } user = _personRepository.GetByUserName(userToValidate.UserName); if (user == null) { return ActionConfirmation.CreateFailureConfirmation("User not found"); } return ActionConfirmation.CreateSuccessConfirmation(""); } catch (InvalidPasswordException) { return ActionConfirmation.CreateFailureConfirmation("Invalid network user name or password"); } catch (NetworkUserNotFoundException) { return ActionConfirmation.CreateFailureConfirmation("Invalid Network User Name or Password"); } catch (Exception ex) { throw new Exception("Encountered an error while attempting to validate username and password", ex); } }
public ActionResult Login(UserDto user, string rememberMe, string returnUrl) { ActionConfirmation actionConfirmation = _membershipProviderManagementService.ValidateUser(user); if (actionConfirmation.WasSuccessful) { _authenticationProvider.SignIn(user.UserName, (rememberMe != null)); if (!string.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); } TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = actionConfirmation.Message; return View("Login"); }