diff --git a/src/tjts5901/authentication/utils.py b/src/tjts5901/authentication/utils.py index c2169db5fc6e0f64bf2dad305ad29de0f57c0cef..f9f2a4384b280f1c5a97578afe7d10c484c851d8 100644 --- a/src/tjts5901/authentication/utils.py +++ b/src/tjts5901/authentication/utils.py @@ -4,7 +4,7 @@ Helper functions to help with authentication import json from typing import Union -from flask import abort, session +from flask import abort, flash, redirect, session, url_for from google.oauth2 import id_token from google.auth.transport import requests from mongoengine.errors import DoesNotExist, MultipleObjectsReturned @@ -78,6 +78,11 @@ def google_login(token: str): except MultipleObjectsReturned: # should not get here... abort(400) + except Exception: + # should not get here... but some cosmosDB indexing stuff.. + # Quick fix + flash("Something went wrong..", 'error') + return redirect(url_for('authentication_blueprint.login')) return create_token_for_user(user) diff --git a/src/tjts5901/user/models.py b/src/tjts5901/user/models.py index 38ef5c693e21914c2806492b96a92b07151bda18..99406c1bd7f0e317f8b8841e6d731abe0242980b 100644 --- a/src/tjts5901/user/models.py +++ b/src/tjts5901/user/models.py @@ -30,14 +30,14 @@ class User(Document): is stored in the 'google' field. This way it is easy to create new users with google information and link existing users to their google accounts. """ - name = StringField(required=True, unique=True) + name = StringField(required=True, unique=False) email = EmailField(required=True, unique=True) # is not required as other authentication methods are available. password = StringField(min_length=MIN_PASSWORD_LENGTH) role = StringField(required=True, default=USER_ROLE, choises=ROLES) - timezone = StringField(default="UTC") # Choises - currency = StringField(default="eur") # Choises - locale = StringField(default="en") # Choises + timezone = StringField(default="UTC") # TODO Choises + currency = StringField(default="eur") # TODO Choises + locale = StringField(default="en") # TODO Choises google = EmbeddedDocumentField(GoogleAccount, default=None, sparse=True) @classmethod @@ -59,4 +59,4 @@ class User(Document): try: return cls.objects.get(email=email) except: - return None \ No newline at end of file + return None