示例#1
0
        public async Task <DestinyProfileUserInfoCard> GetAccount(bool preventSet = false)
        {
            SetupServices();

            if (!oauthManager.IsAuthorized)
            {
                return(null);
            }

            if (currentAccount != null)
            {
                return(currentAccount);
            }

            var linkedProfiles = await Util.RequestAndRetry(() => destinyApi.GetLinkedProfiles(oauthManager.currentToken.AccessToken, oauthManager.currentToken.MembershipId));

            if (linkedProfiles == null)
            {
                return(null);
            }

            var account = linkedProfiles.Profiles.FirstOrDefault();

            if (!preventSet)
            {
                currentAccount = account;
            }

            return(account);
        }
示例#2
0
        public async Task <IActionResult> Index()
        {
            _logger.LogInformation("Index");
            var accessToken = _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var value = User.FindFirst(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            long.TryParse(value, out long membershipId);

            var linkedProfiles = await _destiny.GetLinkedProfiles(await accessToken, membershipId);

            var accounts = linkedProfiles.Profiles.Select(profile => new Account(profile.MembershipType, profile.MembershipId))
                           .ToList();

            if (1 == accounts.Count)
            {
                _logger.LogInformation("Only one account - redirecting to account page");

                // If there is only one account, redirect to the page for it.
                var url = Url.RouteUrl("AccountDetails", new
                {
                    type = (int)accounts[0].Type,
                    id   = accounts[0].Id
                });
                return(Redirect(url));
            }

            var model = new AccountsViewModel();

            model.Accounts = accounts;
            return(View(model));
        }
        public async Task <IActionResult> Index()
        {
            _logger.LogInformation("Index");
            var accessToken = _contextAccessor.HttpContext.GetTokenAsync("access_token");

            var value = User.FindFirst(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            long.TryParse(value, out long membershipId);

            var linkedProfiles = await _destiny2.GetLinkedProfiles(await accessToken, membershipId);

            var accounts = linkedProfiles.Profiles.Select(profile => new Account(profile.MembershipType, profile.MembershipId))
                           .ToList();

            if (1 == accounts.Count)
            {
                _logger.LogInformation("Only one account - redirecting to account page");

                // If there is only one account, redirect to the page for it.
                var url = Url.RouteUrl("WeaponModsIndex", new
                {
                    type      = (int)accounts[0].Type,
                    accountId = accounts[0].Id
                });
                return(Redirect(url));
            }

            throw new Exception("More than one account tied to your Bungie account isn't supported");
        }