示例#1
0
        private void imgBack_Click(object sender, EventArgs e)
        {
            EndTimer(taskObj.id);

            TaskList lst = new TaskList(usrTracker, _token);

            timer1.Enabled = false;
            timer1.Stop();

            lst.Show();
            this.Hide();
        }
示例#2
0
        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();
            }
        }