diff --git a/pedasi/settings.py b/pedasi/settings.py index 4ab252cc275bd0c555f63291a96417d5a85fa6ee..44f089e5dd32b9fb4ce2189b60529a13bed8b968 100644 --- a/pedasi/settings.py +++ b/pedasi/settings.py @@ -243,6 +243,9 @@ SOCIAL_AUTH_PIPELINE = [ # Update the user record with any changed info from the auth service. 'social_core.pipeline.user.user_details', + + # Email admins to activate the account + 'profiles.social_auth.email_admins', ] SOCIAL_AUTH_LOGIN_REDIRECT_URL = reverse_lazy('index') @@ -310,3 +313,18 @@ STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'pedasi', 'static'), os.path.join(BASE_DIR, 'docs', 'build'), ] + + +# Email provider for notification emails +EMAIL_HOST = config('EMAIL_HOST', default=None) +EMAIL_PORT = config('EMAIL_PORT', cast=int, default=25) + +EMAIL_HOST_USER = config('EMAIL_HOST_USER', default=None) +EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default=None) + +EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool, default=False) +EMAIL_USE_SSL = config('EMAIL_USE_SSL', cast=bool, default=False) + +if DEBUG and not EMAIL_HOST: + EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' + EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'mail.log') diff --git a/profiles/social_auth.py b/profiles/social_auth.py index 18171507b5cf46669e425d65aa4d830bba27338a..1d2414085ced58ee34bf35d7ff49513edf197b73 100644 --- a/profiles/social_auth.py +++ b/profiles/social_auth.py @@ -4,6 +4,9 @@ Module containing customisations to the Python Social Auth pipeline. See https://python-social-auth.readthedocs.io/en/latest/ """ +from django.core.mail import mail_admins + + from social_core.pipeline.user import create_user @@ -22,3 +25,14 @@ def create_user_disabled(strategy, details, backend, user=None, *args, **kwargs) django_user.save() return result + + +def email_admins(strategy, details, backend, user=None, *args, **kwargs): + """ + Email the PEDASI admins if a new account has been created and requires approval + """ + if kwargs['is_new']: + mail_admins( + subject='PEDASI Account Created', + message='User account created' + )