Beispiel #1
0
        public ActionResult LuuThongTinFacebook(KhachHangViewModel model)
        {
            KhachHangViewModel khachHang = (KhachHangViewModel)Session[Constants.Constants.LOGIN_KHACHHANG];

            if (ModelState.IsValid)
            {
                khachHang.TenKH  = model.TenKH;
                khachHang.SoDT   = model.SoDT;
                khachHang.DiaChi = model.DiaChi;
                if (!KhachHangQueries.KiemTraTaiKhoanFacebook(khachHang.MaKH))
                {
                    KhachHangQueries.DangKyBangFacebook(khachHang);
                }
                else
                {
                    KhachHangQueries.SuaThongTinKhachHang(khachHang);
                }
                Session[Constants.Constants.LOGIN_KHACHHANG] = khachHang;
            }
            return(RedirectToAction("GioHang", "GioHang"));
        }
Beispiel #2
0
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["FacebookAppID"],
                client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
                redirect_uri  = RediredtUri.AbsoluteUri,
                code          = code
            });
            var accessToken = result.access_token;

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

            //Xu lí thong tin Facebook
            if (!KhachHangQueries.KiemTraTaiKhoanFacebook(me.id))//thua
            {
                KhachHangViewModel model = new KhachHangViewModel()
                {
                    DiaChi   = me.address,
                    Email    = me.email,
                    GioiTinh = me.gender,
                    MaKH     = me.id,
                    TenKH    = me.first_name + " " + me.last_name
                };
                KhachHangQueries.DangKyBangFacebook(model);//thua
                Session[Constants.Constants.LOGIN_KHACHHANG] = model;
            }
            else
            {
                Session[Constants.Constants.LOGIN_KHACHHANG] = KhachHangQueries.TimKhachHangTheoMa(me.id);
            }
            Session[Constants.Constants.HINH_LOGIN] = me.picture.data.url;
            return(RedirectToAction("Index", "TrangChu"));
        }