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"}.
This commit is contained in:
parent
215c1f5abd
commit
186f3518d0
|
@ -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
|
||||
|
|
Reference in New Issue