Esempio n. 1
0
        public IActionResult check([FromBody] GetID user)
        {
            try
            {
                var tokenHandler = new JwtSecurityTokenHandler();
                var key          = Encoding.ASCII.GetBytes("NGUYENTHUONGHOAIIN0NOml3z9FMfmpgXwovR9fp6ryDIoGRM8EPHAB6iHsc0fb");
                tokenHandler.ValidateToken(user.Token, new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    // set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
                    ClockSkew = TimeSpan.Zero
                }, out SecurityToken validatedToken);

                var jwtToken = (JwtSecurityToken)validatedToken;

                var userId = int.Parse(jwtToken.Claims.First(x => x.Type == "id").Value);
                // attach user to context on successful jwt validation
                var response = _userService.GetById(userId);
                return(Ok(response));
            }
            catch
            {
                // do nothing if jwt validation fails
                // user is not attached to context so request won't have access to secure routes
                return(Ok("lỗi"));
            }

            return(Ok(""));
        }
Esempio n. 2
0
        public async static Task <GetStats> GetStats(GetID idroot, int platformindex)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var urlstats    = Data.GenerateURLStats(idroot.uid, idroot.platforms[platformindex]);
                    var responsenew = await client.GetAsync(urlstats);

                    var jsonstats = await responsenew.Content.ReadAsStringAsync();

                    var statsroot = new GetStats();
                    statsroot = JsonConvert.DeserializeObject <GetStats>(jsonstats);
                    return(statsroot);
                }
            }
            catch (Exception e)
            {
                GetStats error = new GetStats();
                error.uid = "errornointernet";
                return(error);
            }


            //we manually transfer the seasons and platforms because we cannot return two objects.

            //BUUUUT IT IS CRASHING SO WE WILL REVIEW IT AGAIN LATER...


            //statsroot.platforms = idroot.platforms;
            //statsroot.GetID.seasons = idroot.seasons;
        }
Esempio n. 3
0
        public async static Task <GetID> GetID(string username)
        {
            var urlid = Data.GenerateURLID(username);


            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var response = await client.GetAsync(urlid);

                    var json = await response.Content.ReadAsStringAsync();

                    if (json.Contains("\"success\":false"))
                    {
                        //THE METHOD SHOULD STOP HERE IF THERE IS A PROBLEM AND THE USER COULD NOT BE FOUND.
                        GetID error = new GetID();
                        error.uid = "error";
                        return(error);
                    }

                    var idroot = JsonConvert.DeserializeObject <GetID>(json);

                    return(idroot);
                }
            }
            catch (Exception e)
            {
                GetID error = new GetID();
                error.uid = "errornointernet";
                return(error);
            }
        }
Esempio n. 4
0
        public async void searchStats(string usernameText)
        {
            search.IsEnabled            = false;
            activityIndicator.IsRunning = true;
            var id = await GetDataLogic.GetID(usernameText);

            publicid = id;
            activityIndicator.IsRunning = false;

            if (id.uid == "error")
            {
                await DisplayAlert("Error", "Could not find username: "******"OK");

                search.IsEnabled = true;
                return;
            }
            else if (id.uid == "errornointernet")
            {
                await DisplayAlert("Error", "Could not connect to the Internet. Please check your connection and try again.", "OK");

                search.IsEnabled = true;
                return;
            }
            else
            {
                if (id.platforms.Count > 1)
                {
                    platformselect.ItemsSource = publicid.platforms.ToList();
                    //we have to show alert to choose platform and then call get user stats.
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (platformselect.IsFocused)
                        {
                            platformselect.Unfocus();
                        }

                        platformselect.Focus();
                    });
                }
                else
                {
                    //we call it without asking because there is only one platform.
                    var userstats = await GetDataLogic.GetStats(id, 0);

                    await Navigation.PushAsync(new Stats(userstats, favorites));
                }


                var resultsearch = recents.Contains(id.username);
                if (!resultsearch)
                {
                    recents.Add(id.username);
                    DependencyService.Get <IGetLists>().SetRecents(recents);
                }
            }
        }
Esempio n. 5
0
        public IActionResult getPart([FromBody] GetID aaa)
        {
            if (aaa != null)
            {
                var getAll = db.Parts.FromSqlRaw("select * from part where id_category =" + aaa.Id).ToList();

                return(Ok(getAll));
            }
            return(Ok("lỗi"));
        }
Esempio n. 6
0
 /// <summary>
 /// 获取一行数据。
 /// </summary>
 protected virtual MDataRow GetOne()
 {
     using (MAction action = new MAction(CrossObjName))
     {
         string where = string.IsNullOrWhiteSpace(GetID) ? GetWhere() : GetID.ToString();
         if (action.Fill(where))
         {
             return(action.Data);
         }
     }
     return(null);
 }
Esempio n. 7
0
 public IActionResult getQuesionById([FromBody] GetID user)
 {
     if (user != null)
     {
         try
         {
             var qr = db.Questions.FromSqlRaw("SELECT * FROM `question` WHERE `id` = " + user.Id).ToList();
             return(Ok(qr));
         }
         catch (Exception e)
         {
             return(Ok("loi" + e.Message));
         }
     }
     return(Ok("loi"));
 }
Esempio n. 8
0
        public IActionResult delQuesionSById([FromBody] GetID user)
        {
            if (user != null)
            {
                try
                {
                    dbS.Questions.FromSqlRaw("DELETE FROM `learning1`.`question` WHERE `id` = " + user.Id).ToList();
                }
                catch (Exception)
                {
                }

                return(Ok("success"));
            }
            return(Ok("loi"));
        }
