Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Request.QueryString["code"]))
        {
            fb = new FacebookCode(siteDefaults.FbClientId, siteDefaults.FbClientSecret, fbUrl);
            using (MySqlConnection conn = new MySqlConnection(siteDefaults.ConnStr))
            {
                if (fb != null && fb.fbUser != null)
                {
                    conn.Open();
                    int loginID = LoginUser.InsertNewFaceBookUser(fb, conn);
                    conn.Close();

                    //Response.Redirect("http://comstar.co/?aa=" + loginID);
                    if (loginID == 0)
                    {
                        Response.Redirect("joinus.aspx");
                    }

                    if (loginID == -1)
                    {
                        Response.Redirect("./");
                    }
                    else
                    {
                        if (Session["SanFransisco"] != null && Session["SanFransisco"] == "true")
                        {
                            string SanFransiscoUrl = "https://panel.i-send.co.il/AddUserFromSite.aspx?eMail=" + fb.fbUser.email + "&1=" + fb.fbUser.first_name + " " + fb.fbUser.last_name + "&4=1&5=0&form=6557__d9fda905-f5aa-49ae-b6a6-e186f1f4613d";

                            HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(SanFransiscoUrl); //setting an httpWebRequest with the URL of the API
                            webRequest.Method      = "GET";                                                            //the type of method the API returns
                            webRequest.Timeout     = 20000;                                                            //sets the timeout for the request
                            webRequest.ContentType = "application/x-www-form-urlencoded";                              //the content type. most of the times it will be application/x-www-form-urlencoded
                            string responseData = "";
                            try
                            {
                                StreamReader MyStream = new StreamReader(webRequest.GetResponse().GetResponseStream()); //creating a stream reader to read the results from the API
                                responseData = MyStream.ReadToEnd();                                                    //reading the result from the API into a string
                            }
                            catch
                            {
                            }
                        }
                        Adduser_WL(5078, fb.fbUser.email, fb.fbUser.first_name + " " + fb.fbUser.last_name);
                        Page.ClientScript.RegisterStartupScript(GetType(), "closePopup", "window.opener.socialLogin('" + fb.fbUser.id + "','" + fb.fbUser.picture + "','" + fb.fbUser.first_name + "'); window.close();", true);
                        Session["login"]             = "******";
                        Session["userId"]            = loginID;
                        Session["Logged"]            = "Yes";
                        Session["LoggedUserMail"]    = fb.fbUser.email;
                        Session["LoggedUserPicture"] = "http://graph.facebook.com/" + fb.fbUser.id + "/picture?type=square";
                    }
                    Session["showStrap"] = true;
                    Response.Redirect("./?firsttime=face");
                }
                else
                {
                    Response.Write("has no fb user");
                }
            }
        }
        else
        {
            Response.Redirect("./");
            //fb = new FacebookCode(siteDefaults.FbClientId, siteDefaults.FbClientSecret);
            //fb.LoginClick(fbUrl, "user_hometown,email,user_location");
        }
    }