コード例 #1
0
ファイル: UserController.cs プロジェクト: pdattt/SaleWebsite
        public ActionResult Login(Login user)
        {
            if (ModelState.IsValid)
            {
                var checkExist_email = Shop.Users.Any(x => x.Email == user.Email);

                if (!checkExist_email)
                {
                    ModelState.AddModelError("Email", "Email không tồn tại");
                }
                else
                {
                    var check_pass = (from check in Shop.Users
                                      where (check.Email == user.Email)
                                      select check.Password).Single();

                    if (String.Compare(Encrypt.ConvertToEncrypt(user.Password), check_pass) != 0)
                    {
                        ModelState.AddModelError("Pass", "Password không hợp lệ");
                    }
                    else
                    {
                        //var username = (from name in Shop.Users
                        //                where (name.Email == user.Email)
                        //                select name.Name).Single();

                        Session["User"] = user.Email;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            return(View(user));
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: pdattt/SaleWebsite
        public ActionResult Register(Register user)
        {
            var checkExist_email = Shop.Users.Any(x => x.Email == user.Email);

            if (checkExist_email)
            {
                ModelState.AddModelError("Email", "Email đã tồn tại!!");
            }

            if (ModelState.IsValid)
            {
                var new_User = new User();

                new_User.Name     = user.Name;
                new_User.Password = Encrypt.ConvertToEncrypt(user.Password);
                new_User.Address  = user.Address;
                new_User.Phone    = user.Phone;
                new_User.Email    = user.Email;

                Shop.Users.Add(new_User);
                Shop.SaveChanges();

                return(RedirectToAction("Success"));
            }

            return(View(user));
        }
コード例 #3
0
        public async Task <IHttpActionResult> Register(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (customer.Phone == null || customer.Address == null || customer.Name == null || customer.UserName == null || customer.Password == null)
            {
                return(BadRequest("Please fill in the form"));
            }
            if (db.Customers.Any(k => k.UserName.Equals(customer.UserName)))
            {
                return(BadRequest("This username has been taken"));
            }
            // Check password length
            if (customer.Password.Length < 8)
            {
                return(BadRequest("Minimum password length is 8."));
            }

            if (!customer.Password.Any(c => char.IsLower(c)))
            {
                return(BadRequest("Password must include at least 1 lower character."));
            }

            if (!customer.Password.Any(c => char.IsUpper(c)))
            {
                return(BadRequest("Password must include at least 1 upper character."));
            }

            db.Customers.Add(new Customer()
            {
                Phone    = customer.Phone,
                Address  = customer.Address,
                Name     = customer.Name,
                UserName = customer.UserName,
                Password = Encrypt.ConvertToEncrypt(customer.Password)
            });
            db.SaveChanges();
            return(Ok());
        }