Further cleanup
This commit is contained in:
+20
-36
@@ -77,43 +77,27 @@ async def auth(request: Request, response: Response):
|
||||
except (TypeError, ValidationError):
|
||||
raise HTTPException(status_code=401, detail="Something went wrong.")
|
||||
|
||||
user_in_db = await User.objects.get_or_none(email=user_data.email)
|
||||
if user_in_db is None:
|
||||
# REGISTER USER
|
||||
try:
|
||||
await User.objects.create(
|
||||
id=uuid.uuid4(),
|
||||
email=user_data.email,
|
||||
username=user_data.preferred_username,
|
||||
verified=user_data.email_verified,
|
||||
auth_type=UserAuthTypes.CUSTOM,
|
||||
google_uid=user_data.sub.hex,
|
||||
avatar=gzipped_user_avatar(),
|
||||
)
|
||||
# skipcq: PYL-W0703
|
||||
except Exception as e:
|
||||
if type(e) is asyncpg.exceptions.UniqueViolationError:
|
||||
error = True
|
||||
counter = 1
|
||||
while error:
|
||||
try:
|
||||
await User.objects.create(
|
||||
id=uuid.uuid4(),
|
||||
email=user_data.email,
|
||||
username=f"{user_data.preferred_username}{counter}",
|
||||
verified=user_data.email_verified,
|
||||
auth_type=UserAuthTypes.CUSTOM,
|
||||
google_uid=user_data.sub.hex,
|
||||
avatar=gzipped_user_avatar(),
|
||||
)
|
||||
error = False
|
||||
except asyncpg.exceptions.UniqueViolationError:
|
||||
counter += 1
|
||||
error = True
|
||||
else:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
try:
|
||||
await User.objects.create(
|
||||
id=uuid.uuid4(),
|
||||
email=user_data.email,
|
||||
username=user_data.preferred_username,
|
||||
verified=user_data.email_verified,
|
||||
auth_type=UserAuthTypes.CUSTOM,
|
||||
google_uid=user_data.sub.hex,
|
||||
avatar=gzipped_user_avatar(),
|
||||
)
|
||||
# skipcq: PYL-W0703
|
||||
except asyncpg.exceptions.UniqueViolationError:
|
||||
# Most likely a duplicate email/username, not UUID.
|
||||
raise HTTPException(status_code=400, detail="User already exists.")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
user = await User.objects.get_or_none(
|
||||
email=user_data.email, google_uid=user_data.sub.hex, auth_type=UserAuthTypes.CUSTOM, verified=True
|
||||
email=user_data.email,
|
||||
google_uid=user_data.sub.hex,
|
||||
auth_type=UserAuthTypes.CUSTOM,
|
||||
verified=True,
|
||||
)
|
||||
print(user_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user