Commit 53de94935b117e0a5ba05f234c428b853c89402b
1 parent
38fe9bae
Exists in
master
and in
39 other branches
Changing check_password and removing unnecessary things
Showing
1 changed file
with
11 additions
and
10 deletions
Show diff stats
src/accounts/models.py
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | import urlparse |
| 4 | 4 | |
| 5 | 5 | from django.db import models, DatabaseError |
| 6 | +from django.contrib.auth.hashers import check_password | |
| 6 | 7 | from django.contrib.auth.models import AbstractUser |
| 7 | 8 | from django.core.urlresolvers import reverse |
| 8 | 9 | |
| ... | ... | @@ -23,19 +24,19 @@ class User(AbstractUser): |
| 23 | 24 | |
| 24 | 25 | def check_password(self, raw_password): |
| 25 | 26 | """ |
| 26 | - Returns a boolean of whether the raw_password was correct. | |
| 27 | + Returns a boolean of whether the raw_password was correct. Handles | |
| 28 | + hashing formats behind the scenes. | |
| 27 | 29 | """ |
| 28 | - if not raw_password or not self.has_usable_password(): | |
| 29 | - return False | |
| 30 | - return self.password == raw_password | |
| 30 | + def setter(raw_password): | |
| 31 | + self.set_password(raw_password) | |
| 32 | + self.save(update_fields=["password"]) | |
| 31 | 33 | |
| 32 | - def has_usable_password(self): | |
| 33 | - if not self.password: | |
| 34 | - return False | |
| 35 | - return True | |
| 34 | + if self.xmpp.exists(): | |
| 35 | + is_correct = raw_password == self.xmpp.all()[0].password | |
| 36 | + if is_correct: | |
| 37 | + return is_correct | |
| 36 | 38 | |
| 37 | - def set_password(self, raw_password): | |
| 38 | - self.password = unicode(raw_password) | |
| 39 | + return check_password(raw_password, self.password, setter) | |
| 39 | 40 | |
| 40 | 41 | def get_absolute_url(self): |
| 41 | 42 | return reverse('user_profile', kwargs={'username': self.username}) | ... | ... |