Skip to content
Snippets Groups Projects
Commit 42348ef0 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts] patch: on godfather validation, activate supervisee account and...

[accounts] patch: on godfather validation, activate supervisee account and send confirmation email to supervisee
parent 9ac65966
No related branches found
No related tags found
1 merge request!224Security accounts
Pipeline #
......@@ -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)
......
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>
Account successfully activated - Supervision Confirmed
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment