Projet

Général

Profil

0001-utils-add-special-case-for-mapping-the-User.password.patch

Benjamin Dauvergne, 29 juin 2018 16:36

Télécharger (1,56 ko)

Voir les différences:

Subject: [PATCH 1/5] utils: add special case for mapping the User.password
 (fixes #24835)

The goal is to set a random password for new accounts,
so that they can recover it. In this case we use
the value {"compute": "random"}.
 src/authentic2_auth_fc/utils.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/authentic2_auth_fc/utils.py
76 76
    elif 'compute' in mapping:
77 77
        if mapping['compute'] == 'today':
78 78
            value = datetime.date.today()
79
        elif mapping['compute'] == 'random':
80
            value = unicode(uuid.uuid4())
79 81
    else:
80 82
        raise NotImplementedError
81 83

  
......
143 145
            continue
144 146
        if mapping.get('if-tag') and mapping['if-tag'] not in tags:
145 147
            continue
146
        if hasattr(user, attribute):
148

  
149
        if attribute == 'password':
150
            if mapping.get('if-empty') and user.has_usable_password():
151
                continue
152
            save_user = True
153
            user.set_password(value)
154
        elif hasattr(user, attribute):
147 155
            save_user = True
148 156
            if mapping.get('if-empty') and getattr(user, attribute):
149 157
                continue
150
-