private void TaskList_Load(object sender, EventArgs e) { Current = this; ReadTasks((int)usr.uid); }
public async void LoginUser(string userName, string passowrd) { string jsonString = string.Empty; string token = string.Empty; this.Cursor = Cursors.WaitCursor; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var client = new HttpClient(); var values = new Dictionary <string, string> { { "action", "login" }, { "username", userName }, { "password", passowrd }, }; var content = new FormUrlEncodedContent(values); HttpResponseMessage message = await client.PostAsync("https://buynowdepot.com/api.php", content); var responseString = await message.Content.ReadAsStringAsync(); JObject obj = (JObject)JsonConvert.DeserializeObject(responseString); if (obj != null) { if (obj["_token"].ToString() != string.Empty) { token = obj["_token"].ToString(); var jwtHandler = new JwtSecurityTokenHandler(); var readableToken = jwtHandler.CanReadToken(token); if (readableToken == true) { var tk = jwtHandler.ReadJwtToken(token); var headers = tk.Header; var claims = tk.Claims; foreach (Claim c in claims) { if (c.Type == "data") { jsonString = c.Value; } } } } else { lblStatus.Text = "Email or password invalid"; } } else { lblStatus.Text = "Email or password invalid"; } if (jsonString != string.Empty) { User u = JsonConvert.DeserializeObject <User>(jsonString); this.Hide(); TaskList tskList = new TaskList(u, token); tskList.Show(); } }