Ejemplo n.º 1
0
        public async Task <CustomerResponse> AuthencateUser(string Email, string CardId, string uid)
        {
            sw.Start();
            CustomerResponse output = null;

            LoggingClass.LogServiceInfo("Service Call", "AuthencateUser");
            try
            {
                var uri       = new Uri(ServiceURL + "AuthenticateUserBeta/" + CardId + "/email/" + Email + "/DeviceId/" + uid);
                var byteArray = new UTF8Encoding().GetBytes(CardId + ":password");
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                var response = await client.GetAsync(uri).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    string Token = response.RequestMessage.Headers.Authorization.Parameter;
                    CurrentUser.SaveAuthToken(Token);
                    output = JsonConvert.DeserializeObject <CustomerResponse>(response.Content.ReadAsStringAsync().Result);
                    LoggingClass.LogServiceInfo("Service Response", "AuthencateUser");
                }
                else
                {
                    AlertActivity a = new AlertActivity();
                    a.UnAuthourised();
                }
            }
            catch (Exception ex)
            {
                LoggingClass.LogError(ex.ToString(), screenid, ex.StackTrace);
            }
            sw.Stop();
            LoggingClass.LogServiceInfo("Service responce " + sw.Elapsed.TotalSeconds, "AuthencateUser");
            return(output);
        }