anonymous logs
This commit is contained in:
parent
262ca6ef0d
commit
a58210a4f8
@ -42,10 +42,11 @@ class DiscordAuthenticationBackend(BaseBackend):
|
|||||||
# also check the new `token_expires` field to see if the token is invalid
|
# also check the new `token_expires` field to see if the token is invalid
|
||||||
# then request a new token, instead of making the user login again
|
# then request a new token, instead of making the user login again
|
||||||
#
|
#
|
||||||
|
# UPDATE:
|
||||||
|
# is this even possible or necessary with the scope of this app?
|
||||||
|
#
|
||||||
# https://discord.com/developers/docs/game-sdk/applications#data-models
|
# https://discord.com/developers/docs/game-sdk/applications#data-models
|
||||||
|
|
||||||
log.debug(discord_user_data)
|
|
||||||
|
|
||||||
discord_user_id = discord_user_data["id"]
|
discord_user_id = discord_user_data["id"]
|
||||||
existing_user = self.get_user(discord_user_id)
|
existing_user = self.get_user(discord_user_id)
|
||||||
log.debug("authenticating, does user exist: %s", bool(existing_user))
|
log.debug("authenticating, does user exist: %s", bool(existing_user))
|
||||||
|
@ -27,14 +27,11 @@ class DiscordUserOAuth2Manager(BaseUserManager):
|
|||||||
The newly created DiscordUser instance.
|
The newly created DiscordUser instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
username = discord_user_data.get("username")
|
log.info("creating new user")
|
||||||
log.debug("creating new user: %s", username)
|
|
||||||
|
|
||||||
discord_user_data.update(extra_fields)
|
discord_user_data.update(extra_fields)
|
||||||
user = discord_user_data # shorthand
|
user = discord_user_data # shorthand
|
||||||
|
|
||||||
log.debug(user)
|
|
||||||
|
|
||||||
return self.create(
|
return self.create(
|
||||||
id=user["id"],
|
id=user["id"],
|
||||||
username=user["username"],
|
username=user["username"],
|
||||||
@ -55,8 +52,7 @@ class DiscordUserOAuth2Manager(BaseUserManager):
|
|||||||
Create a user from their discord data, but also make them a superuser.
|
Create a user from their discord data, but also make them a superuser.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
username = discord_user_data.get("username")
|
log.info("creating new superuser")
|
||||||
log.debug("creating new superuser: %s", username)
|
|
||||||
|
|
||||||
extra_fields.setdefault("is_staff", True)
|
extra_fields.setdefault("is_staff", True)
|
||||||
extra_fields.setdefault("is_superuser", True)
|
extra_fields.setdefault("is_superuser", True)
|
||||||
|
@ -57,11 +57,11 @@ class DiscordLoginRedirect(View):
|
|||||||
A call is made to the Discord API.
|
A call is made to the Discord API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.debug("exchanging code for access token")
|
||||||
|
|
||||||
request_data = settings.DISCORD_CODE_EXCHANGE_REQUEST
|
request_data = settings.DISCORD_CODE_EXCHANGE_REQUEST
|
||||||
request_data["data"]["code"] = code
|
request_data["data"]["code"] = code
|
||||||
|
|
||||||
log.debug("request data: %s", request_data)
|
|
||||||
|
|
||||||
# Fetch the access token
|
# Fetch the access token
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{settings.DISCORD_API_URL}/oauth2/token",
|
url=f"{settings.DISCORD_API_URL}/oauth2/token",
|
||||||
@ -78,11 +78,11 @@ class DiscordLoginRedirect(View):
|
|||||||
token.
|
token.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.debug("refreshing access token")
|
||||||
|
|
||||||
request_data = settings.DISCORD_REFRESH_TOKEN_REQUEST
|
request_data = settings.DISCORD_REFRESH_TOKEN_REQUEST
|
||||||
request_data["data"]["refresh_token"] = refresh_token
|
request_data["data"]["refresh_token"] = refresh_token
|
||||||
|
|
||||||
log.debug("request data: %s", request_data)
|
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{settings.DISCORD_API_URL}/oauth2/token",
|
url=f"{settings.DISCORD_API_URL}/oauth2/token",
|
||||||
data=request_data["data"],
|
data=request_data["data"],
|
||||||
@ -97,14 +97,16 @@ class DiscordLoginRedirect(View):
|
|||||||
A call is made to the Discord API.
|
A call is made to the Discord API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.debug("fetching raw user data")
|
||||||
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
url=f"{settings.DISCORD_API_URL}/users/@me",
|
url=f"{settings.DISCORD_API_URL}/users/@me",
|
||||||
headers={"Authorization": f"Bearer {access_token}"}
|
headers={"Authorization": f"Bearer {access_token}"}
|
||||||
)
|
)
|
||||||
log.debug(response)
|
|
||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
# Assign the default avatar
|
||||||
if not data.get("avatar"):
|
if not data.get("avatar"):
|
||||||
data["avatar"] = int(data["id"]) % 5
|
data["avatar"] = int(data["id"]) % 5
|
||||||
|
|
||||||
@ -129,7 +131,7 @@ class GuildsView(View):
|
|||||||
status = response.status_code
|
status = response.status_code
|
||||||
|
|
||||||
if status != 200:
|
if status != 200:
|
||||||
log.debug("Bad status code getting guilds: %s", status)
|
log.warning("Bad status code getting guilds: %s", status)
|
||||||
return JsonResponse(content, safe=False, status=status)
|
return JsonResponse(content, safe=False, status=status)
|
||||||
|
|
||||||
valid_guilds = [guild for guild in response.json() if self._has_permissions(guild)]
|
valid_guilds = [guild for guild in response.json() if self._has_permissions(guild)]
|
||||||
@ -147,11 +149,9 @@ class GuildsView(View):
|
|||||||
class GuildChannelsView(View):
|
class GuildChannelsView(View):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
log.debug("fetching channels from guid")
|
||||||
|
|
||||||
guild_id = request.GET.get("guild")
|
guild_id = request.GET.get("guild")
|
||||||
|
|
||||||
log.debug("fetching channels from %s using token: %s", guild_id, settings.BOT_TOKEN)
|
|
||||||
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
url=f"{settings.DISCORD_API_URL}/guilds/{guild_id}/channels",
|
url=f"{settings.DISCORD_API_URL}/guilds/{guild_id}/channels",
|
||||||
headers={"Authorization": f"Bot {settings.BOT_TOKEN}"}
|
headers={"Authorization": f"Bot {settings.BOT_TOKEN}"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user