public async Task <bool> AuthenticateUserAsync(AuthenticateConsumerUserDto dto)
        {
            var user = await _consumerUserRepository.GetConsumerUserByPhoneNumberAsync(dto.PhoneNumber);

            if (user is null)
            {
                return(false);
            }

            return(Crypto.VerifyHashedPassword(user.Password, dto.Password));
        }
Example #2
0
        public async Task <IActionResult> AuthenticateUser([FromBody] AuthenticateConsumerUserDto dto)
        {
            var isAuthenticated = await _consumerUserService.AuthenticateUserAsync(dto);

            if (!isAuthenticated)
            {
                return(new JsonResult(new ErrorDto("Invalid credentials"))
                {
                    StatusCode = StatusCodes.Status401Unauthorized
                });
            }

            var token = _tokenService.GenerateConsumerToken(dto.PhoneNumber);

            return(new JsonResult(new TokenDto(token)));
        }