コード例 #1
0
ファイル: Logout.aspx.cs プロジェクト: zgying/CRMWeiXin
        protected void Page_Load(object sender, EventArgs e)
        {
            string FBToken = null;

            if (HttpContext.Current.Session["FBToken"] != null)
            {
                FBToken = HttpContext.Current.Session["FBToken"].ToString();
            }

            BLL.Users.Logout();

            if (FBToken != null)
            {
                Facebook oFB = new Facebook();
                Response.Redirect(oFB.LogOutLinkGet(FBToken));
            }
            else
            {
                Response.Redirect("/Default.aspx");
            }
        }
コード例 #2
0
ファイル: Login.aspx.cs プロジェクト: zgying/CRMWeiXin
 protected void btnFBLogin_Click(object sender, EventArgs e)
 {
     Facebook oFB = new Facebook();
     Response.Redirect(oFB.AuthorizationLinkGet());
 }
コード例 #3
0
ファイル: Users.cs プロジェクト: zgying/CRMWeiXin
        public static void GraphUser()
        {
            string url = "";
            Facebook oAuth = new Facebook();

            if (HttpContext.Current.Request["code"] != null)
            {
                //Get the access token and secret.
                oAuth.AccessTokenGet(HttpContext.Current.Request["code"]);

                if (oAuth.Token.Length > 0)
                {

                    HttpContext.Current.Session["FBToken"] = oAuth.Token.ToString();
                    url = "https://graph.facebook.com/me?fields=" + FBQuery() + "&access_token=" + oAuth.Token;
                    var data = oAuth.WebRequest(Facebook.Method.GET, url, String.Empty);
                    JObject o = JObject.Parse(data);

                    string _Email = null;
                    string _FacebookID = null;
                    string _FullName = null;
                    string _FirstName = null;
                    string _MiddleName = null;
                    string _LastName = null;
                    string _Gender = null;
                    string _Local = null;
                    string _Link = null;
                    string _TimeZone = null;
                    string _Birthday = null;
                    string _Picture = null;
                    string _LocationID = null;
                    string _LocationName = null;
                    string _City = null;
                    string _Region = null;

                    if (o.SelectToken("email") != null)
                    {
                        _Email = o.SelectToken("email").ToString();
                    }

                    if (o.SelectToken("id") != null)
                    {
                        _FacebookID = o.SelectToken("id").ToString();
                    }

                    if (o.SelectToken("name") != null)
                    {
                        _FullName = o.SelectToken("name").ToString();
                    }

                    if (o.SelectToken("first_name") != null)
                    {
                        _FirstName = o.SelectToken("first_name").ToString();
                    }

                    if (o.SelectToken("middle_name") != null)
                    {
                        _MiddleName = o.SelectToken("middle_name").ToString();
                    }

                    if (o.SelectToken("last_name") != null)
                    {
                        _LastName = o.SelectToken("last_name").ToString();
                    }

                    if (o.SelectToken("gender") != null)
                    {
                        _Gender = o.SelectToken("gender").ToString();
                    }

                    if (o.SelectToken("locale") != null)
                    {
                        _Local = o.SelectToken("locale").ToString();
                    }

                    if (o.SelectToken("link") != null)
                    {
                        _Link = o.SelectToken("link").ToString();
                    }

                    if (o.SelectToken("timezone") != null)
                    {
                        _TimeZone = o.SelectToken("timezone").ToString();
                    }

                    if (o.SelectToken("birthday") != null)
                    {
                        _Birthday = o.SelectToken("birthday").ToString();
                    }

                    if (o.SelectToken("picture") != null)
                    {
                        _Picture = o.SelectToken("picture").ToString();
                    }

                    if (o.SelectToken("location.id") != null)
                    {
                        _LocationID = o.SelectToken("location.id").ToString();
                    }

                    if (o.SelectToken("location.name") != null)
                    {
                        _LocationName = o.SelectToken("location.name").ToString();
                    }

                    if (_LocationName != null)
                    {
                        string[] s = _LocationName.Split(',');
                        _City = s[0];
                        _Region = s[1];
                    }

                    if (_Email != null)
                    {

                        if (UserExists(_Email) == false)
                        {
                            CreateAccount(_Email, Crypto.GenerateSimplePassword()); //Create the facebook user and asign a simple password
                        }

                        if (UserExists(_Email) == true)
                        {
                            var U = Utils.DbContext.Users.FirstOrDefault(Usr => Usr.Email == _Email);
                            U.FacebookID = _FacebookID;
                            U.FullName = _FullName;
                            U.FirstName = _FirstName;
                            U.MiddleName = _MiddleName;
                            U.LastName = _LastName;
                            U.Gender = _Gender;
                            U.Local = _Local;
                            U.Link = _Link;
                            U.TimeZone = int.Parse(_TimeZone);
                            U.Birthday = DateTime.Parse(_Birthday);
                            U.Picture = _Picture;
                            U.LocationID = _LocationID;
                            U.City = _City;
                            U.Region = _Region;
                            U.IsLockedOut = false;
                            U.IsSuperUser = false;
                            Utils.DbContext.SaveChanges();

                            if ((BLL.Users.Login(_Email, GetPassword(U.UserID)) != false))
                            {
                                HttpContext.Current.Response.Redirect("/Default.aspx");
                            }
                        }
                    }
                }
            }

            string FBError = HttpContext.Current.Request.QueryString["error_reason"];

            if (FBError == "user_denied") //User canceled go back to login
            {
                HttpContext.Current.Response.Redirect("/Account/Login.aspx");
            }
        }