コード例 #1
0
        public async Task <User> LoginUser(string userName, string password)
        {
            if (userName == "" || password == "")
            {
                return new User()
                       {
                           Username = userName, UserID = 0, Token = ""
                       }
            }
            ;

            Models.AWS.UserResponse response = await awsHttpClient.LoginUserAsync(new User()
            {
                Username = userName, Password = password
            });

            if (response == null || response?.User == null)
            {
                return new User()
                       {
                           Username = userName, UserID = 0, Token = ""
                       }
            }
            ;

            return(response.User);
        }
コード例 #2
0
        public async Task <User> LoginUser(string userName, string password)
        {
            if (userName == "" || password == "")
            {
                return new Models.AWS.User()
                       {
                           Username = userName, UserID = 0, Token = ""
                       }
            }
            ;

            if (client.DefaultRequestHeaders.Contains("code"))
            {
                client.DefaultRequestHeaders.Remove("code");
            }
            client.DefaultRequestHeaders.Add("code", Constants.AzureApiKey_LoginUser);

            try
            {
                string postBody = JsonConvert.SerializeObject(new User()
                {
                    Username = userName, Password = password
                });

                HttpResponseMessage response = await client.PostAsync(Constants.AzureEndPoint_LoginUser, new StringContent(postBody, Encoding.UTF8, "application/json"));

                //  AnalyticsService.TrackEvent("Response: " + response.StatusCode.ToString());

                if (response.IsSuccessStatusCode)
                {
                    string str = await response.Content.ReadAsStringAsync();

                    //AnalyticsService.TrackEvent(str);
                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling     = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    };
                    Models.AWS.UserResponse userResponse = JsonConvert.DeserializeObject <Models.AWS.UserResponse>(str, settings);
                    if (userResponse == null || userResponse?.User == null)
                    {
                        return new User()
                               {
                                   Username = userName, UserID = 0, Token = ""
                               }
                    }
                    ;

                    return(userResponse.User);
                }
                else
                {
                    string str = await response.Content.ReadAsStringAsync();

                    AnalyticsService.TrackEvent(str);
                }
            }
            catch (HttpRequestException hre)
            {
                AnalyticsService.TrackError(hre);
            }
            catch (TaskCanceledException hca)
            {
                AnalyticsService.TrackError(hca);
                AnalyticsService.TrackEvent("Request canceled");
            }
            catch (Exception ex)
            {
                AnalyticsService.TrackError(ex);
            }
            finally
            {
                /*if (httpClient != null)
                 * {
                 *  httpClient.Dispose();
                 *  httpClient = null;
                 * }*/
            }
            return(new User()
            {
                Username = userName, UserID = 0, Token = ""
            });
        }