public IHttpActionResult GetUser([FromUri] CCredentialsDto credentials)
        {
            s_log.LogInfo($"{System.Reflection.MethodBase.GetCurrentMethod()}({credentials}) is called");

            if (credentials == null)
            {
                ModelState.AddModelError($"{nameof(credentials)}", new ArgumentNullException(nameof(credentials), "Incoming data is null"));
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({(CCredentialsDto)null})", new ArgumentNullException(nameof(credentials), "Incoming data is null"));
                return(BadRequest(ModelState));
            }

            var userInfo = _userDataProvider.GetUserByAuthData(credentials.Login, credentials.Password);

            if (userInfo == null)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({credentials})", new HttpResponseException(HttpStatusCode.NotFound));
                return(NotFound());
            }

            var userDto = new CTokenDto(
                userInfo.Id
                );

            return(Ok(userDto));
        }
Beispiel #2
0
        public CTokenDto LogIn(String login, String password)
        {
            Console.WriteLine($@"Supplier method '{nameof(LogIn)}({login})' is called");
            _logger.LogInfo($"Supplier method '{nameof(LogIn)}({login})' is called");

            CCredentialsDto credentials = new CCredentialsDto(
                login,
                password
                );

            Console.WriteLine($@"Credentials = {credentials}");
            _logger.LogInfo($"Credentials = {credentials}");
            return(_service.LogIn(credentials));
        }
Beispiel #3
0
        public Task <CTokenDto> LogInAsync(String login, String password)
        {
            Console.WriteLine($@"Supplier method '{nameof(LogInAsync)}({login})' is called");
            _logger.LogInfo($"Supplier method '{nameof(LogInAsync)}({login}, {password})' is called");

            CCredentialsDto credentials = new CCredentialsDto(
                login,
                password
                );

            Console.WriteLine($@"Credentials = {credentials}");
            _logger.LogInfo($"Credentials = {credentials}");

            return(Task.Run <CTokenDto>(() => _service.LogIn(credentials)));
        }
        public CTokenDto LogIn(CCredentialsDto credentials)
        {
            Console.WriteLine($@"Service method '{nameof(LogIn)}({credentials})' is called");
            _logger.LogInfo($"Service method '{nameof(LogIn)}({credentials})' is called");
            try
            {
                HttpResponseMessage response = _client.GetAsync(
                    $"api/auth/login?login={credentials.Login}&password={credentials.Password}"
                    ).Result;

                return((response.IsSuccessStatusCode)
                    ? response.Content.ReadAsAsync <CTokenDto>().Result
                    : null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                _logger.LogError(@"MessengerService Error", e);
                throw;
            }
        }