示例#1
0
        public async Task <UserAuthDto> AuthenticateAsync(string email, string password)
        {
            var user = await GetUserByEmailOrThrowAsync(email);

            var result = _passwordHasher.VerifyHashedPassword(user, user.HashedPassword, password);

            if (result == PasswordVerificationResult.Failed)
            {
                throw new FieldLogicException("Incorrect email or password", nameof(password));
            }

            var userAuthDto = Mapper.Map <UserAuthDto>(user);

            userAuthDto.Token = await _tokenGenerator.CreateAccessTokenAsync(user);

            return(userAuthDto);
        }