Beispiel #1
0
        public ActionResult Login2(string returnUrl)
        {
            var email = Session["email"] as string;

            if (string.IsNullOrWhiteSpace(email))
            {
                return(RedirectToAction("Login", new { ReturnUrl = returnUrl }));
            }

            var model = new Login2Form
            {
                Email     = email,
                Challenge = Session["challenge"] as string,
                QrUrl     = Session["qrUrl"] as string,
            };

            var respErr = TempData["responseError"] as string;

            if (respErr != null)
            {
                ModelState.AddModelError("Response", respErr);
            }

            return(View("Login2", model));
        }
Beispiel #2
0
        public ActionResult Login2(Login2Form model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var userIp = Request.UserHostAddress;
                var crc    = Sha256(_consumerSecret + model.Response);

                var client    = new SoapSoapClient();
                var errorCode = client.CheckUserAnswer(_consumerId, model.Email, model.Challenge, model.Response, "", userIp, crc);
                if (errorCode == 0)
                {
                    FormsAuthentication.RedirectFromLoginPage(model.Email, false);
                    return(new EmptyResult());
                }


                var errorMsg = client.GetErrDesc(errorCode, "en");
                TempData["responseError"] = errorMsg;

                var email = model.Email;
                crc = Sha256(_consumerSecret + email);
                var result = client.GetChallenge(_consumerId, email, userIp, crc);
                if (result.ErrorCode == 0)
                {
                    Session["challenge"] = result.Challenge;
                    Session["qrUrl"]     = result.QrUrl;
                    return(RedirectToAction("Login2", new { ReturnUrl = returnUrl }));
                }

                if (result.ErrorCode == 301)
                {
                    TempData["responseError"] = null;
                    return(Redirect(AskPermissionUrl(email, returnUrl)));
                }

                Session["challenge"] = Session["qrUrl"] = null;
                return(RedirectToAction("Login", new { ReturnUrl = returnUrl }));
            }

            if (string.IsNullOrWhiteSpace(model.Email))
            {
                return(RedirectToAction("Login", new { ReturnUrl = returnUrl }));
            }

            return(View("Login2", model));
        }