From 9f4aa9bfaa00c0a552111047a025a0372c43f574 Mon Sep 17 00:00:00 2001
From: Andrew Buss <abuss@ucsd.edu>
Date: Sun, 3 May 2015 23:49:16 -0700
Subject: [PATCH] Added FlashcardReport and WhitelistedAddress to support use
 cases\nRegistration now actually sends an email

---
 flashcards/api.py    | 13 +++++++++----
 flashcards/models.py | 21 ++++++++++++++++++++-
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/flashcards/api.py b/flashcards/api.py
index f7b3a04..1ed91f2 100644
--- a/flashcards/api.py
+++ b/flashcards/api.py
@@ -18,13 +18,13 @@ class UserDetail(APIView):
             is valid.
             
         """
-        currentuser = request.user           
+        currentuser = request.user
 
         if 'confirmation_key' in request.data:
-            if not currentuser.confirm_email( request.data['confirmation_key'] ):
+            if not currentuser.confirm_email(request.data['confirmation_key']):
                 raise ValidationError('confirmation_key is invalid')
 
-        if 'new_password' in request.data:            
+        if 'new_password' in request.data:
             if not currentuser.check_password(request.data['old_password']):
                 raise ValidationError('Invalid old password')
             if not request.data['new_password']:
@@ -55,6 +55,10 @@ class UserDetail(APIView):
 
             If you did not register for Flashy, no action is required.
         '''
+        send_mail("Flashy email verification",
+                  body % (user.pk, user.confirmation_key),
+                  "noreply@flashy.cards",
+                  [user.email])
 
         user = authenticate(email=email, password=request.data['password'])
         login(request, user)
@@ -91,6 +95,7 @@ class UserLogin(APIView):
         login(request, user)
         return Response(UserSerializer(user).data)
 
+
 class UserLogout(APIView):
     """
     Logs out an authenticated user.
@@ -151,4 +156,4 @@ class PasswordReset(APIView):
         user.set_password(request.data['new_password'])
         user.save()
 
-        return Response(status=status.HTTP_204_NO_CONTENT)
+        return Response(status=status.HTTP_204_NO_CONTENT)
\ No newline at end of file
diff --git a/flashcards/models.py b/flashcards/models.py
index fe57d18..b55804a 100644
--- a/flashcards/models.py
+++ b/flashcards/models.py
@@ -1,10 +1,11 @@
-from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin, AbstractUser
+from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, AbstractUser
 from django.db.models import *
 from simple_email_confirmation import SimpleEmailConfirmationUserMixin
 
 # Hack to fix AbstractUser before subclassing it
 AbstractUser._meta.get_field('email')._unique = True
 
+
 class User(AbstractUser, SimpleEmailConfirmationUserMixin, ):
     USERNAME_FIELD = 'email'
     REQUIRED_FIELDS = []
@@ -126,6 +127,7 @@ class Section(Model):
     course_title = CharField(max_length=50)
     instructor = CharField(max_length=50)
     quarter = CharField(max_length=4)
+    whitelist = ManyToManyField(User, related_name="whitelisted_sections")
 
     class Meta:
         unique_together = (('department', 'course_num', 'quarter', 'instructor'),)
@@ -140,3 +142,20 @@ class LecturePeriod(Model):
     week_day = IntegerField(help_text="0-indexed day of week, starting at Monday")
     start_time = TimeField()
     end_time = TimeField()
+
+    class Meta:
+        unique_together = (('section', 'start_time', 'week_day'),)
+
+
+class WhitelistedAddress(Model):
+    email = EmailField()
+    section = ForeignKey(Section)
+
+
+class FlashcardReport(Model):
+    user = ForeignKey(User)
+    flashcard = ForeignKey(Flashcard)
+    reason = CharField(max_length=255)
+
+    class Meta:
+        unique_together = (('user', 'flashcard'),)
\ No newline at end of file
-- 
1.9.1