Commit f6068531bbee01d27daa3fe3a7979b97062b2b1f

Authored by Chung Wang
1 parent e8079030e4
Exists in master

Update and fix the email confirmation under flashcards/api.py under the userdetail for patch

Showing 1 changed file with 15 additions and 27 deletions Side-by-side Diff

flashcards/api.py View file @ f606853
... ... @@ -11,30 +11,23 @@
11 11 class UserDetail(APIView):
12 12 def patch(self, request, format=None):
13 13 """
14   - Updates a user's password after they enter a valid old password.
15   - TODO: email verification
  14 + This method checks either the email or the password passed in
  15 + is valid. If confirmation key is correct, it validates the
  16 + user. It updates the password if the new password
  17 + is valid.
  18 +
16 19 """
  20 + currentuser = request.user
17 21  
18   - if 'old_password' not in request.data:
19   - raise ValidationError('Old password is required')
20   - if 'new_password' not in request.data:
21   - raise ValidationError('New password is required')
22   - if not request.data['new_password']:
23   - raise ValidationError('Password cannot be blank')
  22 + if 'confirmation_key' in request.data:
  23 + if not currentuser.confirm_email( request.data['confirmation_key'] ):
  24 + raise ValidationError('confirmation_key is invalid')
24 25  
25   - currentuser = request.user
26   -
27   - if not currentuser.check_password(request.data['old_password']):
28   - raise ValidationError('Invalid old password')
29   -
30   - send_mail("Please verify your Flashy account",
31   - body % currentuser.confirmation_key,
32   - "noreply@flashy.cards",
33   - [currentuser.email])
34   -
35   - currentuser.confirm_email( currentuser.confirmation_key )
36   -
37   - if currentuser.isconfirmed
  26 + if 'new_password' in request.data:
  27 + if not currentuser.check_password(request.data['old_password']):
  28 + raise ValidationError('Invalid old password')
  29 + if not request.data['new_password']:
  30 + raise ValidationError('Password cannot be blank')
38 31 currentuser.set_password(request.data['new_password'])
39 32 currentuser.save()
40 33  
... ... @@ -60,11 +53,6 @@
60 53 If you did not register for Flashy, no action is required.
61 54 '''
62 55  
63   - send_mail("Please verify your Flashy account",
64   - body % user.confirmation_key,
65   - "noreply@flashy.cards",
66   - [user.email])
67   -
68 56 user = authenticate(email=email, password=request.data['password'])
69 57 login(request, user)
70 58 return Response(UserSerializer(user).data)
... ... @@ -98,7 +86,7 @@
98 86 if not user.is_active:
99 87 raise ValidationError('Account is disabled')
100 88 login(request, user)
101   - return Response(UserSerializer(User).data)
  89 + return Response(UserSerializer(user).data)
102 90  
103 91  
104 92 class PasswordReset(APIView):