Esempio n. 1
0
        public async Task ThenItShouldReturnTrueWhenCommandReturnsUser()
        {
            // Act
            var actual = await _orchestrator.Login(_model);

            // Assert
            Assert.IsTrue(actual.Data.Success);
        }
Esempio n. 2
0
        public async Task <ActionResult> Login(string id, LoginViewModel model)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id), "Missing id when posting to login");
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "Missing login model when posting to login");
            }

            model.OriginatingAddress = Request.UserHostAddress;
            var result = await _accountOrchestrator.Login(model);

            var response = new OrchestratorResponse <LoginViewModel>();

            if (result == null)
            {
                throw new NullReferenceException("Orchestrator did not return a result");
            }

            if (result.Data.Success)
            {
                if (result.Data.RequiresActivation)
                {
                    return(RedirectToAction("Confirm"));
                }

                var signinMessage = _owinWrapper.GetSignInMessage(id);
                if (signinMessage == null)
                {
                    _logger.Info($"Could not find signin message for id {id}, Redirecting to Employer Portal");
                    return(await RedirectToEmployerPortal());
                }
                return(Redirect(signinMessage.ReturnUrl));
            }

            if (result.Data.AccountIsLocked)
            {
                return(RedirectToAction("Unlock"));
            }

            if (result.Status != HttpStatusCode.OK)
            {
                response.Data = new LoginViewModel
                {
                    ReturnUrl = model.ReturnUrl,
                    ClientId  = model.ClientId
                };
                response.FlashMessage         = result.FlashMessage;
                response.Status               = result.Status;
                response.Data.ErrorDictionary = result.FlashMessage.ErrorMessages;
                response.Status               = HttpStatusCode.OK;


                return(View(response));
            }

            return(View(response));
        }