From c3421af6022a2312c40aa0345ca64aa35867f7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= <trabarni@gmail.com> Date: Sun, 28 Jan 2018 00:13:55 +0100 Subject: [PATCH] Add create profile on first login --- src/account/auth_pipeline.py | 11 +++++++++++ src/kszkepzes/settings/base.py | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/account/auth_pipeline.py diff --git a/src/account/auth_pipeline.py b/src/account/auth_pipeline.py new file mode 100644 index 0000000..b1918c5 --- /dev/null +++ b/src/account/auth_pipeline.py @@ -0,0 +1,11 @@ +from django.core import exceptions + +from . import models + + +def create_profile(backend, user, response, *args, **kwargs): + if backend.name == 'authsch': + try: + user.profile + except exceptions.ObjectDoesNotExist: + models.Profile.objects.create(user=user) diff --git a/src/kszkepzes/settings/base.py b/src/kszkepzes/settings/base.py index c34b78c..fa2f7b0 100644 --- a/src/kszkepzes/settings/base.py +++ b/src/kszkepzes/settings/base.py @@ -115,6 +115,19 @@ AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', ] +SOCIAL_AUTH_PIPELINE = ( + 'social_core.pipeline.social_auth.social_details', + 'social_core.pipeline.social_auth.social_uid', + 'social_core.pipeline.social_auth.auth_allowed', + 'social_core.pipeline.social_auth.social_user', + 'social_core.pipeline.user.get_username', + 'social_core.pipeline.user.create_user', + 'account.auth_pipeline.create_profile', + 'social_core.pipeline.social_auth.associate_user', + 'social_core.pipeline.social_auth.load_extra_data', + 'social_core.pipeline.user.user_details', +) + SOCIAL_AUTH_AUTHSCH_KEY = os.getenv('AUTHSCH_KEY') SOCIAL_AUTH_AUTHSCH_SECRET = os.getenv('AUTHSCH_SECRET') SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/' -- GitLab