- api/add_sub_distributor_admin.dspy: create org+user+reseller.admin role, show password - api/reset_sub_distributor_admin_pwd.dspy: reset admin password, show new password - sub_distributors_list: add toolbar buttons with popup binds
36 lines
1.2 KiB
Plaintext
36 lines
1.2 KiB
Plaintext
"""Reset the admin password for the selected sub_distributor."""
|
|
sub_distributor_id = params_kw.get('sub_distributor_id') or params_kw.get('id')
|
|
if not sub_distributor_id:
|
|
return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': 'Missing sub_distributor_id', 'timeout': 3}}
|
|
|
|
admin_username = f'admin_{sub_distributor_id[:8]}'
|
|
new_pwd = getID().replace('-','')[:12]
|
|
|
|
async with DBPools().sqlorContext('sage') as sor:
|
|
recs = await sor.sqlExe(
|
|
'SELECT id FROM users WHERE username = ${un}$', {'un': admin_username}
|
|
)
|
|
if not recs:
|
|
return {
|
|
'widgettype': 'Message',
|
|
'options': {
|
|
'title': '管理员不存在',
|
|
'message': f'管理员 {admin_username} 不存在,请先创建',
|
|
'type': 'warning', 'timeout': 5
|
|
}
|
|
}
|
|
|
|
await sor.U('users', {
|
|
'id': recs[0].id,
|
|
'password': password_encode(new_pwd),
|
|
})
|
|
|
|
return {
|
|
'widgettype': 'Message',
|
|
'options': {
|
|
'title': '密码重置成功',
|
|
'message': f'用户名: {admin_username}\n新密码: {new_pwd}',
|
|
'type': 'success', 'timeout': 0
|
|
}
|
|
}
|