Exemplo n.º 1
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            ViewBag.siteName  = ConfigurationManager.AppSettings["siteName"].ToString();
            ViewBag.company   = ConfigurationManager.AppSettings["company"].ToString();
            ViewBag.companyEn = ConfigurationManager.AppSettings["companyEn"].ToString();
            ViewBag.address   = ConfigurationManager.AppSettings["address"].ToString();
            ViewBag.addressEn = ConfigurationManager.AppSettings["addressEn"].ToString();

            ViewBag.UIC           = ConfigurationManager.AppSettings["UIC"].ToString();
            ViewBag.email         = ConfigurationManager.AppSettings["email"].ToString();
            ViewBag.tel           = ConfigurationManager.AppSettings["tel"].ToString();
            ViewBag.bankAccount   = ConfigurationManager.AppSettings["bankAccount"].ToString();
            ViewBag.hasBankAcount = ConfigurationManager.AppSettings["hasBankAcount"].ToString() == "true";
            ViewBag.manager       = ConfigurationManager.AppSettings["manager"].ToString();
            ViewBag.managerEn     = ConfigurationManager.AppSettings["managerEn"].ToString();

            //var a = this.Request.Url.ToString();


            base.Initialize(requestContext);

            if (Session != null && Session["user"] != null)
            {
                ViewBag.user = Session["user"];
            }
            else if (User.Identity.IsAuthenticated)
            {
                var user = UserHeppler.GetUserById(User.Identity.Name);
                Session["user"] = user;
                ViewBag.user    = Session["user"];
            }
        }
Exemplo n.º 2
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            if (Session != null && Session["user"] != null)
            {
                ViewBag.user = Session["user"];
            }
            else if (User.Identity.IsAuthenticated)
            {
                var user = UserHeppler.GetUserById(User.Identity.Name);
                Session["user"] = user;
                ViewBag.user    = Session["user"];
            }
        }
Exemplo n.º 3
0
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["appId"],
                client_secret = ConfigurationManager.AppSettings["appSecret"],
                redirect_uri  = RediredtUri.AbsoluteUri,
                code          = code
            });

            var accessToken = result.access_token;

            if (accessToken == null)
            {
                return(Redirect("/"));
            }

            fb.AccessToken = accessToken;
            dynamic me = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range");

            var user = new VMUser
            {
                UserId     = me.id,
                FirstName  = me.first_name,
                LastName   = me.last_name,
                Email      = me.email,
                PictureUrl = me.picture.data.url
            };

            user = UserHeppler.SyncUserToDatabase(user);

            Session["user"] = user;

            FormsAuthenticationTicket authTicket =
                new FormsAuthenticationTicket(1, user.UserId, DateTime.Now, DateTime.Now.AddMinutes(200), true, user.Role, "/");
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                               FormsAuthentication.Encrypt(authTicket));

            Response.Cookies.Add(cookie);
            return(Redirect("/"));
        }