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));
        }
Exemplo n.º 2
0
        protected override void Execute <T>(Object parameter)
        {
            //TODO Добавить логгер
            if (parameter == null)
            {
                _returnValidationResult(new List <String> {
                    "Null arguments"
                });
                return;
            }

            List <String> values = parameter as List <String>;

            if (values == null)
            {
                _returnValidationResult(new List <String> {
                    "Null arguments"
                });
                return;
            }

            String login    = values[0];
            String password = values[1];

            //TryGetUser
            CTokenDto user       = _authSupplier.LogIn(login, password);
            Boolean   hasGetUser = user != null;

            //validate TryGetUser result
            _returnValidationResult(!hasGetUser ? new List <String>()
            {
                "This login is occupied already"
            } : null);

            if (!hasGetUser)
            {
                return;
            }

            String result = _authSupplier.SignUp(login, password, null);

            if (String.IsNullOrEmpty(result))
            {
                return;
            }

            CViewModelLocator.Instance.ApplicationViewModel.GoToPage(EApplicationPage.Chat);
        }
        protected override async Task ExecuteAsync(Object parameter)
        {
            //TODO Добавить логгер
            if (parameter == null)
            {
                _returnValidationResult(new List <String> {
                    "Null arguments"
                });
                return;
            }

            List <String> values = parameter as List <String>;

            if (values == null)
            {
                _returnValidationResult(new List <String> {
                    "Null arguments"
                });
                return;
            }

            String login    = values[0];
            String password = values[1];

            //TryGetUser
            CTokenDto result = await _authSupplier.LogInAsync(login, password);

            CTokenDto user       = result;
            Boolean   hasGetUser = user != null;

            //validate TryGetUser result
            _returnValidationResult(!hasGetUser ? new List <String> {
                "Login or password is invalid"
            } : null);

            if (!hasGetUser)
            {
                return;
            }

            STokenProvider.OnAuthCompleted(user.Id);

            //await Task.Delay(1_000);

            CViewModelLocator.Instance.ApplicationViewModel.GoToPage(EApplicationPage.Chat);
        }