Exemplo n.º 1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try {
                if (userToken != null)
                {
                    UsersClient            client      = new UsersClient(userToken.access_token);
                    ApiResponse <FeedItem> recentMedia = client.RecentMedia(null, null, null);

                    ViewData["UserData"] = client.User(null).data;

                    if (recentMedia != null)
                    {
                        ViewData["RecentMedia"] = recentMedia.data.Take(6).ToList();
                        ViewData["Following"]   = client.Follows(null).data.Take(12).ToList();
                        ViewData["FollowedBy"]  = client.FollowedBy(null).data.Take(12).ToList();
                    }
                }
                else
                {
                    MediaClient mediaClient = new MediaClient("");
                    ViewData["Popular"]       = mediaClient.Popular(EnvironmentHelpers.GetConfigValue("ClientId")).data;
                    ViewData["Authenticated"] = "false";
                }
            } catch { }

            base.OnActionExecuting(filterContext);
        }
Exemplo n.º 2
0
        public ActionResult Popular()
        {
            try {
                MediaClient            mediaClient = new MediaClient(base.userToken.access_token);
                ApiResponse <FeedItem> popular     = mediaClient.Popular(EnvironmentHelpers.GetConfigValue("ClientId"));

                ViewData["Photos"] = popular.data;
            } catch { }

            return(View());
        }
Exemplo n.º 3
0
        public ActionResult AccessRequest()
        {
            string code = TryParse(Request.QueryString["CODE"].ToString());
            AuthenticationClient client     = new AuthenticationClient();
            OAuthToken           oauthToken = null;

            try {
                oauthToken = client.Request(code, Server.UrlEncode(EnvironmentHelpers.GetConfigValue("CallBackUrl")), EnvironmentHelpers.GetConfigValue("ClientId"), EnvironmentHelpers.GetConfigValue("ClientSecret"));
            } catch (Exception ex) {  }

            if (oauthToken != null)
            {
                // set a cookie with the users access token?
                HttpCookie userCookie = new HttpCookie(COOKIE_ID);
                Response.Cookies.Remove(COOKIE_ID);
                Response.Cookies.Add(userCookie);
                userCookie.Values.Add("token", oauthToken.access_token);
                Response.Cookies[COOKIE_ID].Expires = DateTime.Now.AddYears(1);

                return(RedirectToAction("Index", "Home"));
            }

            return(View(oauthToken));
        }