Beispiel #1
0
        public ActionResult Submit(DanhNhapModel model)
        {
            AccMember298 khachHang = _accMember298Repository.Get(o => o.Email.Equals(model.Email));

            if (khachHang != null)
            {
                string matKhau = Md5Encrypt.Md5EncryptPassword(model.Password);
                if (khachHang.Password.Equals(matKhau))
                {
                    //dang nhap thanh cong
                    SetCookieLogin(this.Request.RequestContext, model.Email);
                    ViewData["Message"] = "Đăng nhập thành công!";
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewData["Message"] = "Mật Khẩu Sai";
                    return(View("dangnhap", model));
                }
            }
            else
            {
                ViewData["Message"] = "Email không tồn tại";
                return(View("dangnhap", model));
            }
        }
Beispiel #2
0
        public ActionResult Submit(KhachHangModel luuVao)
        {
            if (ModelState.IsValid)
            {
                AccMember298 check = _accMember298Repository.Get(o => o.Email.Equals(luuVao.Email.Trim())); //kt email da ton tai chua
                if (check == null)                                                                          //neu rong thi no them vao csdl binh thuong
                {
                    AccMember298 khachHang = new AccMember298()
                    {
                        Fullname       = "",
                        Username       = "******",
                        Email          = luuVao.Email,
                        Phone          = luuVao.Phone,
                        Password       = Md5Encrypt.Md5EncryptPassword(luuVao.Password),
                        sDate          = DateTime.Now,
                        sDateOk        = DateTime.Now,
                        idUser         = 15,
                        idUserOk       = 15,
                        Sex            = "Nữ",
                        Birdthday      = DateTime.Now,
                        Address        = "",
                        States         = "",
                        Level          = 0,
                        Show           = true,
                        DiaChiGiaoHang = "",
                        TenCongTy      = "",
                        MaSoThue       = "",
                        DiaChiCongTy   = ""
                    };
                    _accMember298Repository.Add(khachHang);
                    _unitOfWork.Commit();
                    //new MailersController().GoiMailDangKy(luuVao).Deliver();
                    SetCookieLogin(this.Request.RequestContext, luuVao.Email); //setcookie de luu vao
                                                                               //lay toan bo thong tin cua user lưu vào cookie để load lên những form nào có thông tin như vậy

                    CookieHelper cookieHelper = new CookieHelper("User_Infor");
                    string       jsonString   = JsonConvert.SerializeObject(new KhachHangModel
                    {
                        Email = khachHang.Email,
                        Phone = khachHang.Phone,
                    });
                    cookieHelper.SetUserInforCookie(jsonString);
                    ViewData["Message"] = "Chúc mừng bạn đã đăng ký thành công!";
                    return(View("dangky", luuVao));
                }
                else//khong rong thi ton tai
                {
                    ViewData["Message"] = "Email này đã tồn tại";
                    return(View("dangky", luuVao));
                }
            }
            else//!modelstale.isvalid
            {
                ViewData["Message"] = "Vui lòng nhập đầy đủ thông tin";
                return(View("dangky", luuVao));
            }
        }
        public ActionResult GetUser()
        {
            string       email     = GetCookieLogin(this.HttpContext);
            AccMember298 khachHang = null;

            if (!string.IsNullOrEmpty(email))
            {
                khachHang = _accMember298Repository.Get(o => o.Email.Equals(email));
                return(View("User", khachHang));
            }
            return(View("User", khachHang));
        }
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["FbAppId"],
                client_secret = ConfigurationManager.AppSettings["FbAppSecret"],
                redirect_uri  = RedirectUri.AbsoluteUri,
                code          = code
            });


            var accessToken = result.access_token;

            if (!string.IsNullOrEmpty(accessToken))
            {
                fb.AccessToken = accessToken;
                dynamic me        = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
                string  email     = me.email;
                string  firstname = me.first_name;
                string  lastname  = me.last_name;

                AccMember298 user = new AccMember298()
                {
                    Email          = email,
                    sDate          = DateTime.Now,
                    Fullname       = firstname + " " + lastname,
                    Username       = firstname + " " + lastname,
                    sDateOk        = DateTime.Now,
                    idUser         = 15,
                    idUserOk       = 15,
                    Password       = "******",
                    Birdthday      = DateTime.Now,
                    Address        = "",
                    States         = "",
                    Level          = 0,
                    Show           = true,
                    DiaChiGiaoHang = "",
                    TenCongTy      = "",
                    MaSoThue       = "",
                    DiaChiCongTy   = "",
                    Sex            = "Nữ",
                    Phone          = "0123456789"
                };
                AccMember298 khachHang = _accMember298Repository.Get(o => o.Email.Equals(user.Email));
                if (khachHang != null)
                {
                    //neu mail co roi chi viec lay len roi xin chao
                    SetCookieLogin(this.Request.RequestContext, user.Email);
                }
                else
                {
                    //neu mail chua co thi luu cai khach hang do vao db
                    SetCookieLogin(this.Request.RequestContext, user.Email);
                    _accMember298Repository.Add(user);
                    _unitOfWork.Commit();
                }
            }
            // Set the auth cookie
            //FormsAuthentication.SetAuthCookie(email, false);
            return(RedirectToAction("Index", "Home"));
        }