Commit 2ecbbc70 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

notify administrator by email when an inactive account is created

Ref: #2116
parent db7fecd9
......@@ -50,6 +50,7 @@ ASTAKOS_DEFAULT_USER_LEVEL 4
ASTAKOS_INVITATIONS_PER_LEVEL {0:100, 1:2, 2:0, 3:0, 4:0} Number of user invitations per user level
ASTAKOS_DEFAULT_FROM_EMAIL GRNET Cloud <no-reply\@grnet.gr> ``from`` parameter passed in ``django.core.mail.send_mail``
ASTAKOS_DEFAULT_CONTACT_EMAIL support\@cloud.grnet.gr Contact email
ASTAKOS_DEFAULT_ADMIN_EMAIL support\@cloud.grnet.gr Administrator email to receive user creation notifications
ASTAKOS_IM_MODULES ['local', 'twitter', 'shibboleth'] Signup modules
ASTAKOS_FORCE_PROFILE_UPDATE True Force user profile verification
ASTAKOS_INVITATIONS_ENABLED True Enable invitations
......
......@@ -48,7 +48,7 @@ from urlparse import urljoin
from astakos.im.models import AstakosUser, Invitation
from astakos.im.forms import *
from astakos.im.util import get_invitation
from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, MODERATION_ENABLED, SITENAME, BASEURL
from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, MODERATION_ENABLED, SITENAME, BASEURL, DEFAULT_ADMIN_EMAIL
import socket
import logging
......@@ -143,7 +143,7 @@ class InvitationsBackend(object):
return False
@transaction.commit_manually
def signup(self, form):
def signup(self, form, admin_email_template_name='im/admin_notification.txt'):
"""
Initially creates an inactive user account. If the user is preaccepted
(has a valid invitation code) the user is activated and if the request
......@@ -161,6 +161,7 @@ class InvitationsBackend(object):
user.save()
message = _('Registration completed. You can now login.')
else:
_send_notification(user, admin_email_template_name)
message = _('Registration completed. You will receive an email upon your account\'s activation.')
status = messages.SUCCESS
except Invitation.DoesNotExist, e:
......@@ -201,7 +202,7 @@ class SimpleBackend(object):
return globals()[formclass](initial_data, ip=self.request.META['REMOTE_ADDR'])
@transaction.commit_manually
def signup(self, form, email_template_name='im/activation_email.txt'):
def signup(self, form, email_template_name='im/activation_email.txt', admin_email_template_name='im/admin_notification.txt'):
"""
Creates an inactive user account and sends a verification email.
......@@ -226,7 +227,13 @@ class SimpleBackend(object):
user = form.save()
status = messages.SUCCESS
if MODERATION_ENABLED:
message = _('Registration completed. You will receive an email upon your account\'s activation.')
try:
_send_notification(user, admin_email_template_name)
message = _('Registration completed. You will receive an email upon your account\'s activation.')
except (SMTPException, socket.error) as e:
status = messages.ERROR
name = 'strerror'
message = getattr(e, name) if hasattr(e, name) else e
else:
try:
_send_verification(self.request, user, email_template_name)
......@@ -256,3 +263,13 @@ def _send_verification(request, user, template_name):
sender = DEFAULT_FROM_EMAIL
send_mail('%s account activation' % SITENAME, message, sender, [user.email])
logger.info('Sent activation %s', user)
def _send_notification(user, template_name):
message = render_to_string(template_name, {
'user': user,
'baseurl': BASEURL,
'site_name': SITENAME,
'support': DEFAULT_CONTACT_EMAIL})
sender = DEFAULT_FROM_EMAIL
send_mail('%s account notification' % SITENAME, message, sender, [DEFAULT_ADMIN_EMAIL])
logger.info('Sent admin notification for user %s', user)
......@@ -21,6 +21,7 @@ INVITATIONS_PER_LEVEL = getattr(settings, 'ASTAKOS_INVITATIONS_PER_LEVEL', {
# Address to use for outgoing emails
DEFAULT_FROM_EMAIL = getattr(settings, 'ASTAKOS_DEFAULT_FROM_EMAIL', 'GRNET Cloud <no-reply@grnet.gr>')
DEFAULT_CONTACT_EMAIL = getattr(settings, 'ASTAKOS_DEFAULT_CONTACT_EMAIL', 'support@cloud.grnet.gr')
DEFAULT_ADMIN_EMAIL = getattr(settings, 'ASTAKOS_DEFAULT_ADMIN_EMAIL', 'support@cloud.grnet.gr')
# Identity Management enabled modules
IM_MODULES = getattr(settings, 'ASTAKOS_IM_MODULES', ['local', 'twitter', 'shibboleth'])
......
--- A translation in English follows ---
Έχει δημιουργηθεί ο παρακάτω λογαριασμός:
Email: {{user.email}}
First name: {{user.first_name}}
Last name: {{user.last_name}}
Is active: {{user.is_active}}
Level: {{user.level}}
Invitations: {{user.invitations}}
Για την ενεργοποίησή του μπορείτε να χρησιμοποιήσετε το command line εργαλείο snf-manage activateuser
--
The following account has been created:
Email: {{user.email}}
First name: {{user.first_name}}
Last name: {{user.last_name}}
Is active: {{user.is_active}}
Level: {{user.level}}
Invitations: {{user.invitations}}
Fot its activation you can use the command line tool snf-manage activateuser
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment