nice francis
This commit is contained in:
parent
688f303978
commit
acbc5deb69
1 changed files with 11 additions and 10 deletions
|
@ -6,6 +6,7 @@ from django.contrib.auth import login
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
|
import users
|
||||||
from users.models import CustomUser
|
from users.models import CustomUser
|
||||||
|
|
||||||
logger = logging.getLogger(__file__)
|
logger = logging.getLogger(__file__)
|
||||||
|
@ -28,17 +29,16 @@ def register_callback(req: HttpRequest):
|
||||||
csrftoken = req.COOKIES.get('csrftoken')
|
csrftoken = req.COOKIES.get('csrftoken')
|
||||||
print(csrftoken)
|
print(csrftoken)
|
||||||
response = requests.post(settings.OAUTH["ACCESS_TOKEN_URI"],
|
response = requests.post(settings.OAUTH["ACCESS_TOKEN_URI"],
|
||||||
data={'code': code,
|
data={'code': code,
|
||||||
'grant_type': 'authorization_code',
|
'grant_type': 'authorization_code',
|
||||||
'client_id': settings.OAUTH["CLIENT_ID"],
|
'client_id': settings.OAUTH["CLIENT_ID"],
|
||||||
'client_secret': settings.OAUTH["CLIENT_SECRET"],
|
'client_secret': settings.OAUTH["CLIENT_SECRET"],
|
||||||
'redirect_uri': settings.OAUTH["REDIRECT_URI"]},
|
'redirect_uri': settings.OAUTH["REDIRECT_URI"]},
|
||||||
cookies=None,
|
cookies=None,
|
||||||
headers={'Referer': f'{settings.SERVER_URL}/login/zeus/register'})
|
headers={'Referer': f'{settings.SERVER_URL}/login/zeus/register'})
|
||||||
try:
|
try:
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
json: dict = response.json()
|
json: dict = response.json()
|
||||||
csrftoken = response.cookies['csrftoken']
|
|
||||||
print(response.cookies)
|
print(response.cookies)
|
||||||
# TODO: maybe later do something with the refresh token.
|
# TODO: maybe later do something with the refresh token.
|
||||||
user: dict = user_info(json['access_token'], csrftoken)
|
user: dict = user_info(json['access_token'], csrftoken)
|
||||||
|
@ -59,12 +59,13 @@ def register_callback(req: HttpRequest):
|
||||||
|
|
||||||
|
|
||||||
def validate_user(zeus_id, username) -> CustomUser:
|
def validate_user(zeus_id, username) -> CustomUser:
|
||||||
user = CustomUser.objects.get(zeus_id=zeus_id)
|
try:
|
||||||
if user is None:
|
user = CustomUser.objects.get(zeus_id=zeus_id)
|
||||||
|
user.username = username
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
except users.models.CustomUser.DoesNotExist as e:
|
||||||
return CustomUser.objects.create_user(zeus_id, username)
|
return CustomUser.objects.create_user(zeus_id, username)
|
||||||
user.username = username
|
|
||||||
user.save()
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
def user_info(access_token, csrftoken):
|
def user_info(access_token, csrftoken):
|
||||||
|
|
Loading…
Reference in a new issue