Пример #1
0
 public ActionResult UpdatePicture()
 {
     byte[] imageBytes = (byte[])Session[TWITTER_PREVIEW_IMAGE];
     using (IDocumentSession session = MvcApplication.DocumentStore.OpenSession())
     {
         Models.TwitterAccountModel    model    = GetTwitterAccountModel(session, User.Identity.Name);
         TwitterResponse <TwitterUser> response = TwitterAccount.UpdateProfileImage(GetTwitterUserTokens(model), imageBytes);
     }
     return(Redirect("/home/thankyou"));
 }
Пример #2
0
 private OAuthTokens GetTwitterUserTokens(Models.TwitterAccountModel user)
 {
     return(new OAuthTokens()
     {
         AccessToken = user.TwitterAccessKey,
         AccessTokenSecret = user.TwitterAccessSecret,
         ConsumerKey = ConfigurationManager.AppSettings[CUSTOMER_KEY],
         ConsumerSecret = ConfigurationManager.AppSettings[CUSTOMER_SECRET]
     });
 }
Пример #3
0
        public ActionResult Preview(BadgeType previewType = BadgeType.BasicBlack)
        {
            if (User.Identity.IsAuthenticated)
            {
                using (IDocumentSession session = MvcApplication.DocumentStore.OpenSession())
                {
                    Models.TwitterAccountModel model = GetTwitterAccountModel(session, User.Identity.Name);
                    ViewBag.UserName = model.UserName;

                    TwitterUser twitterUser = TwitterUser.Show(GetTwitterUserTokens(model), decimal.Parse(model.TwitterUserId)).ResponseObject;
                    string      originalProfileImagePath = GetBiggerProfilePictureURL(twitterUser.ProfileImageLocation);

                    ViewBag.OriginalProfileImageLocation = originalProfileImagePath;
                    ViewBag.ImagePreviewType             = previewType;
                }
            }

            return(View());
        }
Пример #4
0
        public ActionResult Callback(string oAuth_Token, string oAuth_Verifier, BadgeType previewType)
        {
            if (string.IsNullOrEmpty(oAuth_Token) || string.IsNullOrEmpty(oAuth_Verifier))
            {
                return(new HttpNotFoundResult("todo"));
            }

            OAuthTokenResponse tokenResponse = OAuthUtility.GetAccessToken(ConfigurationManager.AppSettings[CUSTOMER_KEY], ConfigurationManager.AppSettings[CUSTOMER_SECRET], oAuth_Token, oAuth_Verifier);

            using (IDocumentSession session = MvcApplication.DocumentStore.OpenSession())
            {
                Models.TwitterAccountModel user = GetTwitterAccountModel(session, tokenResponse.UserId.ToString());

                if (user != null)
                {
                    user.BadgeType = previewType;
                    session.SaveChanges();
                }
                else
                {
                    user = new Models.TwitterAccountModel()
                    {
                        TwitterUserId       = tokenResponse.UserId.ToString(),
                        UserName            = tokenResponse.ScreenName,
                        TwitterAccessKey    = tokenResponse.Token,
                        TwitterAccessSecret = tokenResponse.TokenSecret,
                        BadgeType           = previewType
                    };
                    OAuthTokens tokens = GetTwitterUserTokens(user);
                    user.TwitterOriginalProfilePictureURL =
                        GetBiggerProfilePictureURL(TwitterUser.Show(tokenResponse.UserId).ResponseObject.ProfileImageLocation);
                    session.Store(user);

                    session.SaveChanges();
                }

                FormsAuthentication.SetAuthCookie(tokenResponse.UserId.ToString(), false);
            }

            return(Redirect(new Uri(Request.Url, string.Concat("/twitter/preview?previewType=", previewType)).ToString()));
        }
        public ActionResult Callback(string oAuth_Token, string oAuth_Verifier, BadgeType previewType)
        {
            if (string.IsNullOrEmpty(oAuth_Token) || string.IsNullOrEmpty(oAuth_Verifier))
            {
                return new HttpNotFoundResult("todo");
            }

            OAuthTokenResponse tokenResponse = OAuthUtility.GetAccessToken(ConfigurationManager.AppSettings[CUSTOMER_KEY], ConfigurationManager.AppSettings[CUSTOMER_SECRET], oAuth_Token, oAuth_Verifier);

            using (IDocumentSession session = MvcApplication.DocumentStore.OpenSession())
            {
                Models.TwitterAccountModel user = GetTwitterAccountModel(session, tokenResponse.UserId.ToString());

                if (user != null)
                {
                    user.BadgeType = previewType;
                    session.SaveChanges();
                }
                else
                {
                    user = new Models.TwitterAccountModel()
                    {
                        TwitterUserId = tokenResponse.UserId.ToString(),
                        UserName = tokenResponse.ScreenName,
                        TwitterAccessKey = tokenResponse.Token,
                        TwitterAccessSecret = tokenResponse.TokenSecret,
                        BadgeType = previewType
                    };
                    OAuthTokens tokens = GetTwitterUserTokens(user);
                    user.TwitterOriginalProfilePictureURL =
                        GetBiggerProfilePictureURL(TwitterUser.Show(tokenResponse.UserId).ResponseObject.ProfileImageLocation);
                    session.Store(user);

                    session.SaveChanges();
                }

                FormsAuthentication.SetAuthCookie(tokenResponse.UserId.ToString(), false);
            }

            return Redirect(new Uri(Request.Url, string.Concat("/twitter/preview?previewType=", previewType)).ToString());
        }
Пример #6
0
        public FileContentResult PreviewImage(BadgeType previewType)
        {
            Models.TwitterAccountModel user = null;
            using (IDocumentSession session = MvcApplication.DocumentStore.OpenSession())
            {
                user = GetTwitterAccountModel(session, User.Identity.Name);
            }
            if (user == null)
            {
                return(null); // TODO:
            }
            ViewBag.UserName = user.UserName;
            TwitterUser twitterUser = TwitterUser.Show(
                GetTwitterUserTokens(user),
                decimal.Parse(user.TwitterUserId)).ResponseObject;

            string originalProfileImagePath = GetReasonablySmallProfilePictureURL(twitterUser.ProfileImageLocation);

            FileContentResult result = null;

            switch (previewType)
            {
            case BadgeType.BasicBlack:
                result = GetBasicBlackPreviewImageResult(originalProfileImagePath);
                break;

            case BadgeType.BasicRed:
                result = GetBasicRedPreviewImageResult(originalProfileImagePath);
                break;

            case BadgeType.ItsTime:
                result = new FileContentResult(System.IO.File.ReadAllBytes(Server.MapPath("~/Images/restore-full.jpg")), "image/jpg");
                break;
            }

            Session[TWITTER_PREVIEW_IMAGE] = result.FileContents;
            return(result);
        }