Пример #1
0
        public string FacebookAuthenticateUser(long FacebookID)
        {
            DataSet objDS = new DataSet();
            LoginModel objLoginModel = new LoginModel();
            AccountsDAL objAccountsDAL = new AccountsDAL();

            objDS = objAccountsDAL.FacebookUserExit(FacebookID);
            if (objDS.Tables.Count > 0)
            {
                DataTable dataTable = objDS.Tables[0];
                if (dataTable.Rows.Count > 0)
                {
                    List<LoginModel> _LoginList = new List<LoginModel>();
                    foreach (DataRow row in dataTable.Rows)
                    {
                        objLoginModel = new LoginModel
                        {
                            AccountID = Convert.ToInt64(row["AccountID"]),
                            Username = row["UserName"].ToString(),
                            Password = row["password"].ToString(),
                            AccountTitle = row["AccountTitle"].ToString(),
                            ProfileImage = row["ProfileImage"].ToString(),
                        };
                        _LoginList.Add(objLoginModel);
                    }

                    objLoginModel = _LoginList.Single();
                }
                else
                {
                    return "false";
                }
            }
            if (objLoginModel.AccountID > 0)
            {
                //if (RememberME)
                //{
                SetCookie("UserName", objLoginModel.AccountTitle.ToString());
                //}

                SetCookie("ID", objLoginModel.AccountID.ToString());
                SetCookie("AccountTitle", objLoginModel.AccountTitle);
                SetCookie("PImage", objLoginModel.ProfileImage);

                FormsAuthentication.SetAuthCookie(objLoginModel.Username, true);
                FormsAuthentication.RedirectFromLoginPage(objLoginModel.Username, false);
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,
                "user",
                DateTime.Now,
                DateTime.Now.AddMinutes(3),
                true,
                "fabiano!",
                FormsAuthentication.FormsCookiePath);

                // Create encrypted cookie
                string hash = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
                if (ticket.IsPersistent)
                {
                    cookie.Expires = ticket.Expiration;
                }

                // Set and done
                Response.Cookies.Add(cookie); //Necessary, otherwise UserData property gets lost

                return "true";

            }
            if (objLoginModel.AccountID < 1)
            {
                return "false";
            }
            return String.Empty;
        }