save which social network user uses in SocialAuth table
This commit is contained in:
parent
7f70dd1678
commit
87b6df9408
|
@ -14,7 +14,7 @@ from app.config import (
|
||||||
)
|
)
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import User
|
from app.models import User, SocialAuth
|
||||||
from .login_utils import after_login
|
from .login_utils import after_login
|
||||||
from ...email_utils import can_be_used_as_personal_email, email_already_used
|
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 :)
|
# reset the next_url to avoid user getting redirected at each login :)
|
||||||
session.pop("facebook_next_url", None)
|
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)
|
return after_login(user, next_url)
|
||||||
|
|
|
@ -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.email_utils import can_be_used_as_personal_email, email_already_used
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import User
|
from app.models import User, SocialAuth
|
||||||
from app.utils import encode_url
|
from app.utils import encode_url
|
||||||
|
|
||||||
_authorization_base_url = "https://github.com/login/oauth/authorize"
|
_authorization_base_url = "https://github.com/login/oauth/authorize"
|
||||||
|
@ -105,6 +105,10 @@ def github_callback():
|
||||||
|
|
||||||
flash(f"Welcome to SimpleLogin {user.name}!", "success")
|
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
|
# The activation link contains the original page, for ex authorize page
|
||||||
next_url = request.args.get("next") if request.args else None
|
next_url = request.args.get("next") if request.args else None
|
||||||
|
|
||||||
|
|
|
@ -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.config import URL, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, DISABLE_REGISTRATION
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
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 app.utils import random_string
|
||||||
from .login_utils import after_login
|
from .login_utils import after_login
|
||||||
from ...email_utils import can_be_used_as_personal_email, email_already_used
|
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 :)
|
# reset the next_url to avoid user getting redirected at each login :)
|
||||||
session.pop("google_next_url", None)
|
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)
|
return after_login(user, next_url)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue