Example #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));
            }
        }
Example #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));
            }
        }
Example #3
0
        public IEnumerable <ValidationResult> Validate(ChangePasswordCommand command)
        {
            User user    = userRepository.GetById(command.UserId);
            var  encoded = Md5Encrypt.Md5EncryptPassword(command.OldPassword);

            if (!user.PasswordHash.Equals(encoded))
            {
                yield return(new ValidationResult("OldPassword", Resources.Password));
            }
        }
        public ActionResult SaveEdit(Account298 model)
        {
            Account298 ac = _account298Repository.GetById(model.id_);

            ac.id_        = model.id_;
            ac.Email      = model.Email;
            ac.Fullname   = model.Fullname;
            ac.Password   = Md5Encrypt.Md5EncryptPassword(model.Password);
            ac.Permission = model.Permission;
            ac.Show       = model.Show;
            ac.Username   = model.Username;
            _account298Repository.Update(ac);
            _unitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
        public ActionResult SaveEdit(User form)
        {
            User dlcu = _userRepository.GetById(form.UserId);

            dlcu.UserId      = form.UserId;
            dlcu.Email       = form.Email;
            dlcu.HoTen       = form.HoTen;
            dlcu.TenDangNhap = form.TenDangNhap;
            dlcu.MatKhau     = Md5Encrypt.Md5EncryptPassword(form.MatKhau);
            dlcu.NgayTao     = form.NgayTao;
            dlcu.TrangThai   = form.TrangThai;
            _userRepository.Update(dlcu);
            _unitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
        public ActionResult AddNew(User postlen)
        {
            User user = new User()
            {
                UserId      = postlen.UserId,
                Email       = postlen.Email,
                HoTen       = postlen.HoTen,
                TenDangNhap = postlen.TenDangNhap,
                MatKhau     = Md5Encrypt.Md5EncryptPassword(postlen.MatKhau),
                NgayTao     = postlen.NgayTao,
                TrangThai   = postlen.TrangThai,
            };

            _userRepository.Add(user);
            _unitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
 public ActionResult AddNew(ThemAccountModel model)
 {
     if (ModelState.IsValid)
     {
         Account298 ac = new Account298()
         {
             Email      = model.Email,
             Username   = model.Username,
             Fullname   = model.Fullname,
             Show       = model.Show,
             Permission = model.Permission,
             Password   = Md5Encrypt.Md5EncryptPassword(model.Password),
         };
         _account298Repository.Add(ac);
         _unitOfWork.Commit();
     }
     else
     {
         return(View("Create", model));
     }
     return(RedirectToAction("Index"));
 }
Example #8
0
        private bool ValidatePassword(User user, string password)
        {
            var encoded = Md5Encrypt.Md5EncryptPassword(password);

            return(user.PasswordHash.Equals(encoded));
        }
Example #9
0
        public async Task <ActionResult> Register(UserFormModel model)
        {
            if (ModelState.IsValid)
            {
                var command = new UserRegisterCommand
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email,
                    Password  = model.Password,
                    Activated = true,
                    RoleId    = (Int32)UserRoles.User
                };

                IEnumerable <ValidationResult> errors = commandBus.Validate(command);
                ModelState.AddModelErrors(errors);
                if (ModelState.IsValid)
                {
                    var result = commandBus.Submit(command);
                    if (result.Success)
                    {
                        var        user    = this.userRepository.Get(x => x.Email.ToUpper() == command.Email.ToUpper() && Md5Encrypt.Md5EncryptPassword(command.Password) == x.PasswordHash);
                        FNHMVCUser appUser = new FNHMVCUser()
                        {
                            Id       = user.UserId,
                            RoleName = Enum.GetName(typeof(UserRoles), user.RoleId),
                            UserName = user.DisplayName
                        };
                        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                        AuthenticationManager.SignIn(new AuthenticationProperties()
                        {
                            IsPersistent = true
                        }, await appUser.GenerateUserIdentityAsync(userManager));
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "An unknown error occurred.");
                    }
                }
                return(View(model));
            }

            return(View(model));
        }
Example #10
0
        public async Task <ActionResult> Login(LogOnFormModel form, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = this.userRepository.Get(x => x.Email.ToUpper() == form.Email.ToUpper() && Md5Encrypt.Md5EncryptPassword(form.Password) == x.PasswordHash);
                if (user != null)
                {
                    FNHMVCUser appUser = new FNHMVCUser(user);
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                    AuthenticationManager.SignIn(new AuthenticationProperties()
                    {
                        IsPersistent = true, RedirectUri = returnUrl
                    }, await appUser.GenerateUserIdentityAsync(userManager));
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            return(View(form));
        }
Example #11
0
        private bool ValidatePassword(Account298 user, string password)
        {
            var encoded = Md5Encrypt.Md5EncryptPassword(password);

            return(user.Password.Equals(encoded));
        }