예제 #1
0
        public ActionResult Login(LoginForm model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                Session["email"] = model.Email;

                var email  = model.Email;
                var userIp = Request.UserHostAddress;
                var crc    = Sha256(_consumerSecret + email);

                var client = new SoapSoapClient();
                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)
                {
                    return(Redirect(AskPermissionUrl(email, returnUrl)));
                }


                var errorMsg = client.GetErrDesc(result.ErrorCode, "en");
                ModelState.AddModelError("Email", errorMsg);
            }
            return(View("Login", model));
        }
예제 #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));
        }