Commit 37c091d61194a53562a250a2f8324791075c5474
1 parent
721677c8
Exists in
master
and in
28 other branches
Fixed way to build verification url
Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Macartur Souza <macartur.sc@gmail.com> Signed-off-by: Sergio Oliveira <seocam@gmail.com>
Showing
5 changed files
with
23 additions
and
10 deletions
Show diff stats
colab/accounts/views.py
@@ -103,7 +103,12 @@ def signup(request): | @@ -103,7 +103,12 @@ def signup(request): | ||
103 | 103 | ||
104 | user.is_active = False | 104 | user.is_active = False |
105 | user.save() | 105 | user.save() |
106 | - EmailAddressValidation.create(user.email, user) | 106 | + email = EmailAddressValidation.create(user.email, user) |
107 | + | ||
108 | + location = reverse('archive_email_view', | ||
109 | + kwargs={'key': email.validation_key}) | ||
110 | + verification_url = request.build_absolute_uri(location) | ||
111 | + EmailAddressValidation.verify_email(email, verification_url) | ||
107 | 112 | ||
108 | # Check if the user's email have been used previously | 113 | # Check if the user's email have been used previously |
109 | # in the mainling lists to link the user to old messages | 114 | # in the mainling lists to link the user to old messages |
colab/super_archives/models.py
@@ -41,10 +41,14 @@ class EmailAddressValidation(models.Model): | @@ -41,10 +41,14 @@ class EmailAddressValidation(models.Model): | ||
41 | def create(cls, address, user): | 41 | def create(cls, address, user): |
42 | email_address_validation = cls.objects.create(address=address, | 42 | email_address_validation = cls.objects.create(address=address, |
43 | user=user) | 43 | user=user) |
44 | + return email_address_validation | ||
45 | + | ||
46 | + @classmethod | ||
47 | + def verify_email(cls, email_address_validation, verification_url): | ||
44 | email.send_verification_email(email_address_validation.address, | 48 | email.send_verification_email(email_address_validation.address, |
45 | email_address_validation.user, | 49 | email_address_validation.user, |
46 | - email_address_validation.validation_key) | ||
47 | - return email_address_validation | 50 | + email_address_validation.validation_key, |
51 | + verification_url) | ||
48 | 52 | ||
49 | 53 | ||
50 | class EmailAddress(models.Model): | 54 | class EmailAddress(models.Model): |
colab/super_archives/templates/superarchives/emails/email_verification.txt
1 | {% load i18n %} | 1 | {% load i18n %} |
2 | {% blocktrans with fullname=user.get_full_name|title username=user.username|lower %}Hey, we want to verify that you are indeed "{{ fullname }} ({{ username }})". If that's the case, please follow the link below:{% endblocktrans %} | 2 | {% blocktrans with fullname=user.get_full_name|title username=user.username|lower %}Hey, we want to verify that you are indeed "{{ fullname }} ({{ username }})". If that's the case, please follow the link below:{% endblocktrans %} |
3 | 3 | ||
4 | -{{ SITE_URL }}{% url 'archive_email_view' key %} | 4 | +{{ verification_url }} |
5 | 5 | ||
6 | {% blocktrans with username=user.username %}If you're not {{ username }} or didn't request verification you can ignore this email.{% endblocktrans %} | 6 | {% blocktrans with username=user.username %}If you're not {{ username }} or didn't request verification you can ignore this email.{% endblocktrans %} |
colab/super_archives/utils/email.py
@@ -10,11 +10,11 @@ def colab_send_email(subject, message, to): | @@ -10,11 +10,11 @@ def colab_send_email(subject, message, to): | ||
10 | return mail.send_mail(subject, message, from_email, [to]) | 10 | return mail.send_mail(subject, message, from_email, [to]) |
11 | 11 | ||
12 | 12 | ||
13 | -def send_verification_email(to, user, validation_key): | 13 | +def send_verification_email(to, user, validation_key, verification_url): |
14 | subject = _('Please verify your email ') + u'{}'.format(to) | 14 | subject = _('Please verify your email ') + u'{}'.format(to) |
15 | msg_tmpl = \ | 15 | msg_tmpl = \ |
16 | loader.get_template('superarchives/emails/email_verification.txt') | 16 | loader.get_template('superarchives/emails/email_verification.txt') |
17 | message = msg_tmpl.render(Context({'to': to, 'user': user, | 17 | message = msg_tmpl.render(Context({'to': to, 'user': user, |
18 | - 'key': validation_key, | ||
19 | - 'SITE_URL': settings.SITE_URL})) | 18 | + 'verification_url': verification_url |
19 | + })) | ||
20 | return colab_send_email(subject, message, to) | 20 | return colab_send_email(subject, message, to) |
colab/super_archives/views.py
@@ -9,6 +9,7 @@ import requests | @@ -9,6 +9,7 @@ import requests | ||
9 | from django import http | 9 | from django import http |
10 | from django.conf import settings | 10 | from django.conf import settings |
11 | from django.contrib import messages | 11 | from django.contrib import messages |
12 | +from django.core.urlresolvers import reverse | ||
12 | from django.db import IntegrityError | 13 | from django.db import IntegrityError |
13 | from django.views.generic import View | 14 | from django.views.generic import View |
14 | from django.utils.translation import ugettext as _ | 15 | from django.utils.translation import ugettext as _ |
@@ -177,7 +178,7 @@ class EmailView(View): | @@ -177,7 +178,7 @@ class EmailView(View): | ||
177 | except EmailAddressValidation.DoesNotExist: | 178 | except EmailAddressValidation.DoesNotExist: |
178 | messages.error(request, _('The email address you are trying to ' | 179 | messages.error(request, _('The email address you are trying to ' |
179 | 'verify either has already been verified' | 180 | 'verify either has already been verified' |
180 | - 'or does not exist.')) | 181 | + ' or does not exist.')) |
181 | return redirect('/') | 182 | return redirect('/') |
182 | 183 | ||
183 | try: | 184 | try: |
@@ -289,8 +290,11 @@ class EmailValidationView(View): | @@ -289,8 +290,11 @@ class EmailValidationView(View): | ||
289 | raise http.Http404 | 290 | raise http.Http404 |
290 | 291 | ||
291 | try: | 292 | try: |
292 | - send_verification_email(email_addr, email.user, | ||
293 | - email.validation_key) | 293 | + location = reverse('archive_email_view', |
294 | + kwargs={'key': email.validation_key}) | ||
295 | + verification_url = request.build_absolute_uri(location) | ||
296 | + send_verification_email(request, email_addr, email.user, | ||
297 | + email.validation_key, verification_url) | ||
294 | except smtplib.SMTPException: | 298 | except smtplib.SMTPException: |
295 | logging.exception('Error sending validation email') | 299 | logging.exception('Error sending validation email') |
296 | return http.HttpResponseServerError() | 300 | return http.HttpResponseServerError() |