public override async Task <DomainValidationResult <object> > GenerateAuthenticationAsync(UserId userId, LeagueOfLegendsRequest request)
        {
            try
            {
                var result = new DomainValidationResult <object>();

                var summoner = await _leagueOfLegendsService.Summoner.GetSummonerByNameAsync(Region.Na, request.SummonerName);

                if (await _gameCredentialRepository.CredentialExistsAsync(PlayerId.Parse(summoner.AccountId), Game))
                {
                    result.AddFailedPreconditionError("Summoner's name is already linked by another eDoxa account");
                }

                if (result.IsValid)
                {
                    if (await _gameAuthenticationRepository.AuthenticationExistsAsync(userId, Game))
                    {
                        await _gameAuthenticationRepository.RemoveAuthenticationAsync(userId, Game);
                    }

                    var gameAuthentication = await this.GenerateAuthFactor(summoner);

                    await _gameAuthenticationRepository.AddAuthenticationAsync(userId, Game, gameAuthentication);

                    return(gameAuthentication.Factor);
                }

                return(result);
            }
            catch (RiotSharpException)
            {
                return(DomainValidationResult <object> .Failure("Summoner name is invalid"));
            }
        }
コード例 #2
0
        public override async Task <DomainValidationResult <GameAuthentication> > ValidateAuthenticationAsync(UserId userId, LeagueOfLegendsGameAuthentication gameAuthentication)
        {
            var result = new DomainValidationResult <GameAuthentication>();

            await _gameAuthenticationRepository.RemoveAuthenticationAsync(userId, Game);

            var summoner = await _leagueOfLegendsService.Summoner.GetSummonerByAccountIdAsync(Region.Na, gameAuthentication.PlayerId);

            if (summoner.ProfileIconId != gameAuthentication.Factor.ExpectedSummonerProfileIconId)
            {
                result.AddFailedPreconditionError($"{Game} authentication process failed.");
            }

            return(result);
        }