public UserAuthenticateResponseViewModel Authenticate(UserAuthenticateRequestViewModel user)
        {
            User _user = this.userRepository.Find(x => !x.IsDeleted && x.Email.ToLower() == user.Email.ToLower());

            if (_user == null)
            {
                throw new Exception("User not found");
            }
            return(new UserAuthenticateResponseViewModel(mapper.Map <UserViewModel>(_user), TokenService.GenerateToken(_user)));
        }
示例#2
0
        public UserAuthenticateResponseViewModel Authenticate(UserAuthenticateRequestViewModel user)
        {
            if (string.IsNullOrEmpty(user.Email))
            {
                throw new Exception("Email/Password are required.");
            }


            User _user = userRepository.Find(x => x.IsActive && x.Email.ToLower() == user.Email.ToLower());

            if (_user == null)
            {
                throw new Exception("User not found");
            }
            return(new UserAuthenticateResponseViewModel(mapper.Map <UserViewModel>(_user), TokenService.GenerateToken(_user)));
        }
示例#3
0
        public UserAuthenticateResponseViewModel Authenticate(UserAuthenticateRequestViewModel user)
        {
            if (string.IsNullOrEmpty(user.Email) || string.IsNullOrEmpty(user.Password))
            {
                throw new Exception("Email/Password are required.");
            }

            user.Password = EncryptPassoword(user.Password);

            User _user = this.userRepository.Find(x => !x.IsDeleted && x.Email.ToLower() == user.Email.ToLower() &&
                                                  x.Password.ToLower() == user.Password.ToLower());

            if (_user == null)
            {
                throw new Exception("User not found");
            }

            return(new UserAuthenticateResponseViewModel(mapper.Map <UserViewModel>(_user), TokenService.GenerateToken(_user)));
        }
 public IActionResult Authenticate(UserAuthenticateRequestViewModel userViewModel)
 {
     return(Ok(this.userService.Authenticate(userViewModel)));
 }