Commit 85cc285de1fa9b7bbddafedef2e212e674aa9244
Exists in
master
and in
28 other branches
Merge branch 'fix_verification_url' into 'master'
Obtendo domínio a partir da requisição De acordo com o relatado na issue #107, havia um problema com a necessidade da configuração da variável SITE_URL. Agora o domínio é obtido através da própria requisição. See merge request !91
Showing
5 changed files
with
26 additions
and
11 deletions
Show diff stats
colab/accounts/views.py
| ... | ... | @@ -103,7 +103,12 @@ def signup(request): |
| 103 | 103 | |
| 104 | 104 | user.is_active = False |
| 105 | 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 | 113 | # Check if the user's email have been used previously |
| 109 | 114 | # in the mainling lists to link the user to old messages | ... | ... |
colab/super_archives/models.py
| ... | ... | @@ -41,11 +41,17 @@ class EmailAddressValidation(models.Model): |
| 41 | 41 | def create(cls, address, user): |
| 42 | 42 | email_address_validation = cls.objects.create(address=address, |
| 43 | 43 | user=user) |
| 44 | - email.send_verification_email(email_address_validation.address, | |
| 45 | - email_address_validation.user, | |
| 46 | - email_address_validation.validation_key) | |
| 47 | 44 | return email_address_validation |
| 48 | 45 | |
| 46 | + @classmethod | |
| 47 | + def verify_email(cls, email_address_validation, verification_url): | |
| 48 | + return email.send_verification_email( | |
| 49 | + email_address_validation.address, | |
| 50 | + email_address_validation.user, | |
| 51 | + email_address_validation.validation_key, | |
| 52 | + verification_url | |
| 53 | + ) | |
| 54 | + | |
| 49 | 55 | |
| 50 | 56 | class EmailAddress(models.Model): |
| 51 | 57 | user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, | ... | ... |
colab/super_archives/templates/superarchives/emails/email_verification.txt
| 1 | 1 | {% load i18n %} |
| 2 | 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 | 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 | 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 | 14 | subject = _('Please verify your email ') + u'{}'.format(to) |
| 15 | 15 | msg_tmpl = \ |
| 16 | 16 | loader.get_template('superarchives/emails/email_verification.txt') |
| 17 | 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 | 20 | return colab_send_email(subject, message, to) | ... | ... |
colab/super_archives/views.py
| ... | ... | @@ -9,6 +9,7 @@ import requests |
| 9 | 9 | from django import http |
| 10 | 10 | from django.conf import settings |
| 11 | 11 | from django.contrib import messages |
| 12 | +from django.core.urlresolvers import reverse | |
| 12 | 13 | from django.db import IntegrityError |
| 13 | 14 | from django.views.generic import View |
| 14 | 15 | from django.utils.translation import ugettext as _ |
| ... | ... | @@ -177,7 +178,7 @@ class EmailView(View): |
| 177 | 178 | except EmailAddressValidation.DoesNotExist: |
| 178 | 179 | messages.error(request, _('The email address you are trying to ' |
| 179 | 180 | 'verify either has already been verified' |
| 180 | - 'or does not exist.')) | |
| 181 | + ' or does not exist.')) | |
| 181 | 182 | return redirect('/') |
| 182 | 183 | |
| 183 | 184 | try: |
| ... | ... | @@ -289,8 +290,11 @@ class EmailValidationView(View): |
| 289 | 290 | raise http.Http404 |
| 290 | 291 | |
| 291 | 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 | 298 | except smtplib.SMTPException: |
| 295 | 299 | logging.exception('Error sending validation email') |
| 296 | 300 | return http.HttpResponseServerError() | ... | ... |