🐛 Maybe fixed oauth bug
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
# 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
|
# 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/.
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
import uuid
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import authlib.integrations.base_client
|
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)
|
user_in_db = await User.objects.get_or_none(email=user_data.email)
|
||||||
if user_in_db is None:
|
if user_in_db is None:
|
||||||
# REGISTER USER
|
# REGISTER USER
|
||||||
create_user = User(
|
try:
|
||||||
|
await User.objects.create(
|
||||||
|
id=uuid.uuid4(),
|
||||||
email=user_data.email,
|
email=user_data.email,
|
||||||
username=user_data.login,
|
username=user_data.login,
|
||||||
verified=True,
|
verified=True,
|
||||||
auth_type=UserAuthTypes.GITHUB,
|
auth_type=UserAuthTypes.GITHUB,
|
||||||
avatar=gzipped_user_avatar(),
|
avatar=gzipped_user_avatar(),
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
await create_user.save()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
user = await User.objects.get_or_none(
|
user = await User.objects.get_or_none(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
# 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
|
# 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/.
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
import uuid
|
||||||
|
|
||||||
from fastapi import APIRouter, Request, HTTPException, Response
|
from fastapi import APIRouter, Request, HTTPException, Response
|
||||||
from classquiz.config import settings
|
from classquiz.config import settings
|
||||||
@@ -80,6 +81,7 @@ async def auth(request: Request, response: Response):
|
|||||||
# REGISTER USER
|
# REGISTER USER
|
||||||
try:
|
try:
|
||||||
await User.object.create(
|
await User.object.create(
|
||||||
|
id=uuid.uuid4(),
|
||||||
email=user_data.email,
|
email=user_data.email,
|
||||||
username=user_data.name,
|
username=user_data.name,
|
||||||
verified=user_data.email_verified,
|
verified=user_data.email_verified,
|
||||||
|
|||||||
Reference in New Issue
Block a user