Ejemplo n.º 1
0
        public static async Task <LoginAttemptStatusResult> CheckLogin(this HttpClient client, IHtmlDocument loginAttemptDocument)
        {
            var loginAttemptId = loginAttemptDocument.GetInputFieldValue(nameof(LoginAttemptViewModel.Id));
            var returnUrl      = loginAttemptDocument.GetInputFieldValue(nameof(LoginAttemptViewModel.ReturnUrl));
            var rememberLogin  = loginAttemptDocument.GetInputFieldValue(nameof(LoginAttemptViewModel.RememberLogin));

            var checkResult = await client.PostAsync("/Account/CheckLoginApproval", new Dictionary <string, string>
            {
                { nameof(LoginAttemptInputModel.Id), loginAttemptId },
                { nameof(LoginAttemptInputModel.ReturnUrl), returnUrl },
                { nameof(LoginAttemptInputModel.RememberLogin), rememberLogin }
            });

            var checkResultContent    = JObject.Parse(await checkResult.Content.ReadAsStringAsync());
            var returnUrlFromResponse = checkResultContent["returnUrl"]?.Value <string>();

            if (checkResultContent["expired"]?.Value <bool>() == true)
            {
                return new LoginAttemptStatusResult
                       {
                           Status = LoginAttemptStatus.ExpiredOrRejected, ReturnUrl = returnUrlFromResponse
                       }
            }
            ;

            if (checkResultContent["approved"]?.Value <bool>() == true)
            {
                return new LoginAttemptStatusResult
                       {
                           Status = LoginAttemptStatus.Accepted, ReturnUrl = returnUrlFromResponse
                       }
            }
            ;

            return(new LoginAttemptStatusResult {
                Status = LoginAttemptStatus.Pending
            });
        }