Skip to content
Snippets Groups Projects
Commit 90c9cc2f authored by James Graham's avatar James Graham
Browse files

Add admin email to account creation process - see #65

Need to add admin email addresses to settings
parent c3757f5f
Branches
Tags
No related merge requests found
...@@ -243,6 +243,9 @@ SOCIAL_AUTH_PIPELINE = [ ...@@ -243,6 +243,9 @@ SOCIAL_AUTH_PIPELINE = [
# Update the user record with any changed info from the auth service. # Update the user record with any changed info from the auth service.
'social_core.pipeline.user.user_details', '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') SOCIAL_AUTH_LOGIN_REDIRECT_URL = reverse_lazy('index')
...@@ -310,3 +313,18 @@ STATICFILES_DIRS = [ ...@@ -310,3 +313,18 @@ STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'pedasi', 'static'), os.path.join(BASE_DIR, 'pedasi', 'static'),
os.path.join(BASE_DIR, 'docs', 'build'), 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')
...@@ -4,6 +4,9 @@ Module containing customisations to the Python Social Auth pipeline. ...@@ -4,6 +4,9 @@ Module containing customisations to the Python Social Auth pipeline.
See https://python-social-auth.readthedocs.io/en/latest/ See https://python-social-auth.readthedocs.io/en/latest/
""" """
from django.core.mail import mail_admins
from social_core.pipeline.user import create_user from social_core.pipeline.user import create_user
...@@ -22,3 +25,14 @@ def create_user_disabled(strategy, details, backend, user=None, *args, **kwargs) ...@@ -22,3 +25,14 @@ def create_user_disabled(strategy, details, backend, user=None, *args, **kwargs)
django_user.save() django_user.save()
return result 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'
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment