Commit 66797bb29a7ddeef38e91b9640759ddbd5e82417
Committed by
Sergio Oliveira
1 parent
2d26e024
Exists in
master
and in
39 other branches
Added validation of user creation via email
Showing
3 changed files
with
19 additions
and
3 deletions
Show diff stats
colab/accounts/views.py
| ... | ... | @@ -20,7 +20,7 @@ from conversejs import xmpp |
| 20 | 20 | from conversejs.models import XMPPAccount |
| 21 | 21 | from haystack.query import SearchQuerySet |
| 22 | 22 | |
| 23 | -from colab.super_archives.models import EmailAddress, Message | |
| 23 | +from colab.super_archives.models import EmailAddress, Message, EmailAddressValidation | |
| 24 | 24 | from colab.search.utils import trans |
| 25 | 25 | # from proxy.trac.models import WikiCollabCount, TicketCollabCount |
| 26 | 26 | from .forms import (UserCreationForm, ListsForm, UserUpdateForm, |
| ... | ... | @@ -160,6 +160,10 @@ def signup(request): |
| 160 | 160 | |
| 161 | 161 | user = user_form.save(commit=False) |
| 162 | 162 | user.needs_update = False |
| 163 | + if not browser_id: | |
| 164 | + user.is_active = False | |
| 165 | + EmailAddressValidation.create(user.email, user) | |
| 166 | + | |
| 163 | 167 | user.save() |
| 164 | 168 | |
| 165 | 169 | # Check if the user's email have been used previously | ... | ... |
colab/super_archives/models.py
| ... | ... | @@ -17,7 +17,7 @@ from taggit.managers import TaggableManager |
| 17 | 17 | from hitcounter.models import HitCounterModelMixin |
| 18 | 18 | |
| 19 | 19 | from .managers import NotSpamManager, MostVotedManager, HighestScore |
| 20 | -from .utils import blocks | |
| 20 | +from .utils import blocks, email | |
| 21 | 21 | from .utils.etiquetador import etiquetador |
| 22 | 22 | |
| 23 | 23 | |
| ... | ... | @@ -36,6 +36,13 @@ class EmailAddressValidation(models.Model): |
| 36 | 36 | class Meta: |
| 37 | 37 | unique_together = ('user', 'address') |
| 38 | 38 | |
| 39 | + @classmethod | |
| 40 | + def create(cls, address, user): | |
| 41 | + email_address_validation = cls.objects.create(address=address, user=user) | |
| 42 | + email.send_verification_email(email_address_validation.address, | |
| 43 | + email_address_validation.user, | |
| 44 | + email_address_validation.validation_key) | |
| 45 | + return email_address_validation | |
| 39 | 46 | |
| 40 | 47 | class EmailAddress(models.Model): |
| 41 | 48 | user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, | ... | ... |
colab/super_archives/views.py
| ... | ... | @@ -21,6 +21,7 @@ from django.shortcuts import render, redirect, get_object_or_404 |
| 21 | 21 | from haystack.query import SearchQuerySet |
| 22 | 22 | |
| 23 | 23 | from colab.accounts.utils import mailman |
| 24 | +from colab.accounts.models import User | |
| 24 | 25 | from .utils.email import send_verification_email |
| 25 | 26 | from .models import MailingList, Thread, EmailAddress, \ |
| 26 | 27 | EmailAddressValidation, Message |
| ... | ... | @@ -159,7 +160,7 @@ class EmailView(View): |
| 159 | 160 | except EmailAddress.DoesNotExist: |
| 160 | 161 | email = EmailAddress(address=email_val.address) |
| 161 | 162 | |
| 162 | - if email.user: | |
| 163 | + if email.user and email.user.is_active: | |
| 163 | 164 | messages.error(request, _('The email address you are trying to ' |
| 164 | 165 | 'verify is already an active email ' |
| 165 | 166 | 'address.')) |
| ... | ... | @@ -169,6 +170,10 @@ class EmailView(View): |
| 169 | 170 | email.user = email_val.user |
| 170 | 171 | email.save() |
| 171 | 172 | email_val.delete() |
| 173 | + | |
| 174 | + user = User.objects.get(username=email.user.username) | |
| 175 | + user.is_active = True | |
| 176 | + user.save() | |
| 172 | 177 | |
| 173 | 178 | messages.success(request, _('Email address verified!')) |
| 174 | 179 | return redirect('user_profile', username=email_val.user.username) | ... | ... |