Пример #1
0
        public ActionResult LoginTwitterComplete()
        {
            // Denied authorization
            var param = Request.QueryString["denied"];

            if (!string.IsNullOrEmpty(param)) {
                TempData.SetStatusMessage(ViewRes.User.LoginUsingAuthStrings.SignInCancelled);
                return View("Login");
            }

            var response = new TwitterConsumer().ProcessUserAuthorization(Hostname);

            if (response == null) {
                ModelState.AddModelError("Authentication", ViewRes.User.LoginUsingAuthStrings.AuthError);
                return View("Login");
            }

            var user = Service.CheckTwitterAuthentication(response.AccessToken, Hostname);

            if (user == null) {
                int twitterId;
                int.TryParse(response.ExtraData["user_id"], out twitterId);
                var twitterName = response.ExtraData["screen_name"];
                return View(new RegisterOpenAuthModel(response.AccessToken, twitterName, twitterId, twitterName));
            }

            HandleCreate(user);

            return RedirectToAction("Index", "Home");
        }
Пример #2
0
        public ActionResult ConnectTwitterComplete()
        {
            // Denied authorization
            var param = Request.QueryString["denied"];

            if (!string.IsNullOrEmpty(param)) {
                TempData.SetStatusMessage(ViewRes.User.LoginUsingAuthStrings.SignInCancelled);
                return View("MySettings");
            }

            var response = new TwitterConsumer().ProcessUserAuthorization(Hostname);

            if (response == null) {
                ModelState.AddModelError("Authentication", ViewRes.User.LoginUsingAuthStrings.AuthError);
                return View("MySettings");
            }

            int twitterId;
            int.TryParse(response.ExtraData["user_id"], out twitterId);
            var twitterName = response.ExtraData["screen_name"];

            if (Service.ConnectTwitter(response.AccessToken, twitterId, twitterName, WebHelper.GetRealHost(Request))) {
                TempData.SetStatusMessage("Connected successfully");
            } else {
                ModelState.AddModelError("Authentication", ViewRes.User.LoginUsingAuthStrings.AuthError);
            }

            return RedirectToAction("MySettings");
        }
Пример #3
0
        public void LoginTwitter()
        {
            // Make sure session ID is initialized
            // ReSharper disable UnusedVariable
            var sessionId = Session.SessionID;
            // ReSharper restore UnusedVariable

            var twitterSignIn = new TwitterConsumer().TwitterSignIn;

            var uri = new Uri(new Uri(AppConfig.HostAddress), Url.Action("LoginTwitterComplete"));
            var request = twitterSignIn.PrepareRequestUserAuthorization(uri, null, null);
            var response = twitterSignIn.Channel.PrepareResponse(request);

            response.Send();
            Response.End();
        }
Пример #4
0
        public ActionResult LoginTwitter()
        {
            // Make sure session ID is initialized
            // ReSharper disable UnusedVariable
            var sessionId = Session.SessionID;
            // ReSharper restore UnusedVariable

            var twitterSignIn = new TwitterConsumer().TwitterSignIn;

            var uri = new Uri(new Uri(AppConfig.HostAddress), Url.Action("LoginTwitterComplete"));

            UserAuthorizationRequest request;

            try {
                request = twitterSignIn.PrepareRequestUserAuthorization(uri, null, null);
            } catch (ProtocolException x) {

                log.ErrorException("Exception while attempting to send Twitter request", x);
                TempData.SetErrorMessage("There was an error while connecting to Twitter - please try again later.");

                return RedirectToAction("Login");

            }

            var response = twitterSignIn.Channel.PrepareResponse(request);

            response.Send();
            Response.End();

            return new EmptyResult();
        }