From 186f3518d0451f97ab5f5ea6f8816cea8d923bdd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 27 Jun 2018 19:59:58 +0200 Subject: [PATCH] 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(-) diff --git a/src/authentic2_auth_fc/utils.py b/src/authentic2_auth_fc/utils.py index 6037ee6..6e9c35b 100644 --- a/src/authentic2_auth_fc/utils.py +++ b/src/authentic2_auth_fc/utils.py @@ -76,6 +76,8 @@ def mapping_to_value(mapping, user_info): elif 'compute' in mapping: if mapping['compute'] == 'today': value = datetime.date.today() + elif mapping['compute'] == 'random': + value = unicode(uuid.uuid4()) else: raise NotImplementedError @@ -143,7 +145,13 @@ def apply_user_info_mappings(user, user_info): continue if mapping.get('if-tag') and mapping['if-tag'] not in tags: continue - if hasattr(user, attribute): + + if attribute == 'password': + if mapping.get('if-empty') and user.has_usable_password(): + continue + save_user = True + user.set_password(value) + elif hasattr(user, attribute): save_user = True if mapping.get('if-empty') and getattr(user, attribute): continue