diff --git a/app/auth/views/facebook.py b/app/auth/views/facebook.py index b59beceb..e5a2cabd 100644 --- a/app/auth/views/facebook.py +++ b/app/auth/views/facebook.py @@ -14,7 +14,7 @@ from app.config import ( ) from app.extensions import db from app.log import LOG -from app.models import User +from app.models import User, SocialAuth from .login_utils import after_login from ...email_utils import can_be_used_as_personal_email, email_already_used @@ -143,4 +143,8 @@ def facebook_callback(): # reset the next_url to avoid user getting redirected at each login :) session.pop("facebook_next_url", None) + if not SocialAuth.get_by(user_id=user.id, social="facebook"): + SocialAuth.create(user_id=user.id, social="facebook") + db.session.commit() + return after_login(user, next_url) diff --git a/app/auth/views/github.py b/app/auth/views/github.py index 19ccbb0c..6a23ab0d 100644 --- a/app/auth/views/github.py +++ b/app/auth/views/github.py @@ -9,7 +9,7 @@ from app.config import GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, URL, DISABLE_REGI from app.email_utils import can_be_used_as_personal_email, email_already_used from app.extensions import db from app.log import LOG -from app.models import User +from app.models import User, SocialAuth from app.utils import encode_url _authorization_base_url = "https://github.com/login/oauth/authorize" @@ -105,6 +105,10 @@ def github_callback(): flash(f"Welcome to SimpleLogin {user.name}!", "success") + if not SocialAuth.get_by(user_id=user.id, social="github"): + SocialAuth.create(user_id=user.id, social="github") + db.session.commit() + # The activation link contains the original page, for ex authorize page next_url = request.args.get("next") if request.args else None diff --git a/app/auth/views/google.py b/app/auth/views/google.py index 78792e60..5639b1ec 100644 --- a/app/auth/views/google.py +++ b/app/auth/views/google.py @@ -7,7 +7,7 @@ from app.auth.base import auth_bp from app.config import URL, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, DISABLE_REGISTRATION from app.extensions import db from app.log import LOG -from app.models import User, File +from app.models import User, File, SocialAuth from app.utils import random_string from .login_utils import after_login from ...email_utils import can_be_used_as_personal_email, email_already_used @@ -128,6 +128,10 @@ def google_callback(): # reset the next_url to avoid user getting redirected at each login :) session.pop("google_next_url", None) + if not SocialAuth.get_by(user_id=user.id, social="github"): + SocialAuth.create(user_id=user.id, social="github") + db.session.commit() + return after_login(user, next_url)