From 66797f511a3372ecc49e77aa0c254b4b941ef593 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Sun, 6 Nov 2022 12:16:16 +0100 Subject: [PATCH] :bug: Maybe fixed oauth bug --- classquiz/oauth/github.py | 19 ++++++++++--------- classquiz/oauth/google.py | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/classquiz/oauth/github.py b/classquiz/oauth/github.py index 30914b6..301398e 100644 --- a/classquiz/oauth/github.py +++ b/classquiz/oauth/github.py @@ -1,7 +1,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. - +import uuid from typing import Optional import authlib.integrations.base_client @@ -105,15 +105,16 @@ async def auth(request: Request, response: Response): user_in_db = await User.objects.get_or_none(email=user_data.email) if user_in_db is None: # REGISTER USER - create_user = User( - email=user_data.email, - username=user_data.login, - verified=True, - auth_type=UserAuthTypes.GITHUB, - avatar=gzipped_user_avatar(), - ) try: - await create_user.save() + await User.objects.create( + id=uuid.uuid4(), + email=user_data.email, + username=user_data.login, + verified=True, + auth_type=UserAuthTypes.GITHUB, + avatar=gzipped_user_avatar(), + ) + except Exception as e: raise HTTPException(status_code=500, detail=str(e)) user = await User.objects.get_or_none( diff --git a/classquiz/oauth/google.py b/classquiz/oauth/google.py index 1e94f5a..64f1009 100644 --- a/classquiz/oauth/google.py +++ b/classquiz/oauth/google.py @@ -1,6 +1,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. +import uuid from fastapi import APIRouter, Request, HTTPException, Response from classquiz.config import settings @@ -80,6 +81,7 @@ async def auth(request: Request, response: Response): # REGISTER USER try: await User.object.create( + id=uuid.uuid4(), email=user_data.email, username=user_data.name, verified=user_data.email_verified,