Projet

Général

Profil

0001-custom_user-add-User.has_usable_password-48136.patch

Paul Marillonnet, 30 octobre 2020 10:53

Télécharger (1,51 ko)

Voir les différences:

Subject: [PATCH] custom_user: add User.has_usable_password (#48136)

    * mitigate variations in django versions on
    django.contrib.auth.hashers.is_usable_password
 src/authentic2/custom_user/models.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
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 import hashers
33 34
from django.contrib.auth.models import AbstractBaseUser
34 35
from django.contrib.postgres.fields import JSONField
35 36

  
......
208 209
        verbose_name_plural = _('users')
209 210
        ordering = ('last_name', 'first_name', 'email', 'username')
210 211

  
212
    def has_usable_password(self):
213
        if self.password is None or self.password.startswith('!'):
214
            return False
215
        try:
216
            hashers.identity_hasher(password)
217
        except ValueError:
218
            return False
219
        return True
220

  
211 221
    def get_full_name(self):
212 222
        """
213 223
        Returns the first_name plus the last_name, with a space in between.
214
-