Created
April 30, 2014 20:48
-
-
Save whalesalad/e53d50b6f0ec88af521c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @require_POST | |
| def update_password(request): | |
| payload = json.loads(request.body) | |
| password = payload.get('password', None) | |
| password_confirm = payload.get('password_confirm', None) | |
| unique = set([password, password_confirm]) | |
| if len(unique) > 1: | |
| return JSONResponse({ | |
| 'messages': ('error', 'The two passwords provided do not match.') | |
| }) | |
| if len(unique) == 1: | |
| request.user.set_password(password) | |
| request.user.save() | |
| if request.user.check_password(password): | |
| return JSONResponse({ | |
| 'messages': ('success', 'The password was updated successfully for %s.' % request.user.email) | |
| }) | |
| return JSONResponse({ | |
| 'messages': ('error', 'You must specify a password and password_confirm field.') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment