Skip to content
Snippets Groups Projects
Commit d4587e6d authored by stotayag's avatar stotayag
Browse files

Merge branch 'fix-issues' into 'main'

some bad possible fixes for google login in cosmos

See merge request !66
parents a316280d 99218977
No related branches found
No related tags found
1 merge request!66some bad possible fixes for google login in cosmos
Pipeline #15731 passed
...@@ -4,7 +4,7 @@ Helper functions to help with authentication ...@@ -4,7 +4,7 @@ Helper functions to help with authentication
import json import json
from typing import Union 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.oauth2 import id_token
from google.auth.transport import requests from google.auth.transport import requests
from mongoengine.errors import DoesNotExist, MultipleObjectsReturned from mongoengine.errors import DoesNotExist, MultipleObjectsReturned
...@@ -78,6 +78,11 @@ def google_login(token: str): ...@@ -78,6 +78,11 @@ def google_login(token: str):
except MultipleObjectsReturned: except MultipleObjectsReturned:
# should not get here... # should not get here...
abort(400) 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) return create_token_for_user(user)
......
...@@ -30,14 +30,14 @@ class User(Document): ...@@ -30,14 +30,14 @@ class User(Document):
is stored in the 'google' field. This way it is easy to create new users with 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. 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) email = EmailField(required=True, unique=True)
# is not required as other authentication methods are available. # is not required as other authentication methods are available.
password = StringField(min_length=MIN_PASSWORD_LENGTH) password = StringField(min_length=MIN_PASSWORD_LENGTH)
role = StringField(required=True, default=USER_ROLE, choises=ROLES) role = StringField(required=True, default=USER_ROLE, choises=ROLES)
timezone = StringField(default="UTC") # Choises timezone = StringField(default="UTC") # TODO Choises
currency = StringField(default="eur") # Choises currency = StringField(default="eur") # TODO Choises
locale = StringField(default="en") # Choises locale = StringField(default="en") # TODO Choises
google = EmbeddedDocumentField(GoogleAccount, default=None, sparse=True) google = EmbeddedDocumentField(GoogleAccount, default=None, sparse=True)
@classmethod @classmethod
...@@ -59,4 +59,4 @@ class User(Document): ...@@ -59,4 +59,4 @@ class User(Document):
try: try:
return cls.objects.get(email=email) return cls.objects.get(email=email)
except: except:
return None return None
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment