Esempio n. 1
0
        public async Task <ResponseEntity> SignInAsync(DangNhapViewModel modelVm)
        {
            try
            {
                // Lấy ra thông tin người dùng từ database dựa vào email
                NguoiDung entity = await _nguoiDungRepository.GetByEmailAsync(modelVm.Email);

                if (entity == null)// Nếu email sai
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, modelVm, MessageConstants.SIGNIN_WRONG));
                }
                // Kiểm tra mật khẩu có khớp không
                if (!BCrypt.Net.BCrypt.Verify(modelVm.MatKhau, entity.MatKhau))
                {
                    // Nếu password không khớp
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, modelVm, MessageConstants.SIGNIN_WRONG));
                }
                // Tạo token
                string token = await GenerateToken(entity);

                if (token == string.Empty)
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, modelVm, MessageConstants.TOKEN_GENERATE_ERROR));
                }

                entity.Token = token;

                NguoiDungViewModel model = _mapper.Map <NguoiDungViewModel>(entity);
                return(new ResponseEntity(StatusCodeConstants.OK, model, MessageConstants.SIGNIN_SUCCESS));
            }
            catch
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, modelVm, MessageConstants.SIGNIN_ERROR));
            }
        }
Esempio n. 2
0
        public static bool KiemTraDangNhap(DangNhapViewModel model)
        {
            QlTourDuLichEntities entity = new QlTourDuLichEntities();
            var result = entity.NGUOIDUNGs.FirstOrDefault(t => (t.TenDangNhap == model.Username && t.MatKhau == model.Password));

            //if (result != null)
            //{
            //    HttpContext.Current.Session[Constants.Constants.LOGIN] = model.Username;

            //    //if (model.GhiNhoDangNhap)
            //    //{
            //    //}

            //    return true;
            //}
            return(result != null);
        }
 public ActionResult DangNhap(DangNhapViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (TaiKhoanQueries.KiemTraDangNhap(model))
         {
             Session[Constants.Constants.LOGIN_QUANTRIVIEN] = model.Username;
             if (Response.Cookies[Constants.Constants.LOGIN_QUANTRIVIEN] != null)
             {
                 Response.Cookies.Remove(Constants.Constants.LOGIN_QUANTRIVIEN);
             }
             Response.Cookies[Constants.Constants.LOGIN_QUANTRIVIEN].Value = model.Username;
             Response.Cookies[Constants.Constants.LOGIN_QUANTRIVIEN][Constants.Constants.DANGNHAPLANCUOI] = DateTime.Now.ToString();
             Response.Cookies[Constants.Constants.LOGIN_QUANTRIVIEN].Expires = DateTime.Now.AddDays(15);
             return(RedirectToAction("Index", "TourDuLich"));
         }
     }
     return(View(model));
 }
 public XemVaSuaTaiKhoanWindow()
 {
     InitializeComponent();
     viewModel = new DangNhapViewModel();
     if (DangNhapViewModel.User != null)
     {
         user = new USER()
         {
             IDUSER   = DangNhapViewModel.User.IDUSER,
             TENUSER  = DangNhapViewModel.User.TENUSER,
             PASSWORD = DangNhapViewModel.User.PASSWORD,
             USERNAME = DangNhapViewModel.User.USERNAME,
             EMAIL    = DangNhapViewModel.User.EMAIL,
             HINHANH  = DangNhapViewModel.User.HINHANH,
             LOAIUSER = DangNhapViewModel.User.LOAIUSER
         };
         this.DataContext   = user;
         matKhauTB.Password = DangNhapViewModel.User.PASSWORD;
     }
 }
Esempio n. 5
0
 public async Task <IActionResult> Post([FromBody] DangNhapViewModel model)
 {
     return(await _nguoiDungService.SignInAsync(model));
 }
        public ActionResult DangNhap()
        {
            DangNhapViewModel model = new DangNhapViewModel();

            return(View(model));
        }
 public DangNhapWindow()
 {
     InitializeComponent();
     viewModel = new DangNhapViewModel();
     md5       = MD5.Create();
 }