public ActionResult LOGIN(LoginModel model) { Authenticate useCase = new Authenticate(new Authenticatecommande(model.Email, model.Password)); var user = useCase.Execute(); if (user == null) { model.IsError = true; model.Message = "Email or password is invalid"; return(View(model)); } if (user.Status == false) { model.IsError = true; model.Message = "this account has be been disabled !"; return(View(model)); } FormsAuthenticationTicket ticket = new FormsAuthenticationTicket ( 1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(30), false, JsonConvert.SerializeObject ( new RegisterModel ( user.Email, user.Password, user.Password, user.Name ) ), FormsAuthentication.FormsCookiePath ); Response.Cookies.Add( new HttpCookie( FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket) ) ); if (!string.IsNullOrEmpty(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } return(RedirectToAction("Index", "Home")); }
public async Task Should_return_response_if_successful( CastleConfiguration configuration, Verdict response) { Task <Verdict> Send() => Task.FromResult(response); var logger = Substitute.For <IInternalLogger>(); var result = await Authenticate.Execute(Send, configuration, logger); result.Should().Be(response); }
public async Task Should_throw_exception_if_failing_over_with_no_strategy( Exception exception, CastleConfiguration configuration) { configuration.FailOverStrategy = ActionType.None; var logger = Substitute.For <IInternalLogger>(); Task <Verdict> Send() => throw exception; Func <Task> act = async() => await Authenticate.Execute(Send, configuration, logger); await act.Should().ThrowAsync <CastleExternalException>(); }
public async Task Should_log_failover_exception_as_warning( Exception exception, CastleConfiguration configuration) { configuration.FailOverStrategy = ActionType.Allow; var logger = Substitute.For <IInternalLogger>(); Task <Verdict> Send() => throw exception; await Authenticate.Execute(Send, configuration, logger); logger.Received().Warn(Arg.Is <Func <string> >(x => x() == "Failover, " + exception)); }
public async Task Should_return_failover_response_if_any_exception( Exception exception, CastleConfiguration configuration) { configuration.FailOverStrategy = ActionType.Allow; var logger = Substitute.For <IInternalLogger>(); Task <Verdict> Send() => throw exception; var result = await Authenticate.Execute(Send, configuration, logger); result.Failover.Should().Be(true); result.FailoverReason.Should().Be("server error"); }
public async Task Should_return_failover_response_if_timeout( string requestUri, CastleConfiguration configuration) { configuration.FailOverStrategy = ActionType.Allow; var logger = Substitute.For <IInternalLogger>(); Task <Verdict> Send() => throw new CastleTimeoutException(requestUri, configuration.Timeout); var result = await Authenticate.Execute(Send, configuration, logger); result.Failover.Should().Be(true); result.FailoverReason.Should().Be("timeout"); }
public async Task Should_return_failover_response_if_do_not_track_is_set( CastleConfiguration configuration, Verdict response) { configuration.DoNotTrack = true; configuration.FailOverStrategy = ActionType.Allow; var logger = Substitute.For <IInternalLogger>(); Task <Verdict> Send() => Task.FromResult(response); var result = await Authenticate.Execute(Send, configuration, logger); result.Failover.Should().Be(true); result.FailoverReason.Should().Be("do not track"); }