Esempio n. 1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            Classes.AllData.Update();
            SocialAPI fbAPI = new SocialAPI();
            string    code  = Request.QueryString["code"];

#if DEBUG
            Session["Submitter"] = Submitter.GetSubmitterFromFBID(Hidden.TestFBID, Hidden.TestFBName);
#endif

            if (Session["Submitter"] == null)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    string[] accessTokenDetails = SocialAPI.GetAccessTokenAndExpirationDays(code, fbAPI);

                    //store access token and expiration in your database for reuse/renew it
                    fbAPI.AccessToken = accessTokenDetails[0];
                    string expiration = accessTokenDetails[1];

                    Submitter clsSubmitter = GetSubmitter(fbAPI);
                    NLog.LogManager.GetCurrentClassLogger().Debug(UExtensionLibrary.Serialization.Serialization.Serialize(clsSubmitter));
                    Session["Submitter"]     = clsSubmitter;
                    btnFBLogin.OnClientClick = "return false;";
                    btnFBLogin.Text          = clsSubmitter.strName;
                }
            }
            else
            {
                IsSubmitter = true;
                btnFBLogin.OnClientClick = "return false;";
                btnFBLogin.Text          = ((Submitter)Session["Submitter"]).strName;
            }
        }
Esempio n. 2
0
        public Submitter GetSubmitter(SocialAPI fbAPI)
        {
            try
            {
                dynamic userProfile = fbAPI.FbClient.Get("me?fields=id,name,birthday,email,education,photos{picture,album},cover");
                try
                {
                    NLog.LogManager.GetCurrentClassLogger().Debug(UExtensionLibrary.Serialization.Serialization.Serialize(userProfile));
                }
                catch
                {
                }

                return(Submitter.GetSubmitterFromFBID(userProfile.id, userProfile.name));
            }
            catch (FacebookApiException ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        protected void Page_Init(object sender, EventArgs e)
        {
            SocialAPI fbAPI    = new SocialAPI();
            var       provider = Request.QueryString["provider"];

            if (provider == "google")
            {
                var result = OAuthWeb.VerifyAuthorization();
                if (!result.IsSuccessfully)
                {
                    throw new UnauthorizedAccessException("Not authorized");
                }

                if (result.ProviderName != "Google")
                {
                    throw new NotSupportedException("Provider not supported");
                }

                fbAPI.AccessToken = result.AccessToken;
                Submitter clsSubmitter = Submitter.GetSubmitterFromFBID("google-" + result.UserId, result.UserInfo.DisplayName);
                Session["Submitter"]     = clsSubmitter;
                IsSubmitter              = true;
                btnFBLogin.OnClientClick = "return false;";
                btnFBLogin.Text          = ((Submitter)Session["Submitter"]).strName;
                btnGoogleLogin.Visible   = false;

                return;
            }


            Classes.AllData.Update();
            string code = Request.QueryString["code"];

//#if DEBUG
//            Session["Submitter"] = Submitter.GetSubmitterFromFBID(Hidden.TestFBID, Hidden.TestFBName);
//#endif

            if (Session["Submitter"] == null)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    string[] accessTokenDetails = SocialAPI.GetAccessTokenAndExpirationDays(code, fbAPI);

                    //store access token and expiration in your database for reuse/renew it
                    fbAPI.AccessToken = accessTokenDetails[0];
                    string expiration = accessTokenDetails[1];

                    Submitter clsSubmitter = GetSubmitter(fbAPI);
                    NLog.LogManager.GetCurrentClassLogger().Debug(UExtensionLibrary.Serialization.Serialization.Serialize(clsSubmitter));
                    Session["Submitter"]     = clsSubmitter;
                    btnFBLogin.OnClientClick = "return false;";
                    btnFBLogin.Text          = clsSubmitter.strName;
                    btnGoogleLogin.Visible   = false;
                }
            }
            else
            {
                IsSubmitter = true;
                btnFBLogin.OnClientClick = "return false;";
                btnFBLogin.Text          = ((Submitter)Session["Submitter"]).strName;
                btnGoogleLogin.Visible   = false;
            }
        }