Commit dfb508c311b5fab2c37445280cedb3a524f4aa17

Authored by Andrew Buss
1 parent 3ca2d122ab
Exists in master

Checked for existing users with an email address

Showing 2 changed files with 5 additions and 1 deletions Side-by-side Diff

flashcards/api.py View file @ dfb508c
... ... @@ -45,6 +45,9 @@
45 45 raise ValidationError('Password is required')
46 46  
47 47 email = request.data['email']
  48 + existing_users = User.objects.filter(email=email)
  49 + if existing_users.exists():
  50 + raise ValidationError("An account with this email already exists")
48 51 user = User.objects.create_user(email, email=email, password=request.data['password'])
49 52  
50 53 body = '''
... ... @@ -58,7 +61,7 @@
58 61 login(request, user)
59 62 return Response(UserSerializer(user).data, status=HTTP_201_CREATED)
60 63  
61   - def delete(self, request, format=None):
  64 + def delete(self, request):
62 65 request.user.delete()
63 66 return Response(status=HTTP_204_NO_CONTENT)
64 67  
run_tests.sh View file @ dfb508c
  1 +#!/bin/bash -xe
1 2 venv/bin/python venv/bin/coverage run --source='flashcards' manage.py test flashcards/tests/
2 3 venv/bin/python venv/bin/coverage html