Ejemplo n.º 1
0
        public async Task <bool> AreCredentialsValidAsync(UserCredentialsModel userCredentialsModel)
        {
            var userCredentialsLogText = $"user credentials with login '{userCredentialsModel.Login}'";

            _logger.Information($"Checking if {userCredentialsLogText} are valid...");

            var vegaConfiguration = _starsConfigurationService.Root.Vega;

            if (string.IsNullOrEmpty(vegaConfiguration.HostName))
            {
                throw new ConfigurationParameterException("Vega host name is null or empty");
            }

            var uri = $"{vegaConfiguration.HostName}:{vegaConfiguration.Port}";

            uri = uri.AddQueryPath(StarsApiConstants.Vega.USER_ACCOUNT_ARE_CREDENTIALS_VALID);

            var requestDto = new UserAreCredentialsValidRequestDto
            {
                Login = userCredentialsModel.Login,
                PasswordHashBase64 = userCredentialsModel.Password.GetSHA256().ToBase64()
            };

            var requestModel = new HttpRequestModel
            {
                Method = HttpMethod.Post,
                Uri    = uri,
                Body   = requestDto
            };

            var response = await _httpService.SendRequestAsync <UserAreCredentialsValidResponseDto>(requestModel);

            if (!response.IsSuccessful)
            {
                throw new InterserviceApiException($"Request to Vega API failed (uri = '{uri}')");
            }

            if (response.Body.AreUserCredentialsValid)
            {
                _logger.Information($"Check has been completed, {userCredentialsLogText} are valid");
            }
            else
            {
                _logger.Information($"Check has been completed, {userCredentialsLogText} are not valid");
            }

            return(response.Body.AreUserCredentialsValid);
        }
Ejemplo n.º 2
0
        public async Task <UserAreCredentialsValidResponseDto> AreCredentialsValidAsync(UserAreCredentialsValidRequestDto dto)
        {
            var areUserCredentialsValid = await _userAccountDataService.AreCredentialsValidAsync(dto.Login, dto.PasswordHashBase64);

            return(new UserAreCredentialsValidResponseDto
            {
                AreUserCredentialsValid = areUserCredentialsValid
            });
        }