public void FindOneSteamIdentity()
        {
            // arrange
            _steamIdentityService.Upsert(SteamIdentity()).GetAwaiter().GetResult();
            // act
            var steamIdentity = _steamIdentityService.FindOne("1").GetAwaiter().GetResult();

            // assert
            steamIdentity.Should().NotBe(null);
            steamIdentity.Name.Should().Be("test");
        }
Example #2
0
        private SteamIdentity InitializeEntryForWhiteList(out PavlovServer[] pavlovServers)
        {
            var user          = ServerSelectedModServiceTests.InsertUserAndSteamIdentity(_steamIdentityService, _userManager);
            var steamIdentity = _steamIdentityService.FindOne(user.Id).GetAwaiter().GetResult();

            pavlovServers = PavlovServerServiceTests.InitializePavlovServer(_sshServerSerivce, _pavlovServerService);
            return(steamIdentity);
        }
        private async Task OverWriteExistingSteamIdOrSaveNewOne(ExternalLoginInfo info, LiteDbUser user)
        {
            var steam = CrawlSteamIdentity(info);
            //Todo get existing one and give it to the player or save it as a new one
            var realSteamIdentity = await _steamIdentityService.FindOne(steam.Id);

            if (realSteamIdentity != null)
            {
                realSteamIdentity.LiteDbUser = user;
                await _steamIdentityService.Upsert(realSteamIdentity);
            }
            else
            {
                steam.LiteDbUser = user;
                await _steamIdentityService.Upsert(steam);
            }
        }
        public async Task <IActionResult> EditSteamIdentity([CanBeNull] string steamIdentityId)
        {
            if (steamIdentityId == null || steamIdentityId == "0")
            {
                var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var bla    = await _steamIdentityService.FindOne(new ObjectId(userId));

                return(View("SteamIdentity", new SteamIdentity
                {
                    LiteDbUsers = (await _userService.FindAll()).ToList()
                }));
            }


            var steamIdentity = await _steamIdentityService.FindOne(steamIdentityId);

            steamIdentity.LiteDbUsers = (await _userService.FindAll()).ToList();
            return(View("SteamIdentity", steamIdentity));
        }
        public async Task <IActionResult> EditModList(int serverId)
        {
            if (!await RightsHandler.HasRightsToThisPavlovServer(HttpContext.User,
                                                                 await _userservice.getUserFromCp(HttpContext.User), serverId, _service, _pavlovServerService))
            {
                return(Forbid());
            }
            var server = await _pavlovServerService.FindOne(serverId);

            var tmpUserIds = await _userservice.FindAll();

            var userIds = new List <LiteDbUser>();
            var isAdmin = false;
            var isMod   = false;

            foreach (var user in tmpUserIds)
            {
                if (user != null)
                {
                    isAdmin = await UserManager.IsInRoleAsync(user, "Admin");

                    isMod = await UserManager.IsInRoleAsync(user, "Mod");

                    var steamIdentity = await _steamIdentityService.FindOne(user.Id);

                    if (!isAdmin && !isMod && steamIdentity != null)
                    {
                        userIds.Add(user);
                    }
                }
            }

            var selectedUserIds = await _serverSelectedModsService.FindAllFrom(server);

            //service
            var model = new PavlovServerModlistViewModel
            {
                userIds        = selectedUserIds.Select(x => x.LiteDbUser.Id.ToString()).ToList(),
                pavlovServerId = server.Id
            };

            ViewBag.Users = userIds.ToList();
            return(View("ModList", model));
        }
        public static Match CreateMatch(MatchService matchService, PavlovServer pavlovServer, bool teamMatch,
                                        TeamService teamService, SteamIdentityService steamIdentityService, UserManager <LiteDbUser> userManager,
                                        MatchSelectedSteamIdentitiesService matchSelectedSteamIdentitiesService,
                                        MatchSelectedTeamSteamIdentitiesService matchSelectedTeamSteamIdentitiesService)
        {
            var user = ServerSelectedModServiceTests.InsertUserAndSteamIdentity(steamIdentityService, userManager,
                                                                                "test");
            var user2 = ServerSelectedModServiceTests.InsertUserAndSteamIdentity(steamIdentityService, userManager,
                                                                                 "test2", "2");
            var steamIdentity1 = steamIdentityService.FindOne(user.Id).GetAwaiter().GetResult();
            var steamIdentity2 = steamIdentityService.FindOne(user2.Id).GetAwaiter().GetResult();
            var team1          = TeamSelectedSteamIdentityServiceTest.CreateTeam(teamService);
            var team2          = TeamSelectedSteamIdentityServiceTest.CreateTeam(teamService, "test2");

            if (teamMatch)
            {
                matchService.Upsert(new Match
                {
                    Name         = "Test",
                    MapId        = "null",
                    GameMode     = "TDM",
                    ForceStart   = false,
                    ForceSop     = false,
                    TimeLimit    = 40,
                    PlayerSlots  = 10,
                    Team0        = team1,
                    Team1        = team2,
                    PavlovServer = pavlovServer,
                    Status       = Status.Preparing
                }).GetAwaiter().GetResult();
            }
            else
            {
                matchService.Upsert(new Match
                {
                    Name         = "Test",
                    MapId        = "null",
                    GameMode     = "GUN",
                    ForceStart   = false,
                    ForceSop     = false,
                    TimeLimit    = 40,
                    PlayerSlots  = 10,
                    Team0        = team1,
                    PavlovServer = pavlovServer,
                    Status       = Status.Preparing
                }).GetAwaiter().GetResult();
            }


            var match = matchService.FindAll().GetAwaiter().GetResult().FirstOrDefault();

            if (teamMatch)
            {
                match.MatchTeam0SelectedSteamIdentities = new List <MatchTeamSelectedSteamIdentity>
                {
                    new()
                    {
                        SteamIdentityId = steamIdentity1.Id,
                        SteamIdentity   = steamIdentity1,
                        matchId         = match.Id,
                        TeamId          = 0
                    }
                };
                match.MatchTeam1SelectedSteamIdentities = new List <MatchTeamSelectedSteamIdentity>
                {
                    new()
                    {
                        SteamIdentityId = steamIdentity2.Id,
                        SteamIdentity   = steamIdentity2,
                        matchId         = match.Id,
                        TeamId          = 1
                    }
                };
                matchSelectedTeamSteamIdentitiesService.Upsert(match.MatchTeam0SelectedSteamIdentities, match.Id, 0)
                .GetAwaiter().GetResult();
                matchSelectedTeamSteamIdentitiesService.Upsert(match.MatchTeam1SelectedSteamIdentities, match.Id, 1)
                .GetAwaiter().GetResult();
            }
            else
            {
                match.MatchSelectedSteamIdentities = new List <MatchSelectedSteamIdentity>
                {
                    new()
                    {
                        SteamIdentityId = steamIdentity1.Id,
                        SteamIdentity   = steamIdentity1,
                        matchId         = match.Id
                    },
                    new()
                    {
                        SteamIdentityId = steamIdentity2.Id,
                        SteamIdentity   = steamIdentity2,
                        matchId         = match.Id
                    }
                };

                matchSelectedSteamIdentitiesService.Upsert(match.MatchSelectedSteamIdentities, match.Id).GetAwaiter()
                .GetResult();
            }

            matchService.Upsert(match);
            return(match);
        }
        public async Task <IActionResult> DownloadPersonalData()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            _logger.LogInformation("User with ID '{UserId}' asked for their personal data.", _userManager.GetUserId(User));

            // Only include personal data for download
            var personalData      = new Dictionary <string, string>();
            var personalDataProps = typeof(IdentityUser).GetProperties().Where(
                prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));

            foreach (var p in personalDataProps)
            {
                try
                {
                    var getValue = p.GetValue(user)?.ToString() ?? "null";
                    personalData.Add(p.Name, getValue);
                }
                catch (Exception)
                {
                    //ignore
                }
            }

            var logins = await _userManager.GetLoginsAsync(user);

            foreach (var l in logins)
            {
                personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey);
            }

            var id = await _steamIdentityService.FindOne(user.Id);

            var AdditionalData = new Dictionary <string, IEnumerable>();

            if (id != null)
            {
                AdditionalData.Add("HistorySteam", (await _pavlovServerPlayerHistoryService.FindAllFromPlayer(id.Id)));
                AdditionalData.Add("MatchesSteam", (await _matchService.PersonalStats(id.Id)));
                AdditionalData.Add("LeaderBoardSteam", (await _steamIdentityStatsServerService.GetForSteamId(id.Id)));
            }

            if (id != null && id.OculusId != "" && await _steamIdentityService.FindOne(id.OculusId) == null)
            {
                AdditionalData.Add("HistoryOculus", (await _pavlovServerPlayerHistoryService.FindAllFromPlayer(id.OculusId)));
                AdditionalData.Add("MatchesOculus", (await _matchService.PersonalStats(id.OculusId)));
                AdditionalData.Add("LeaderBoardOculus", (await _steamIdentityStatsServerService.GetForSteamId(id.OculusId)));
            }

            personalData.Add($"Authenticator Key", await _userManager.GetAuthenticatorKeyAsync(user));

            Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
            return(new FileContentResult(JsonSerializer.SerializeToUtf8Bytes(new
            {
                internalData = personalData,
                additionalData = AdditionalData
            }), "application/json"));
        }