Ejemplo n.º 1
0
        //kiểm tra captch
        //Lưu thông tin đăng kí vào CSDL
        public ActionResult Register(UserRegisting user)
        {
            if (!ModelState.IsValid)
            {
                // TODO: Captcha validation failed, show error message
                ViewBag.ErrorMsg = "Incorrect CAPTCHA code!";
            }
            else
            {
                // TODO: Captcha validation passed, proceed with protected action
                var u = new ClientUser
                {
                    f_Username = user.Username,
                    f_Password = Ulti.Md5Hash(user.Password),
                    f_Name     = user.Name,
                    f_Email    = user.Email,
                    f_DOB      = DateTime.ParseExact(user.DOB, "d/m/yyyy", null)
                };

                CSDLQLBH.InsertUser(u);

                Session["Registered"] = 1;
                return(RedirectToAction("Login", "Account"));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Register(UserRegisting user)
        {
            var u = new User
            {
                f_UserName = user.UserName,
                f_Password = Ulti.Md5Hash(user.Password),
                f_Name     = user.Name
            };

            using (var dc = new QLKSEntities())
            {
                dc.Users.Add(u);
                dc.SaveChanges();
            }
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult UpdateProfile(ClientUserInfo ui)
        {
            if (!ModelState.IsValid)
            {
                // TODO: Captcha validation failed, show error message
                ViewBag.ErrorMsg = "Incorrect CAPTCHA code!";
            }
            else
            {
                ClientUser u = ui.FullInfo;
                u.f_Password = Ulti.Md5Hash(ui.Password);

                CSDLQLBH.UpdateUser(u.f_ID, u);

                Session["Updated"] = 1;
                Session["Logged"]  = null;
                Session["cart"]    = null;
                Response.Cookies["UserId"].Expires = DateTime.Now.AddDays(-1);
                return(RedirectToAction("Login", "Account"));
            }
            return(View());
        }
Ejemplo n.º 4
0
        public ApiUserInfo Login(string userName, string password, bool?rememberMe)
        {
            var userInfor    = new ApiUserInfo();
            var passEnscrypt = Ulti.Md5Hash(password);
            var test         = db.Users.ToList();
            var user         = db.Users.Where(u => u.f_Username == userName && u.f_Password == passEnscrypt).FirstOrDefault();

            if (user != null)
            {
                user.f_Password      = "";
                userInfor.Username   = userName;
                userInfor.Permission = Ulti.PermissionMapTo(user.f_Permission);
                userInfor.RemeberMe  = rememberMe;
                userInfor.FullInfo   = this._mapper.Map <User, ApiUser>(user);
            }
            else
            {
                throw new Exception("Tên đăng nhập hoặc mật khẩu không đúng");
            }

            return(userInfor);
        }
Ejemplo n.º 5
0
        public ActionResult Login(ClientUserInfo ui)
        {
            var pass = Ulti.Md5Hash(ui.Password);
            var user = CSDLQLBH.Login(ui);

            if (user != null)
            {
                if (user.Permission == "Customer")
                {
                    Session["Logged"]  = ui;
                    Session["Updated"] = null;
                    Response.Cookies["UserId"].Value   = user.FullInfo.f_ID.ToString();
                    Response.Cookies["UserId"].Expires = DateTime.Now.AddDays(7);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    //them chuc nang admin
                    ui.Permission = user.Permission;
                    //cookie
                    Session["Logged"]  = ui;
                    Session["Updated"] = null;
                    Response.Cookies["UserId"].Value   = user.FullInfo.f_ID.ToString();
                    Response.Cookies["UserId"].Expires = DateTime.Now.AddDays(7);

                    return(RedirectToAction("Index", "ManageProduct"));// trả về trang Index nếu đã nhập đúng thông tin
                }
            }


            else
            {
                ViewBag.ErrorMsg = "Thông tin đăng nhập chưa đúng";
            }

            return(View());
        }