Commit 93a3554c929f0f1ebdd54545335bac9e619fc3a5
Exists in
master
Merge branch 'master' of git.ucsd.edu:110swag/flashy-backend
Showing 2 changed files Side-by-side Diff
flashcards/api.py
View file @
93a3554
... | ... | @@ -43,8 +43,10 @@ |
43 | 43 | raise ValidationError('Email is required') |
44 | 44 | if 'password' not in request.data: |
45 | 45 | raise ValidationError('Password is required') |
46 | - | |
47 | 46 | email = request.data['email'] |
47 | + existing_users = User.objects.filter(email=email) | |
48 | + if existing_users.exists(): | |
49 | + raise ValidationError("An account with this email already exists") | |
48 | 50 | user = User.objects.create_user(email, email=email, password=request.data['password']) |
49 | 51 | |
50 | 52 | body = ''' |
... | ... | @@ -58,7 +60,7 @@ |
58 | 60 | login(request, user) |
59 | 61 | return Response(UserSerializer(user).data, status=HTTP_201_CREATED) |
60 | 62 | |
61 | - def delete(self, request, format=None): | |
63 | + def delete(self, request): | |
62 | 64 | request.user.delete() |
63 | 65 | return Response(status=HTTP_204_NO_CONTENT) |
64 | 66 | |
... | ... | @@ -82,7 +84,7 @@ |
82 | 84 | password = request.data['password'] |
83 | 85 | user = authenticate(email=email, password=password) |
84 | 86 | |
85 | - if user is None: | |
87 | + if user is not None: | |
86 | 88 | raise ValidationError('Invalid email or password') |
87 | 89 | if not user.is_active: |
88 | 90 | raise ValidationError('Account is disabled') |