Ejemplo n.º 1
0
        public bool getLoginTokens(string login, string password)
        {
            Models.AppData appdata = App.Database.GetAppDataAsync().Result;

            /*if (appdata != null)
             * {
             *  deviceid = appdata.DeviceID;
             * }*/

            var client = new RestClient("https://www.kresgefor98.com/rest/CFCandidate/");

            client.AddDefaultHeader("Content-type", "application/json");
            var request     = new RestRequest("token", Method.POST);
            var requestbody = new { login = login, password = password };

            request.RequestFormat = DataFormat.Json;

            request.AddJsonBody(requestbody);

            var response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                return(false);
            }

            var newappdata = JsonConvert.DeserializeObject <Models.AppData>(response.Content);

            App.Database.UpdateAppData(newappdata);

            access_token = newappdata.Access_Token;
            expires_in   = newappdata.Expires_In;

            return(true);
        }
Ejemplo n.º 2
0
        private void getTokens()
        {
            Models.AppData appdata = App.Database.GetAppDataAsync().Result;

            string deviceid = "";

            if (appdata != null)
            {
                deviceid = appdata.DeviceID;
            }

            var client = new RestClient("https://www.kresgefor98.com/rest/CFCandidate/");

            client.AddDefaultHeader("Content-type", "application/json");
            var request     = new RestRequest("token", Method.POST);
            var requestbody = new { deviceid = deviceid };

            request.RequestFormat = DataFormat.Json;

            request.AddJsonBody(requestbody);

            var response   = client.Execute(request);
            var newappdata = JsonConvert.DeserializeObject <Models.AppData>(response.Content);

            if (deviceid.Length > 0)
            {
                newappdata.DeviceID = deviceid;
            }

            App.Database.UpdateAppData(newappdata);

            access_token = newappdata.Access_Token;
            expires_in   = newappdata.Expires_In;
        }
Ejemplo n.º 3
0
        public Services()
        {
            if (access_token.Length <= 0)
            {
                Models.AppData appdata = App.Database.GetAppDataAsync().Result;

                if (appdata == null)
                {
                    getTokens();
                }
                else
                {
                    if (appdata.Expires_In <= DateTime.Now)
                    {
                        getTokens();
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void UpdateAppData(Models.AppData appdata)
 {
     database.DropTableAsync<AppData>().Wait();
     database.CreateTableAsync<AppData>().Wait();
     database.InsertOrReplaceAsync(appdata).Wait();
 }