示例#1
0
        public ActionResult Login(LoginModel model)
        {
            var   userSession = new UserLogin();
            Regex regex       = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match       = regex.Match(model.TaiKhoan);

            if (match.Success)
            {
                if (ModelState.IsValid)
                {
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var dao    = new TaiKhoanDao();
                    var result = dao.Login(model.TaiKhoan, Encryptor.MD5Hash(model.MatKhau));
                    if (result == 1)
                    {
                        var user = dao.GetById(model.TaiKhoan);
                        userSession.UserId   = user.MaTaiKhoan;
                        userSession.TaiKhoan = user.TaiKhoan;
                        userSession.MaVaiTro = user.MaVaiTro;
                        var listCredentials = dao.GetListCredential(model.TaiKhoan);

                        Session.Add(CommonConstants.SESSION_CREDENTIALS, listCredentials);
                        Session.Add(CommonConstants.USER_SESSION, userSession);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else if (result == -1)
                    {
                        ModelState.AddModelError("", "Tài khoản hiện đang bị khóa");
                    }
                    else if (result == -2)
                    {
                        ModelState.AddModelError("", "Vui lòng nhập lại mật khẩu");
                    }
                    else if (result == 0)
                    {
                        ModelState.AddModelError("", "Tài khoản không tồn tại");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Đăng nhập thất bại, vui lòng liên hệ Admin");
                    }
                }
            }
            return(View("Index"));
        }
示例#2
0
 public TaiKhoanDto Login(string username, string password)
 {
     return(TaiKhoanDao.Login(username, password));
 }