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,7 +20,7 @@ from conversejs import xmpp | ||
20 | from conversejs.models import XMPPAccount | 20 | from conversejs.models import XMPPAccount |
21 | from haystack.query import SearchQuerySet | 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 | from colab.search.utils import trans | 24 | from colab.search.utils import trans |
25 | # from proxy.trac.models import WikiCollabCount, TicketCollabCount | 25 | # from proxy.trac.models import WikiCollabCount, TicketCollabCount |
26 | from .forms import (UserCreationForm, ListsForm, UserUpdateForm, | 26 | from .forms import (UserCreationForm, ListsForm, UserUpdateForm, |
@@ -160,6 +160,10 @@ def signup(request): | @@ -160,6 +160,10 @@ def signup(request): | ||
160 | 160 | ||
161 | user = user_form.save(commit=False) | 161 | user = user_form.save(commit=False) |
162 | user.needs_update = False | 162 | user.needs_update = False |
163 | + if not browser_id: | ||
164 | + user.is_active = False | ||
165 | + EmailAddressValidation.create(user.email, user) | ||
166 | + | ||
163 | user.save() | 167 | user.save() |
164 | 168 | ||
165 | # Check if the user's email have been used previously | 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,7 +17,7 @@ from taggit.managers import TaggableManager | ||
17 | from hitcounter.models import HitCounterModelMixin | 17 | from hitcounter.models import HitCounterModelMixin |
18 | 18 | ||
19 | from .managers import NotSpamManager, MostVotedManager, HighestScore | 19 | from .managers import NotSpamManager, MostVotedManager, HighestScore |
20 | -from .utils import blocks | 20 | +from .utils import blocks, email |
21 | from .utils.etiquetador import etiquetador | 21 | from .utils.etiquetador import etiquetador |
22 | 22 | ||
23 | 23 | ||
@@ -36,6 +36,13 @@ class EmailAddressValidation(models.Model): | @@ -36,6 +36,13 @@ class EmailAddressValidation(models.Model): | ||
36 | class Meta: | 36 | class Meta: |
37 | unique_together = ('user', 'address') | 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 | class EmailAddress(models.Model): | 47 | class EmailAddress(models.Model): |
41 | user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, | 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,6 +21,7 @@ from django.shortcuts import render, redirect, get_object_or_404 | ||
21 | from haystack.query import SearchQuerySet | 21 | from haystack.query import SearchQuerySet |
22 | 22 | ||
23 | from colab.accounts.utils import mailman | 23 | from colab.accounts.utils import mailman |
24 | +from colab.accounts.models import User | ||
24 | from .utils.email import send_verification_email | 25 | from .utils.email import send_verification_email |
25 | from .models import MailingList, Thread, EmailAddress, \ | 26 | from .models import MailingList, Thread, EmailAddress, \ |
26 | EmailAddressValidation, Message | 27 | EmailAddressValidation, Message |
@@ -159,7 +160,7 @@ class EmailView(View): | @@ -159,7 +160,7 @@ class EmailView(View): | ||
159 | except EmailAddress.DoesNotExist: | 160 | except EmailAddress.DoesNotExist: |
160 | email = EmailAddress(address=email_val.address) | 161 | email = EmailAddress(address=email_val.address) |
161 | 162 | ||
162 | - if email.user: | 163 | + if email.user and email.user.is_active: |
163 | messages.error(request, _('The email address you are trying to ' | 164 | messages.error(request, _('The email address you are trying to ' |
164 | 'verify is already an active email ' | 165 | 'verify is already an active email ' |
165 | 'address.')) | 166 | 'address.')) |
@@ -169,6 +170,10 @@ class EmailView(View): | @@ -169,6 +170,10 @@ class EmailView(View): | ||
169 | email.user = email_val.user | 170 | email.user = email_val.user |
170 | email.save() | 171 | email.save() |
171 | email_val.delete() | 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 | messages.success(request, _('Email address verified!')) | 178 | messages.success(request, _('Email address verified!')) |
174 | return redirect('user_profile', username=email_val.user.username) | 179 | return redirect('user_profile', username=email_val.user.username) |