msg = 'Sent admin notification for user %s' % user.email
logger._log(LOGGING_LEVEL, msg, [])
+def send_helpdesk_notification(user, template_name='im/helpdesk_notification.txt'):
+ """
+ Send email to DEFAULT_CONTACT_EMAIL to notify for a new user activation.
+
+ Raises SendNotificationError
+ """
+ if not DEFAULT_CONTACT_EMAIL:
+ return
+ message = render_to_string(template_name, {
+ 'user': user,
+ 'baseurl': BASEURL,
+ 'site_name': SITENAME,
+ 'support': DEFAULT_ADMIN_EMAIL})
+ sender = DEFAULT_FROM_EMAIL
+ try:
+ send_mail('%s alpha2 testing account notification' % SITENAME, message, sender, [DEFAULT_CONTACT_EMAIL])
+ except (SMTPException, socket.error) as e:
+ logger.exception(e)
+ raise SendNotificationError()
+ else:
+ msg = 'Sent helpdesk admin notification for user %s' % user.email
+ logger._log(LOGGING_LEVEL, msg, [])
+
def send_invitation(invitation, template_name='im/invitation.txt'):
"""
Send invitation email.
def __init__(self):
self.message = _('Failed to send change email')
super(ChangeEmailError, self).__init__()
+
+class SendNotificationError(SendMailError):
+ def __init__(self):
+ self.message = _('Failed to send notification email')
+ super(SendNotificationError, self).__init__()
--- /dev/null
+--- 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}}
+
+--
+
+The following account has been activated:
+
+Email: {{user.email}}
+First name: {{user.first_name}}
+Last name: {{user.last_name}}
+Is active: {{user.is_active}}
+Level: {{user.level}}
+Invitations: {{user.invitations}}
\ No newline at end of file
from astakos.im.util import get_context, prepare_response, set_cookie, get_query
from astakos.im.forms import *
from astakos.im.functions import send_greeting, send_feedback, SendMailError, \
- invite as invite_func, logout as auth_logout
+ invite as invite_func, logout as auth_logout, send_helpdesk_notification
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, COOKIE_NAME, COOKIE_DOMAIN, IM_MODULES, SITENAME, LOGOUT_NEXT, LOGGING_LEVEL
logger = logging.getLogger(__name__)
return response
@transaction.commit_manually
-def activate(request, email_template_name='im/welcome_email.txt', on_failure='im/signup.html'):
+def activate(request, email_template_name='im/welcome_email.txt', on_failure='im/signup.html',
+ helpdesk_email_template_name='im/helpdesk_notification.txt'):
"""
Activates the user identified by the ``auth`` request parameter, sends a welcome email
and renews the user token.
messages.add_message(request, messages.ERROR, message)
return render_response(on_failure)
+ notify_helpdesk = False
try:
local_user = AstakosUser.objects.get(~Q(id = user.id), email=user.email, is_active=True)
except AstakosUser.DoesNotExist:
user.save()
except ValidationError, e:
return HttpResponseBadRequest(e)
+ notify_helpdesk = True
else:
# switch the existing account to shibboleth one
if user.provider == 'shibboleth':
user = local_user
try:
+ if notify_helpdesk:
+ send_helpdesk_notification(user, helpdesk_email_template_name)
send_greeting(user, email_template_name)
response = prepare_response(request, user, next, renew=True)
transaction.commit()