public AuthenticationResult LogUserIn(Controller controller, ILoginViewModel vm, IUserAreaDefinition userAreaToLogInTo) { Condition.Requires(controller).IsNotNull(); Condition.Requires(userAreaToLogInTo).IsNotNull(); Condition.Requires(vm).IsNotNull(); var result = new AuthenticationResult(); result.ReturnUrl = controller.Request["ReturnUrl"]; if (!controller.ModelState.IsValid) { return(result); } var command = new LogUserInWithCredentialsCommand() { UserAreaCode = userAreaToLogInTo.UserAreaCode, Username = vm.EmailAddress, Password = vm.Password, RememberUser = vm.RememberMe }; _controllerResponseHelper.ExecuteIfValid(controller, command); if (controller.ModelState.IsValid) { result.IsAuthenticated = true; var currentContext = _userContextService.GetCurrentContext(); result.RequiresPasswordChange = currentContext.IsPasswordChangeRequired; } return(result); }
public Task ExecuteAsync(LogMemberInCommand command, IExecutionContext executionContext) { var logUserInCommand = new LogUserInWithCredentialsCommand() { Username = command.Email, Password = command.Password, UserAreaCode = MemberUserArea.MemberUserAreaCode, RememberUser = true }; return(_commandExecutor.ExecuteAsync(logUserInCommand)); }
public async Task <AuthenticationResult> LogUserInAsync(Controller controller, ILoginViewModel vm, IUserAreaDefinition userAreaToLogInTo) { if (controller == null) { throw new ArgumentNullException(nameof(controller)); } if (userAreaToLogInTo == null) { throw new ArgumentNullException(nameof(userAreaToLogInTo)); } if (vm == null) { throw new ArgumentNullException(nameof(vm)); } var result = new AuthenticationResult(); result.ReturnUrl = GetAndValidateReturnUrl(controller); if (!controller.ModelState.IsValid) { return(result); } var command = new LogUserInWithCredentialsCommand() { UserAreaCode = userAreaToLogInTo.UserAreaCode, Username = vm.Username, Password = vm.Password, RememberUser = vm.RememberMe }; try { await _controllerResponseHelper.ExecuteIfValidAsync(controller, command); } catch (PasswordChangeRequiredException ex) { result.RequiresPasswordChange = true; // Add modelstate error as a precaution, because // result.RequiresPasswordChange may not be handled by the caller controller.ModelState.AddModelError(string.Empty, "Password change required."); } result.IsAuthenticated = controller.ModelState.IsValid; return(result); }