Esempio n. 9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (GetID != 0)
            {
                hash ^= GetID.GetHashCode();
            }
            if (GetCount != 0)
            {
                hash ^= GetCount.GetHashCode();
            }
            if (GetOdds != 0)
            {
                hash ^= GetOdds.GetHashCode();
            }
            return(hash);
        }
Esempio n. 10
0
        public IActionResult pushData([FromBody] GetID user)
        {
            if (user != null)
            {
                try
                {
                    var qr = dbS.Questions.FromSqlRaw("SELECT * FROM `question` WHERE `id` = " + user.Id).ToList();
                    db.Questions.Add(new QuestionModel
                    {
                        Id_Lession     = qr[0].Id_Lession,
                        Id_Part        = qr[0].Id_Part,
                        title_question = qr[0].title_question,
                        Question       = qr[0].Question,
                        DapanA         = qr[0].DapanA,
                        DapanB         = qr[0].DapanB,
                        DapanC         = qr[0].DapanC,
                        DapanD         = qr[0].DapanD,
                        Answer         = qr[0].Answer,
                        description    = qr[0].description,
                        Sound          = qr[0].Sound,
                        Image          = qr[0].Image,
                        isActive       = 1
                    });
                    int output = db.SaveChanges();
                    dbS.Questions.FromSqlRaw("DELETE FROM `learning1`.`question` WHERE `id` = " + user.Id).ToList();

                    if (output > 0)
                    {
                        return(Ok(true));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                }
            }
            return(Ok("loi"));
        }
Esempio n. 11
0
        private async void load()
        {
            A = false;
            if (App.Current.Properties.ContainsKey("Schema"))
            {
                var _zx = (App.Current.Properties["Schema"] as string).Split(';');
                for (int x = 0; x < _zx.Length; x++)
                {
                    var _ab = _zx[x].Split(',');
                    if (_ab.Length == 4)
                    {
                        TeacherPage.list.Add(new ListItem
                        {
                            LecDay  = _ab[0],
                            LecTime = _ab[1],
                            Class   = _ab[2],
                            Room    = _ab[3], ItemColor = App.UNCLICKED
                        });
                    }
                }
            }
            await DB.LoadAccounts();

            await DB.LoadLectures();

            await DB.LoadInfos();

            for (int x = 0; x < DB.infos.Count; x++)
            {
                var _ = DB.infos[x];
                if (DB.GetLectureById(_.LecId) == null)
                {
                    await DB.RemoveInfo(_);
                }
            }
            //for(int x = 0; x < DB.accounts.Count; x++)
            //{
            //    var s = DB.accounts[x]; s.isLogged = false; await DB.EditAccount(s);
            //}
            var id = GetID.Get();
            var D  = DB.CheckMobileID(id);

            if (App.Current.Properties.ContainsKey("LoggedIn"))
            {
                var     nm  = App.Current.Properties["LoggedIn"] as string;
                Account acc = DB.getAccountByName(nm);
                if (acc != null && acc.isLogged)
                {
                    if (acc.MobileID != null && acc.MobileID == id)
                    {
                        OpenPage();
                        return;
                    }
                }
            }
            else
            {
                if (D != null && D.isLogged)
                {
                    App.Current.Properties["LoggedIn"] = D.Username;
                    await App.Current.SavePropertiesAsync();

                    //if (!D.isLogged) {
                    //    D.isLogged = true;
                    //    await DB.EditAccount(D);
                    //}
                    OpenPage();
                    return;
                }
            }
            Navigation.PushAsync(new LoginPage());
        }
Esempio n. 12
0
        private void Button_Clicked(object sender, EventArgs e)
        {
            if (clicked || _clicked)
            {
                return;
            }
            clicked = true;
            RunTimer();
            if (timeLeft > 0)
            {
                new Popup(new ErrorMessage(_G()), this).Show();
                return;
            }
            string t1 = username.Text, t2 = password.Text;

            if (t1 == null || t2 == null)
            {
                new Popup(new ErrorMessage("Fyll i alla fälten!"), this).Show();
            }
            else
            {
                Start();
                var id = GetID.Get();
                for (int x = 0; x < DB.accounts.Count; x++)
                {
                    Account acc = DB.accounts[x];
                    if (acc.Username == t1 && acc.Password == t2)
                    {
                        if (!acc.isLogged)
                        {
                            Log(acc, id);
                            return;
                        }
                        if (acc.MobileID == null)
                        {
                            Log(acc, id);
                        }
                        else
                        {
                            if (acc.MobileID == id)
                            {
                                Log(acc, id);
                            }
                            else
                            {
                                new Popup(new ErrorMessage("Du är redan inloggad på en annan mobil!\nKontakta Rektorn"), this).Show();
                                Stop();
                            }
                        }
                        return;
                    }
                }
                fails++;
                if (fails > 2)
                {
                    timeLeft = fails < 7 ? (fails - 2) * 60 : 60 * 5;
                }
                CountDown();
                Stop();
                new Popup(new ErrorMessage("Fel användarnamn eller lösenord!"), this).Show();
            }
        }
Esempio n. 13
0
        public IActionResult getLessions([FromBody] GetID aaa)
        {
            var getAll = db.Lessions.FromSqlRaw("select * from lession where id_category =" + aaa.Id).ToList();

            return(Ok(getAll));
        }