Beispiel #1
0
        public async Task <UserWithToken> GetUserByShindenIdAsync(ulong id)
        {
            using (var db = new Database.UserContext(_config))
            {
                var user = await db.GetCachedFullUserByShindenIdAsync(id);

                if (user == null)
                {
                    await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext);
                    return(null);
                }

                TokenData tokenData = null;
                var       currUser  = ControllerContext.HttpContext.User;
                if (currUser.HasClaim(x => x.Type == ClaimTypes.Webpage))
                {
                    tokenData = UserTokenBuilder.BuildUserToken(_config, user);
                }

                return(new UserWithToken()
                {
                    Expire = tokenData?.Expire,
                    Token = tokenData?.Token,
                    User = user,
                });
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <Database.Models.Card> > GetShindenUserWishlistAsync(ulong id)
        {
            using (var db = new Database.UserContext(_config))
            {
                var user = await db.GetCachedFullUserByShindenIdAsync(id);

                if (user == null)
                {
                    await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext);
                    return(null);
                }

                if (user.GameDeck.Wishes.Count < 1)
                {
                    await "Wishlist not found!".ToResponse(404).ExecuteResultAsync(ControllerContext);
                    return(null);
                }

                var p = user.GameDeck.GetCharactersWishList();
                var t = user.GameDeck.GetTitlesWishList();
                var c = user.GameDeck.GetCardsWishList();

                return(await _waifu.GetCardsFromWishlist(c, p, t, db, user.GameDeck.Cards));
            }
        }
Beispiel #3
0
        public async Task <UserWithToken> GiveShindenUserAPacksAsync(ulong id, [FromBody] List <Models.CardBoosterPack> boosterPacks)
        {
            if (boosterPacks?.Count < 1)
            {
                await "Model is Invalid".ToResponse(500).ExecuteResultAsync(ControllerContext);
                return(null);
            }

            var packs = new List <BoosterPack>();

            foreach (var pack in boosterPacks)
            {
                var rPack = pack.ToRealPack();
                if (rPack != null)
                {
                    packs.Add(rPack);
                }
            }

            if (packs.Count < 1)
            {
                await "Data is Invalid".ToResponse(500).ExecuteResultAsync(ControllerContext);
                return(null);
            }

            using (var db = new Database.UserContext(_config))
            {
                var user = await db.GetCachedFullUserByShindenIdAsync(id);

                if (user == null)
                {
                    await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext);
                    return(null);
                }

                var discordId = user.Id;
                var exe       = new Executable($"api-packet u{discordId}", new Task(() =>
                {
                    using (var dbs = new Database.UserContext(_config))
                    {
                        var botUser = dbs.GetUserOrCreateAsync(discordId).Result;

                        foreach (var pack in packs)
                        {
                            botUser.GameDeck.BoosterPacks.Add(pack);
                        }

                        dbs.SaveChanges();

                        QueryCacheManager.ExpireTag(new string[] { $"user-{botUser.Id}", "users" });
                    }
                }));

                await _executor.TryAdd(exe, TimeSpan.FromSeconds(1));

                TokenData tokenData = null;
                var       currUser  = ControllerContext.HttpContext.User;
                if (currUser.HasClaim(x => x.Type == ClaimTypes.Webpage))
                {
                    tokenData = UserTokenBuilder.BuildUserToken(_config, user);
                }

                return(new UserWithToken()
                {
                    Expire = tokenData?.Expire,
                    Token = tokenData?.Token,
                    User = user,
                });
            }
        }