Пример #1
0
        public async Task <LoginResult> Login(DCLogin login)
        {
            _logger.Information("Trying to login user {User}", login.Username);
            var response = await _clientProvider.Client.PostAsJsonAsync("/eventdirector/rest/mobile/auth", login);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                _logger.Information("Login succeded for user {UserName}", login.Username);
                var result = new LoginResult()
                {
                    Login = login,
                };
                return(result);
            }
            else if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.BadRequest)
            {
                _logger.Information("User {UserName} was not authorized", login.Username);
                var result = new LoginResult()
                {
                    ErrorMessage = AppResources.LoginInvalid
                };
                return(result);
            }
            else
            {
                _logger.Information("Login failed for user {UserName} - received {StatusCode} status code, {Reason}, {Response}", login.Username, response.StatusCode, response.ReasonPhrase, response.Content);
                var result = new LoginResult()
                {
                    ErrorMessage = AppResources.LoginFailed + response.ReasonPhrase
                };
                return(result);
            }
        }
Пример #2
0
 public Task <LoginResult> Login(DCLogin login)
 {
     return(RetryIfFails((service) => service.Login(login)));
 }