Commit 34a8edc2e1758454dbc46449a65e3dd4c237a692
1 parent
e7a281e866
Exists in
master
ignore effects of unverified users
Showing 3 changed files with 31 additions and 2 deletions Side-by-side Diff
flashcards/fixtures/testusers.json
View file @
34a8edc
flashcards/migrations/0004_user_confirmed_email.py
View file @
34a8edc
1 | +# -*- coding: utf-8 -*- | |
2 | +from __future__ import unicode_literals | |
3 | + | |
4 | +from django.db import models, migrations | |
5 | + | |
6 | + | |
7 | +class Migration(migrations.Migration): | |
8 | + | |
9 | + dependencies = [ | |
10 | + ('flashcards', '0003_auto_20150521_0203'), | |
11 | + ] | |
12 | + | |
13 | + operations = [ | |
14 | + migrations.AddField( | |
15 | + model_name='user', | |
16 | + name='confirmed_email', | |
17 | + field=models.BooleanField(default=False), | |
18 | + ), | |
19 | + ] |
flashcards/models.py
View file @
34a8edc
1 | 1 | from math import log1p |
2 | 2 | from math import exp |
3 | +import datetime | |
3 | 4 | |
4 | 5 | from django.contrib.auth.models import AbstractUser, UserManager |
5 | 6 | from django.contrib.auth.tokens import default_token_generator |
6 | 7 | |
... | ... | @@ -13,10 +14,10 @@ |
13 | 14 | from simple_email_confirmation import SimpleEmailConfirmationUserMixin |
14 | 15 | from fields import MaskField |
15 | 16 | from cached_property import cached_property |
16 | -import datetime | |
17 | 17 | |
18 | 18 | |
19 | 19 | |
20 | + | |
20 | 21 | # Hack to fix AbstractUser before subclassing it |
21 | 22 | |
22 | 23 | AbstractUser._meta.get_field('email')._unique = True |
... | ... | @@ -70,6 +71,7 @@ |
70 | 71 | USERNAME_FIELD = 'email' |
71 | 72 | REQUIRED_FIELDS = [] |
72 | 73 | sections = ManyToManyField('Section', help_text="The sections which the user is enrolled in") |
74 | + confirmed_email = BooleanField(default=False) | |
73 | 75 | |
74 | 76 | def is_in_section(self, section): |
75 | 77 | return self.sections.filter(pk=section.pk).exists() |
76 | 78 | |
... | ... | @@ -118,7 +120,12 @@ |
118 | 120 | "noreply@flashy.cards", |
119 | 121 | [self.email]) |
120 | 122 | |
123 | + def confirm_email(self, confirmation_key): | |
124 | + # This will raise an exception if the email address is invalid | |
125 | + self.email_address_set.confirm(confirmation_key, save=True) | |
126 | + self.confirmed_email = True | |
121 | 127 | |
128 | + | |
122 | 129 | class UserFlashcard(Model): |
123 | 130 | """ |
124 | 131 | Represents the relationship between a user and a flashcard by: |
... | ... | @@ -250,6 +257,7 @@ |
250 | 257 | epoch = make_aware(datetime.datetime.utcfromtimestamp(0)) |
251 | 258 | delta = dt - epoch |
252 | 259 | return delta.total_seconds() |
260 | + | |
253 | 261 | z = 0 |
254 | 262 | rate = 1.0 / 3600 |
255 | 263 | for vote in self.userflashcard_set.iterator(): |
... | ... | @@ -265,7 +273,8 @@ |
265 | 273 | :param user: |
266 | 274 | :return: A queryset with all cards that should be visible to a user. |
267 | 275 | """ |
268 | - return cls.objects.filter(author__is_active=True).filter(is_hidden=False).exclude(flashcardhide__user=user) | |
276 | + return cls.objects.filter(author__confirmed_email=True).filter(is_hidden=False).exclude( | |
277 | + flashcardhide__user=user) | |
269 | 278 | |
270 | 279 | |
271 | 280 | class UserFlashcardQuiz(Model): |