Пример #1
0
        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));
        }
Пример #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)));
        }