diff --git a/beat/web/accounts/api.py b/beat/web/accounts/api.py index fca48e6175dcaefa4b561acde91f8b9cb315d717..ae449df7874ad00a24e2644340dd8eb8dc358b73 100644 --- a/beat/web/accounts/api.py +++ b/beat/web/accounts/api.py @@ -32,6 +32,8 @@ from django.http import Http404 from django.db import models from django.db.models import Q from django.core.urlresolvers import reverse +from django.template import loader +from django.template import Context from rest_framework import generics from rest_framework import views @@ -61,6 +63,7 @@ from ..common.responses import BadRequestResponse, ForbiddenResponse import datetime import re +from urlparse import urlparse import simplejson as json @@ -134,7 +137,32 @@ class GodfatherAddSuperviseeView(BaseUpdateSupervisionTrackView): supervisiontrack.save() supervisee.profile.save() + supervisee.is_active = True + supervisee.save() + from django.core.mail import send_mail + + parsed_url = urlparse(settings.URL_PREFIX) + server_address = '%s://%s' % (parsed_url.scheme, parsed_url.hostname) + + c = Context({ 'supervisor': supervisiontrack.godfather, + 'supervisee': supervisee, + 'prefix': server_address, + }) + + try: + t = loader.get_template('registration/mail.godfather_validated.subject.txt') + subject = t.render(c) + + # Note: e-mail subject *must not* contain newlines + subject = settings.EMAIL_SUBJECT_PREFIX + ''.join(subject.splitlines()) + + t = loader.get_template('registration/mail.godfather_validated.message.txt') + message = t.render(c) + + send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [supervisee.email]) + except: + pass return Response(status=status.HTTP_204_NO_CONTENT) diff --git a/beat/web/ui/registration/templates/registration/mail.godfather_validated.message.txt b/beat/web/ui/registration/templates/registration/mail.godfather_validated.message.txt new file mode 100644 index 0000000000000000000000000000000000000000..a791956571bdc87e5c8d2d0d91db9aa1f033d377 --- /dev/null +++ b/beat/web/ui/registration/templates/registration/mail.godfather_validated.message.txt @@ -0,0 +1,8 @@ +Dear {{ supervisee.first_name }}, + +Your account was successfully activated by your supervisor {{ supervisor.username }}. + +Welcome {{ supervisee.username }}, + +You can now <a href="{% url 'login' %}">sign in</a> and start your own +experiments!</p> diff --git a/beat/web/ui/registration/templates/registration/mail.godfather_validated.subject.txt b/beat/web/ui/registration/templates/registration/mail.godfather_validated.subject.txt new file mode 100644 index 0000000000000000000000000000000000000000..af97067a67b3cb9a6a2731e828ffe90391c3558c --- /dev/null +++ b/beat/web/ui/registration/templates/registration/mail.godfather_validated.subject.txt @@ -0,0 +1 @@ +Account successfully activated - Supervision Confirmed