public async Task <ActionResult> SignIn(AuthenticatePasswordInputModel model, string action, string leaveBlank)
        {
            if (leaveBlank != null)
            {
                ViewBag.Message = "You appear to be a spambot";
            }
            else if (model.Username != null && (action == "getcode" || (action != "signin" && model.Password == null)))
            {
                ModelState.ClearValidationState("Password");
                var input = new SendCodeInputModel()
                {
                    Username = model.Username,
                    NextUrl  = model.NextUrl
                };
                var response = await _authenticateOrchestrator.SendOneTimeCodeAsync(input);

                ViewBag.Message = response.Message;
            }
            else if (ModelState.IsValid)
            {
                var response = await _authenticateOrchestrator.AuthenticateAsync(model);

                if (response.StatusCode == 301)
                {
                    await _authenticateOrchestrator.SignInUserAsync(HttpContext, model.Username, model.StaySignedIn);

                    return(Redirect(response.RedirectUrl));
                }
                ViewBag.Message = response.Message;
            }
            return(View(model));
        }
        public async Task <ActionResult> SignIn(AuthenticatePasswordInputModel model, string action, string leaveBlank)
        {
            if (leaveBlank != null)
            {
                ViewBag.Message = "You appear to be a spambot";
            }
            else if (model.Username != null && (action == "getcode" || (action == "submit" && model.Password == null)))
            {
                ModelState.ClearValidationState(nameof(model.Password));
                var context = await _interaction.GetAuthorizationContextAsync(model.NextUrl);

                var input = new SendCodeInputModel()
                {
                    ApplicationId = context?.ClientId,
                    Username      = model.Username,
                    NextUrl       = model.NextUrl
                };
                var status = await _authenticateOrchestrator.SendOneTimeCodeAsync(input);

                ViewBag.Message = status.Text;
            }
            else if (ModelState.IsValid)
            {
                var status = await _authenticateOrchestrator.AuthenticateAsync(model);

                if (status.StatusCode == HttpStatusCode.Redirect)
                {
                    return(Redirect(status.RedirectUrl));
                }
                ViewBag.Message = status.Text;
            }
            return(View(model));
        }
 public async Task <IActionResult> SendOneTimeCode([FromBody] SendCodeInputModel model)
 {
     if (ModelState.IsValid)
     {
         return((await _authenticateOrchestrator.SendOneTimeCodeAsync(model)).ToJsonResult());
     }
     return(new ActionResponse(ModelState).ToJsonResult());
 }