public UserDTO GetUserByEmailAndPass(string email, string password)
        {
            var pass = PasswordHashService.Hash(password);
            var res  = PasswordHashService.Check(pass, password);
            var user = _database.Users.GetUserByEmail(email);

            return(_mapper.Map <User, UserDTO>(user));
        }
        public UserDTO CreateUser(CreateUserDTO userDTO)
        {
            var pass = PasswordHashService.Hash(userDTO.Password);

            var user = userDTO.ToUpdateUser();

            user.Role     = "User";
            user.Password = pass;

            _database.Users.Add(user);
            _database.Save();

            return(_mapper.Map <User, UserDTO>(user));
            //return userDTO;
        }
        public UserService(IUnitOfWork database)
        {
            _database = database;
            _mapper   = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <User, UserDTO>();
                cfg.CreateMap <Comment, CommentDTO>();
                cfg.CreateMap <Post, PostDTO>();
                cfg.CreateMap <UserDTO, User>();
                cfg.CreateMap <CommentDTO, Comment>();
                cfg.CreateMap <PostDTO, Post>();
            }).CreateMapper();

            var hspass = new PasswordHashService();
        }
Exemple #4
0
        private string GetAccessToken(int tokenId, string username, string password, out int userId)
        {
            var user = _database.Users.GetUserByEmail(username);

            userId = user.Id;

            //var userHashPass = PasswordHashService.Hash(password);

            if (!PasswordHashService.Check(user.Password, password).Verified)
            {
                throw new SecurityException("Invalid email or password");
            }

            var identity = GetIdentity(user.Name, user.Email, user.Role, tokenId, userId);

            return(identity == null ?
                   "Invalid username or password." :
                   GenerateToken(identity));
        }