Commit 7a17fac38ec351f93f4a1144abeefedd92874620
1 parent
01eeffc6fd
Exists in
master
add view to resend confirmation email
Showing 3 changed files with 21 additions and 11 deletions Side-by-side Diff
flashcards/models.py
View file @
7a17fac
... | ... | @@ -20,6 +20,8 @@ |
20 | 20 | |
21 | 21 | |
22 | 22 | |
23 | + | |
24 | + | |
23 | 25 | # Hack to fix AbstractUser before subclassing it |
24 | 26 | |
25 | 27 | AbstractUser._meta.get_field('email')._unique = True |
26 | 28 | |
27 | 29 | |
... | ... | @@ -43,21 +45,12 @@ |
43 | 45 | date_joined=now(), **extra_fields) |
44 | 46 | user.set_password(password) |
45 | 47 | user.save(using=self._db) |
48 | + user.send_confirmation_email() | |
46 | 49 | return user |
47 | 50 | |
48 | 51 | def create_user(self, email, password=None, **extra_fields): |
49 | 52 | user = self._create_user(email, password, False, False, **extra_fields) |
50 | - body = ''' | |
51 | - Visit the following link to confirm your email address: | |
52 | - https://flashy.cards/app/verifyemail/%s | |
53 | 53 | |
54 | - If you did not register for Flashy, no action is required. | |
55 | - ''' | |
56 | - | |
57 | - assert send_mail("Flashy email verification", | |
58 | - body % user.confirmation_key, | |
59 | - "noreply@flashy.cards", | |
60 | - [user.email]) | |
61 | 54 | return user |
62 | 55 | |
63 | 56 | def create_superuser(self, email, password, **extra_fields): |
... | ... | @@ -82,6 +75,15 @@ |
82 | 75 | REQUIRED_FIELDS = [] |
83 | 76 | sections = ManyToManyField('Section', help_text="The sections which the user is enrolled in") |
84 | 77 | confirmed_email = BooleanField(default=False) |
78 | + | |
79 | + def send_confirmation_email(self): | |
80 | + body = ''' | |
81 | + Visit the following link to confirm your email address: | |
82 | + https://flashy.cards/app/verifyemail/%s | |
83 | + | |
84 | + If you did not register for Flashy, no action is required. | |
85 | + ''' | |
86 | + send_mail("Flashy email verification", body % self.confirmation_key, "noreply@flashy.cards", [self.email]) | |
85 | 87 | |
86 | 88 | def is_in_section(self, section): |
87 | 89 | return self.sections.filter(pk=section.pk).exists() |
flashcards/views.py
View file @
7a17fac
... | ... | @@ -189,6 +189,13 @@ |
189 | 189 | return Response(status=HTTP_204_NO_CONTENT) |
190 | 190 | |
191 | 191 | |
192 | + | |
193 | +@api_view(['POST']) | |
194 | +@permission_classes([IsAuthenticated]) | |
195 | +def resend_confirmation_email(request): | |
196 | + request.user.send_confirmation_email() | |
197 | + return Response(status=HTTP_204_NO_CONTENT) | |
198 | + | |
192 | 199 | @api_view(['POST']) |
193 | 200 | def register(request, format=None): |
194 | 201 | """ |
flashy/urls.py
View file @
7a17fac
1 | 1 | from django.conf.urls import include, url |
2 | 2 | from django.contrib import admin |
3 | 3 | from flashcards.views import SectionViewSet, UserDetail, FlashcardViewSet, UserSectionListView, request_password_reset, \ |
4 | - reset_password, logout, login, register, UserFlashcardQuizViewSet | |
4 | + reset_password, logout, login, register, UserFlashcardQuizViewSet, resend_confirmation_email | |
5 | 5 | from flashy.frontend_serve import serve_with_default |
6 | 6 | from flashy.settings import DEBUG, IN_PRODUCTION |
7 | 7 | from rest_framework.routers import DefaultRouter |
... | ... | @@ -19,6 +19,7 @@ |
19 | 19 | url(r'^api/login/$', login), |
20 | 20 | url(r'^api/logout/$', logout), |
21 | 21 | url(r'^api/me/sections/', UserSectionListView.as_view()), |
22 | + url(r'^api/resend_confirmation_email/', resend_confirmation_email), | |
22 | 23 | url(r'^api/request_password_reset/', request_password_reset), |
23 | 24 | url(r'^api/reset_password/', reset_password), |
24 | 25 | url(r'^api/', include(router.urls)), |