public static void SetToken() { if (!_client.DefaultRequestHeaders.Contains("Authorization")) { _client.DefaultRequestHeaders.Add("Authorization", AuthenticationUser.GetInstance().Token); } }
private static Table ParseTable(string json) { dynamic parsedTable = JsonConvert.DeserializeObject(json); int id = parsedTable["data"]["table"]["id"]; Table table = AuthenticationUser.GetInstance().Tables.Find(x => x.Id == id); var fields = parsedTable["data"]["table"]["fieldNames"]; foreach (var f in fields) { Field field = new Field(); field.Id = f["id"]; field.Type = f["type"]; field.Name = f["name"]; var items = f["fieldValues"]; foreach (var i in items) { Item item = new Item(); item.Id = i["id"]; item.Value = i["value"]; item.FieldNameId = i["fieldNameId"]; field.Items.Add(item); } table.Fields.Add(field); } return(table); }
public static async Task <bool> LoginPostRequest() { LoginUser loginUser = new LoginUser(AuthenticationUser.GetInstance()); // TODO: extract this logic string json = JsonSerializer.Serialize(loginUser); var data = new StringContent(json, Encoding.UTF8, Instance.MediaType); var response = await Client.GetInstance().PostAsync(Instance.Login, data); if (!response.IsSuccessStatusCode) { return(false); } var res = response.Content.ReadAsStringAsync(); if (!res.IsCompleted) { throw new Exception("Login Result exception"); } Debug.WriteLine(res.Result); ProcessToken.ParseToken(res.Result); // TODO: handle request return(true); }
public TablesModel(Action goToAuth) { _goToAuth = goToAuth; Logout = new DelegateCommand(OnLogout); Email = AuthenticationUser.GetInstance().Email; GetAllTables(); }
public static void LoadData() { string dataPath = Variables.EnviromentPath + Variables.DataFileName; if (File.Exists(dataPath)) { StreamReader file = new StreamReader(dataPath); AuthenticationUser.GetInstance().Email = AesOperation.DecryptString(Variables.MacAdress, file.ReadLine()); AuthenticationUser.GetInstance().Password = AesOperation.DecryptString(Variables.MacAdress, file.ReadLine()); file.Close(); } }
private static Task ParseAllTables(string json) { dynamic parsedTables = JsonConvert.DeserializeObject(json); var tables = parsedTables["data"]["tables"]; foreach (var table in tables) { Table t = new Table(); t.Id = table["id"]; t.Name = table["name"]; t.UserId = table["userId"]; AuthenticationUser.GetInstance().Tables.Add(t); } return(Task.CompletedTask); }
private bool LoadUserData() { // TODO: Loading Screen UpdateMacAddress(); ProcessData.LoadData(); AuthenticationUser.GetInstance().UpdateToken(); if (AuthenticationUser.GetInstance().IsDataValid()) { // Creating AuthView to initialize AuthModel _goToApp action AuthView authView = new AuthView(GoToApp, false); AuthModel.SignIn(); return(true); } return(false); }
public static void ParseToken(string json) { JObject obj = JObject.Parse(json); string token = (string)obj.SelectToken("data.authToken"); // Save token to current user AuthenticationUser.GetInstance().Token = token; Client.SetToken(); token = AesOperation.EncryptString(Variables.MacAdress, token); FileStream stream = new FileStream(Variables.EnviromentPath + Variables.JwtFileName, FileMode.Create); stream.Close(); StreamWriter sw = new StreamWriter(Variables.EnviromentPath + Variables.JwtFileName, true, Encoding.UTF8); sw.Write(token); sw.Close(); }