public async Task <IActionResult> Index(RegisterViewModel registerViewModel) { if (ModelState.IsValid) { _register.Username = registerViewModel.Username; _register.SteamId = registerViewModel.SteamId; _register.Password = registerViewModel.Password; APIInterface.RegisterUser(_register); var claims = new List <Claim> { new Claim(ClaimTypes.Name, _register.SteamId) }; var userIdentity = new ClaimsIdentity(claims, "login"); ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync(principal); return(RedirectToAction("Index", "Matches")); } return(View(registerViewModel)); }
private void Button_Clicked(object sender, EventArgs e) { if (Symptoms.Count > 0) { var ids = Symptoms.ToArray(); var prediction = APIInterface.Predict(ids.Select(x => x.ID).ToArray()); if (prediction != null) { if (prediction.StateCode == 2) { var dis = prediction.ResultDisease; var det = DataModel.GetDetails(dis.ID); Navigation.PushAsync(new VDiseaseDetials(dis, det)); } else if (prediction.StateCode == 1) { Navigation.PushAsync(new VQuestion(prediction.ResultSymptoms.ToList(), ids.ToList())); } else { DisplayAlert("Error", "Some thing went wrong! .. Retry", "Ok"); } } else { DisplayAlert("Error", "Some thing went wrong! .. Retry", "Ok"); } } else { DisplayAlert("Error", "Please Select Your Main Symptoms!", "Ok"); } }
public void GetBiblePassage() { if (BibleBookSelected == null) { return; } if (ChapterFrom.Length == 0) { return; } if (ChapterTo.Length == 0) { return; } Int32 from = 0; Int32 to = 0; Int32.TryParse(ChapterFrom, out from); Int32.TryParse(ChapterTo, out to); String book = BibleBookSelected.Book; FormattedString result = APIInterface.GetPassage(book, from, 1, to, 20); //PassageUrl = APIInterface.GetPassageURL(book, 1, 1, 1, 16).AbsoluteUri; BiblePassages = result; OnPropertyChanged("BiblePassages"); OnPropertyChanged("PassageUrl"); }
private async Task <JToken> PullAllDecklistData() { List <Card> cards = InterpretCardlist().GroupBy(e => e.CardName).Select(e => e.First()).ToList(); JArray collection = new JArray(); if (cards.Count > 75) { JToken fullData = null; List <HttpResponseMessage> responses = new List <HttpResponseMessage>(); int loopAmount = (int)Math.Ceiling(cards.Count / 75f); for (int i = 0; i < loopAmount; i++) { int remainingAmount = cards.Count - (i * 75) > 75 ? 75 : cards.Count - (i * 75); for (int j = 0; j < remainingAmount; j++) { collection.Add(JToken.Parse("{\"name\":\"" + cards[j + i * 75].CardName + "\"}")); } string bigBody = "{\"identifiers\":" + collection.ToString() + "}"; HttpResponseMessage resp = await APIInterface.Post("/cards/collection", new StringContent(bigBody, Encoding.UTF8, "application/json")); if (fullData == null) { fullData = JToken.Parse(resp.Content.ReadAsStringAsync().Result); } else { responses.Add(resp); } collection.Clear(); Thread.Sleep(100); } foreach (HttpResponseMessage resp in responses) { JToken jt = JToken.Parse(resp.Content.ReadAsStringAsync().Result); foreach (JToken data in jt["data"]) { fullData["data"].Value <JArray>().Add(data); } } return(fullData); } else { foreach (Card ca in cards) { collection.Add(JToken.Parse("{\"name\":\"" + ca.CardName + "\"}")); } string body = "{\"identifiers\":" + collection.ToString() + "}"; HttpResponseMessage singleResp = await APIInterface.Post("/cards/collection", new StringContent(body, Encoding.UTF8, "application/json")); //, "include_multilingual=true" return(JToken.Parse(singleResp.Content.ReadAsStringAsync().Result)); } }
private bool LoginUser(string username, string password) { if (APIInterface.IsValidUser(new User { username = username, password = password })) { return(true); } return(false); }
public async Task <IActionResult> Index(UserLogin userLogin, string returnUrl = "") { if (ModelState.IsValid) { User user = new User() { username = userLogin.username, password = userLogin.password }; JWT jwt = APIInterface.LoginUser(new User { username = user.username, password = user.password }); if (jwt != null) { SteamId steamId = APIInterface.GetSteamId(jwt); // fix the casing on the User properties var claims = new List <Claim> { new Claim(ClaimTypes.Name, steamId.steam_id), new Claim("AccessToken", jwt.access_token), new Claim("RefreshToken", jwt.refresh_token) }; var userIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { // AllowRefresh = true, // Not sure if this is for JWT Refresh Tokens ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7), IsPersistent = userLogin.stayLoggedIn ? true : false, IssuedUtc = DateTime.Now }; ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authProperties); if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(Redirect($"{returnUrl}?routedFromLogin=1")); } else { return(Redirect("http://localhost:5000/Matches?routedFromLogin=1")); } } } return(View(userLogin)); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var registerViewModel = (RegisterViewModel)validationContext.ObjectInstance; APIMessage apiMessage = APIInterface.IsSteamIdInDb(registerViewModel.SteamId).GetAwaiter().GetResult(); if (apiMessage.Message == "User with that steam id already exists.") { return(new ValidationResult("That steam id is currently registered to another user")); } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { UserLogin userLogin = (UserLogin)validationContext.ObjectInstance; APIMessage apiMessage = APIInterface.IsUsernameInDb(userLogin.username).GetAwaiter().GetResult(); if (apiMessage.Message == "That username is currently available.") { return(new ValidationResult("That username is not currently found in the database")); } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { UserLogin userLogin = (UserLogin)validationContext.ObjectInstance; User user = new User() { username = userLogin.username, password = userLogin.password }; if (!APIInterface.IsValidUser(user)) { return(new ValidationResult("Invalid password")); } return(ValidationResult.Success); }
private void Button_Clicked(object sender, EventArgs e) { if (NoAnswers()) { DisplayAlert("Error", "Please select at least one answer!", "Ok"); } else { var sympId = Q1.IsChecked ? sympsQ[0] : Q2.IsChecked ? sympsQ[1] : Q3.IsChecked ? sympsQ[2] : null; if (sympId != null) { symps.Add(sympId); } var prediction = APIInterface.Predict(symps.Select(x => x.ID).ToArray()); if (prediction != null) { if (prediction.StateCode == 2) { var dis = prediction.ResultDisease; var det = DataModel.GetDetails(dis.ID); Navigation.PushAsync(new VDiseaseDetials(dis, det)); } else if (prediction.StateCode == 1) { Navigation.PushAsync(new VQuestion(prediction.ResultSymptoms.ToList(), symps)); } else { DisplayAlert("Error", "Some thing went wrong! .. Retry", "Ok"); } } else { DisplayAlert("Error", "Some thing went wrong! .. Retry", "Ok"); } } }
private async void ParseDecklist() { Dispatcher.Invoke(() => { Info.Owner = this; Info.TextBlock.Text = "Parsing decklist..."; Info.Show(); IsEnabled = false; }); JToken pulledCards = await PullAllDecklistData(); List <Card> allCards = InterpretCardlist(); int progress = 0; foreach (Card currentCard in allCards) { Dispatcher.Invoke(() => Info.TextBlock.Text = "Parsing decklist, Progress: " + ++progress + "/" + allCards.Count); foreach (JToken jt in pulledCards["data"].Children()) { List <string> cardNames = jt["name"].Value <string>().Split(" // ").ToList(); string displayName = cardNames.Count > 1 ? cardNames[0] + " // " + cardNames[1] : cardNames[0]; string regexPattern = @"[^a-zA-Z0-9]"; for (int i = 0; i < cardNames.Count; i++) { cardNames[i] = Regex.Replace(cardNames[i], regexPattern, ""); } string cardname = Regex.Replace(currentCard.CardName, regexPattern, ""); if (cardNames.Contains(cardname, StringComparer.OrdinalIgnoreCase) || jt["name"].Value <string>().Equals(currentCard.CardName, StringComparison.OrdinalIgnoreCase)) { HttpResponseMessage allPrintsResp = await APIInterface.Get("/cards/search", jt["prints_search_uri"].Value <string>().Split('?')[1]); JToken allPrints = JToken.Parse(allPrintsResp.Content.ReadAsStringAsync().Result); List <Edition> editions = new List <Edition>(); foreach (JToken singlePrint in allPrints["data"]) { List <string> specialEffects = new List <string>(); Edition ed = new Edition(); string specialEffectsStr = ""; if (singlePrint["full_art"].Value <bool>()) { specialEffects.Add("Fullart"); } if (singlePrint["textless"].Value <bool>()) { specialEffects.Add("Textless"); } if (singlePrint["frame"].Value <string>() == "future") { specialEffects.Add("Future Sight frame"); } if (singlePrint["border_color"].Value <string>() == "borderless") { specialEffects.Add("Borderless"); } if (singlePrint["frame_effects"] != null) { Dictionary <string, string> frameEffects = new Dictionary <string, string>() { { "extendedart", "Extended art" }, { "showcase", "Showcase" }, { "inverted", "FNM promo" }, { "colorshifted", "Colorshifted" } }; List <string> containedFrameEffects = singlePrint["frame_effects"].Children().Values <string>().ToList(); foreach (string s in containedFrameEffects) { if (frameEffects.ContainsKey(s)) { specialEffects.Add(frameEffects[s]); } } } if (singlePrint["promo_types"] != null) { Dictionary <string, string> promoTypes = new Dictionary <string, string>() { { "prerelease", "Prerelease" }, { "datestamped", "Datestamped" }, { "promostamped", "Promostamped" }, { "judgegift", "Judge promo" }, { "buyabox", "Buy-a-Box promo" }, { "gameday", "Gameday promo" } }; List <string> containedPromoTypes = singlePrint["promo_types"].Children().Values <string>().ToList(); foreach (string s in containedPromoTypes) { if (promoTypes.ContainsKey(s)) { specialEffects.Add(promoTypes[s]); } } } bool differentName = false; if (singlePrint["printed_name"] != null) { differentName = singlePrint["name"].Value <string>() != singlePrint["printed_name"].Value <string>() && singlePrint["lang"].Value <string>() == "en"; } string setName = singlePrint["set_name"].Value <string>(); string setCode = differentName ? singlePrint["printed_name"].Value <string>() : singlePrint["set"].Value <string>().ToUpper(); string imageUri = singlePrint["image_uris"] != null ? singlePrint["image_uris"]["png"].Value <string>() : singlePrint["card_faces"][0]["image_uris"]["png"].Value <string>(); if (specialEffects.Count > 0 && !differentName) { specialEffectsStr = specialEffects.Aggregate("", (s, listStr) => s + listStr + ", ") .TrimEnd(',', ' ').Insert(0, " [") + "]"; } ed.Name = setName; ed.SetCode = setCode; ed.SpecialEffects = specialEffectsStr; ed.ArtworkURL = imageUri; ed.CardNumber = singlePrint["collector_number"].Value <string>(); ed.BorderColor = singlePrint["border_color"].Value <string>(); if (singlePrint["card_faces"] != null) { if (singlePrint["card_faces"].Children().Count() > 0) { if (singlePrint["card_faces"][1]["image_uris"] != null) { ed.BackFaceURL = singlePrint["card_faces"][1]["image_uris"]["png"].Value <string>(); } } } editions.Add(ed); } editions.Reverse(); currentCard.SelectedEditionIndex = 0; currentCard.Editions = editions; currentCard.DisplayName = displayName; break; //stops the loop when the first matching card is found } } } allCards.RemoveAll(e => e.Editions == null || e.Editions.Count == 0); Cards = allCards; Dispatcher.Invoke(() => { CardGrid.ItemsSource = Cards; CardGrid.Items.Refresh(); Info.Hide(); IsEnabled = true; }); string notFoundList = pulledCards["not_found"].Children().Aggregate("", (s, token) => s + "\"" + token["name"] + "\", ").TrimEnd(',', ' '); if (!string.IsNullOrEmpty(notFoundList)) { MessageBox.Show("Cards not found: " + notFoundList, "Cards not found"); } }