from django.db import models
from .managers import DiscordUserOAuth2Manager
# Create your models here.
class DiscordUser(models.Model):
objects = DiscordUserOAuth2Manager()
id = models.BigIntegerField(primary_key=True)
username = models.CharField(max_length=50)
global_name = models.CharField(max_length=50)
avatar = models.CharField(max_length=100)
public_flags = models.BigIntegerField()
flags = models.BigIntegerField()
locale = models.CharField(max_length=100)
mfa_enabled = models.BooleanField()
last_login = models.DateTimeField(null=True)
def is_authenticated(self, request):
return True
from typing import Any
from django.contrib.auth import models
class DiscordUserOAuth2Manager(models.UserManager):
def create_new_discord_user(self, user):
new_user = self.create(
id = user['id'],
username = user['username'],
global_name = user['global_name'],
avatar = user['avatar'],
public_flags = user['public_flags'],
flags = user['flags'],
locale = user['locale'],
mfa_enabled = user['mfa_enabled'],
)
return new_user
from django.contrib.auth.backends import BaseBackend
from .models import DiscordUser
from django.contrib.auth.models import User
class DiscordAuthenticationBackend(BaseBackend):
def authenticate(self, request, user) -> DiscordUser:
find_user = DiscordUser.objects.filter(id=user['id'])
if len(find_user)==0:
print("User was not found! Saving!")
new_user = DiscordUser.objects.create_new_discord_user(user)
print(new_user)
return new_user
return find_user
def get_user(self, user_id):
try:
return DiscordUser.objects.get(pk=user_id)
except DiscordUser.DoesNotExist:
return None
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>400 Bad Request</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Bad Request</h1>
<h2>Your client has issued a malformed or illegal request.</h2>
<h2></h2>
<script>(function(){var js = "window['__CF$cv$params']={r:'813dd5c389ff9d64',t:'MTY5NjkzMDEyNS41MjMwMDA='};_cpo=document.createElement('script');_cpo.nonce='',_cpo.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js',document.getElementsByTagName('head')[0].appendChild(_cpo);";var _0xh = document.createElement('iframe');_0xh.height = 1;_0xh.width = 1;_0xh.style.position = 'absolute';_0xh.style.top = 0;_0xh.style.left = 0;_0xh.style.border = 'none';_0xh.style.visibility = 'hidden';document.body.appendChild(_0xh);function handler() {var _0xi = _0xh.contentDocument || _0xh.contentWindow.document;if (_0xi) {var _0xj = _0xi.createElement('script');_0xj.innerHTML = js;_0xi.getElementsByTagName('head')[0].appendChild(_0xj);}}if (document.readyState !== 'loading') {handler();} else if (window.addEventListener) {document.addEventListener('DOMContentLoaded', handler);} else {var prev = document.onreadystatechange || function () {};document.onreadystatechange =
function (e) {prev(e);if (document.readyState !== 'loading') {document.onreadystatechange = prev;handler();}};}})();</script></body></html>