예제 #1
0
        //
        // GET: /Account/LogOn

        public ActionResult LogOn(string returnUrl)
        {
            FacebookGraph fbUser;

            if (FacebookAuthorization(out fbUser))
            {
                var user = UsersManager.ConvertFacebookUser(fbUser);
                if (!usersService.Exists(user.userid))
                {
                    usersService.Save(user);
                }
                else
                {
                    user = usersService.GetUserByExternalId(fbUser.Id);
                }

                FormsAuthentication.SetAuthCookie(fbUser.Name, false);
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                                                                                 user.fullname,
                                                                                 DateTime.Now,
                                                                                 DateTime.Now.AddMinutes(30),
                                                                                 true,
                                                                                 user.id.ToString(),
                                                                                 FormsAuthentication.FormsCookiePath);

                string encTicket = FormsAuthentication.Encrypt(ticket);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                    !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                LogOn(returnUrl);
            }

            return(View());
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FacebookGraph fbUser;
                if (StateManager.IsAuthenticated(out fbUser))
                {
                    var user = UsersManager.ConvertFacebookUser(fbUser);
                    if (!new UsersService().Exists(user.id))
                    {
                        new UsersService().Save(user);
                    }

                    GetSite();
                }
                else
                {
                    Response.RedirectWithQueryString("Facebook.aspx");
                }
            }
        }