Commit 9f4aa9bfaa00c0a552111047a025a0372c43f574
1 parent
5dce065517
Exists in
master
Added FlashcardReport and WhitelistedAddress to support use cases\nRegistration …
…now actually sends an email
Showing 2 changed files with 29 additions and 5 deletions Side-by-side Diff
flashcards/api.py
View file @
9f4aa9b
... | ... | @@ -18,13 +18,13 @@ |
18 | 18 | is valid. |
19 | 19 | |
20 | 20 | """ |
21 | - currentuser = request.user | |
21 | + currentuser = request.user | |
22 | 22 | |
23 | 23 | if 'confirmation_key' in request.data: |
24 | - if not currentuser.confirm_email( request.data['confirmation_key'] ): | |
24 | + if not currentuser.confirm_email(request.data['confirmation_key']): | |
25 | 25 | raise ValidationError('confirmation_key is invalid') |
26 | 26 | |
27 | - if 'new_password' in request.data: | |
27 | + if 'new_password' in request.data: | |
28 | 28 | if not currentuser.check_password(request.data['old_password']): |
29 | 29 | raise ValidationError('Invalid old password') |
30 | 30 | if not request.data['new_password']: |
... | ... | @@ -55,6 +55,10 @@ |
55 | 55 | |
56 | 56 | If you did not register for Flashy, no action is required. |
57 | 57 | ''' |
58 | + send_mail("Flashy email verification", | |
59 | + body % (user.pk, user.confirmation_key), | |
60 | + "noreply@flashy.cards", | |
61 | + [user.email]) | |
58 | 62 | |
59 | 63 | user = authenticate(email=email, password=request.data['password']) |
60 | 64 | login(request, user) |
... | ... | @@ -90,6 +94,7 @@ |
90 | 94 | raise ValidationError('Account is disabled') |
91 | 95 | login(request, user) |
92 | 96 | return Response(UserSerializer(user).data) |
97 | + | |
93 | 98 | |
94 | 99 | class UserLogout(APIView): |
95 | 100 | """ |
flashcards/models.py
View file @
9f4aa9b
1 | -from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin, AbstractUser | |
1 | +from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, AbstractUser | |
2 | 2 | from django.db.models import * |
3 | 3 | from simple_email_confirmation import SimpleEmailConfirmationUserMixin |
4 | 4 | |
5 | 5 | # Hack to fix AbstractUser before subclassing it |
6 | 6 | AbstractUser._meta.get_field('email')._unique = True |
7 | 7 | |
8 | + | |
8 | 9 | class User(AbstractUser, SimpleEmailConfirmationUserMixin, ): |
9 | 10 | USERNAME_FIELD = 'email' |
10 | 11 | REQUIRED_FIELDS = [] |
... | ... | @@ -126,6 +127,7 @@ |
126 | 127 | course_title = CharField(max_length=50) |
127 | 128 | instructor = CharField(max_length=50) |
128 | 129 | quarter = CharField(max_length=4) |
130 | + whitelist = ManyToManyField(User, related_name="whitelisted_sections") | |
129 | 131 | |
130 | 132 | class Meta: |
131 | 133 | unique_together = (('department', 'course_num', 'quarter', 'instructor'),) |
... | ... | @@ -140,4 +142,21 @@ |
140 | 142 | week_day = IntegerField(help_text="0-indexed day of week, starting at Monday") |
141 | 143 | start_time = TimeField() |
142 | 144 | end_time = TimeField() |
145 | + | |
146 | + class Meta: | |
147 | + unique_together = (('section', 'start_time', 'week_day'),) | |
148 | + | |
149 | + | |
150 | +class WhitelistedAddress(Model): | |
151 | + email = EmailField() | |
152 | + section = ForeignKey(Section) | |
153 | + | |
154 | + | |
155 | +class FlashcardReport(Model): | |
156 | + user = ForeignKey(User) | |
157 | + flashcard = ForeignKey(Flashcard) | |
158 | + reason = CharField(max_length=255) | |
159 | + | |
160 | + class Meta: | |
161 | + unique_together = (('user', 'flashcard'),) |