Exemplo n.º 1
0
        private async Task CompleteUserCreation(string code, string state)
        {
            if (string.IsNullOrEmpty(code))
            {
                ErrorMessage = "Invalid external code. Please try again later";
            }

            // redirect url should not be encoded
            var data = await _apiClient.ExchangeCodeAsync(code, _discordOAuth.RedirectUrl);

            if (data?.User == null || data.User.Id == 0)
            {
                ErrorMessage = "Failed to communicate with Discord servers. Please try again later";
                return;
            }
            else
            {
                var dto = new AddUserDto()
                {
                    Code          = code,
                    HardwareId    = state,
                    DiscordUserId = data.User.Id
                };

                ApiUser apiUser = await _apiUserService.GetOrAddAsync(dto);

                ApiKey = apiUser.ApiKey;
            }
        }