コード例 #1
0
        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"));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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>();
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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");
        }