0001-custom_user-add-User.has_usable_password-48136.patch
src/authentic2/custom_user/models.py | ||
---|---|---|
30 | 30 |
from django.contrib.contenttypes.fields import GenericRelation |
31 | 31 |
except ImportError: |
32 | 32 |
from django.contrib.contenttypes.generic import GenericRelation |
33 |
from django.contrib.auth.hashers import identify_hasher |
|
34 |
from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX |
|
33 | 35 |
from django.contrib.auth.models import AbstractBaseUser |
34 | 36 |
from django.contrib.postgres.fields import JSONField |
35 | 37 | |
... | ... | |
208 | 210 |
verbose_name_plural = _('users') |
209 | 211 |
ordering = ('last_name', 'first_name', 'email', 'username') |
210 | 212 | |
213 |
def has_usable_password(self): |
|
214 |
""" |
|
215 |
Returns a boolean of whether the user has a usable password. |
|
216 |
""" |
|
217 |
if not super().has_usable_password(): |
|
218 |
return False |
|
219 |
if (self.password is None or |
|
220 |
self.password.startswith(UNUSABLE_PASSWORD_PREFIX)): |
|
221 |
return False |
|
222 |
try: |
|
223 |
identify_hasher(self.password) |
|
224 |
except ValueError: |
|
225 |
return False |
|
226 |
return True |
|
227 | ||
211 | 228 |
def get_full_name(self): |
212 | 229 |
""" |
213 | 230 |
Returns the first_name plus the last_name, with a space in between. |
214 |
- |