public async Task Invalid_credentials_should_render_basic_form_with_error()
        {
            // Given
            A.CallTo(() => loginService.AttemptLogin(A <string> ._, A <string> ._)).Returns(
                new LoginResult(LoginAttemptResult.InvalidCredentials)
                );

            // When
            var result = await controller.Index(LoginTestHelper.GetDefaultLoginViewModel());

            // Then
            result.Should().BeViewResult().WithViewName("Index").ModelAs <LoginViewModel>();
            Assert.IsFalse(controller.ModelState.IsValid);
        }
Example #2
0
        public async Task <ActionResult> Login(LoginViewModel vm)
        {
            // Send the email and password.
            if (ModelState.IsValid)
            {
                var result = await loginService.AttemptLogin(vm);

                if (result != null && result.IsValid)
                {
                    // Set token in session
                    HttpContext.Session.SetString("JWToken", result.Token);
                    return(RedirectToAction("Jobs", "Admin"));
                }

                return(BadRequest(result.Errors));
            }
            else
            {
                return(Ok());
            }
        }
Example #3
0
        public async Task <ActionResult> Login([FromBody] LoginVM vm, [FromQuery] bool biometric = false)
        {
            if (ModelState.IsValid)
            {
                var           ip     = HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();
                ServiceResult result = await loginService.AttemptLogin(mapper.Map <LoginSM>(vm), biometric, ip);

                if (result.Valid)
                {
                    // We return the service result values as there is a token present to be passed to the user, to use for all future authentication requests.
                    return(new JsonResult(result.Values));
                }

                return(new JsonResult(new { result.Errors })
                {
                    StatusCode = 400
                });
            }

            return(new StatusCodeResult(400));
        }