From 9fd6eba6da5b401878477a15085af8c61687a684 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 21 Jan 2025 13:49:26 +0800 Subject: [PATCH] bugfix --- json/userroles.json | 22 ----------------- json/users.json | 9 ++++++- wwwroot/add_adminuser.dspy | 23 ++++++++++++++++++ wwwroot/user/user.ui | 2 +- wwwroot/user/user_panel.ui | 2 +- wwwroot/userpassword_login.dspy | 11 +++++++++ wwwroot/userpassword_login.ui | 43 +++++++++++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 25 deletions(-) delete mode 100644 json/userroles.json create mode 100644 wwwroot/add_adminuser.dspy create mode 100644 wwwroot/userpassword_login.dspy create mode 100644 wwwroot/userpassword_login.ui diff --git a/json/userroles.json b/json/userroles.json deleted file mode 100644 index e1ccd24..0000000 --- a/json/userroles.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "models_dir": "${HOME}$/py/rbac/models", - "output_dir": "${HOME}$/py/sage/wwwroot/_a/userroles", - "dbname": "sage", - "tblname": "userroles", - "title":"用户", - "params": { - "relation":{ - "outter_field":"roleid", - "param_field":"userid" - }, - "browserfields": { - "exclouded": ["id", "userid"], - "cwidth": {} - }, - "editexclouded": [ - "id", - "userid" - ], - "record_toolbar": null - } -} diff --git a/json/users.json b/json/users.json index 35c9cc9..376cdbc 100644 --- a/json/users.json +++ b/json/users.json @@ -6,6 +6,7 @@ "title":"用户", "params": { "sortby":"username", + "logined_userorgid":"orgid", "browserfields": { "exclouded": ["id"], "cwidth": {} @@ -13,6 +14,12 @@ "editexclouded": [ "id" ], - "record_toolbar": null + "subtables": [ + { + "field":"userid", + "title":"用户角色", + "subtable":"userrole" + } + ] } } diff --git a/wwwroot/add_adminuser.dspy b/wwwroot/add_adminuser.dspy new file mode 100644 index 0000000..61af0de --- /dev/null +++ b/wwwroot/add_adminuser.dspy @@ -0,0 +1,23 @@ +if params_kw.get('password') != params_kw.get('chkpassword'): + return Error(title='add user error', message='password not match') + +ns = params_kw.copy() +ns['id'] = uuid() +await rfexe('passowrd', ns) +user_orgid = await get_userorgid() +ns['orgid'] = user_orgid +dbname = await rfexe('get_module_dbname','rbac') +db = DBPools() +debug(f'{dbname=}') +async with db.sqlorContext(dbname) as sor: + await sor.C('users',ns.copy()) + uid = ns['id'] + ns = { + 'id':uuid(), + 'userid':uid, + 'roleid':'admin' + } + await sor.C('userrole', ns.copy()) + return UiMesage(title='Success', message='admin user added') +return UiError(title='Error', message='Error happened when add admin user') + diff --git a/wwwroot/user/user.ui b/wwwroot/user/user.ui index 62902d2..865b428 100644 --- a/wwwroot/user/user.ui +++ b/wwwroot/user/user.ui @@ -28,7 +28,7 @@ "widgettype":"Text", "options":{ "wrap":false, - "text":"{{get_username()}}" + "text":"{{get_username()}}({{str(get_user_roles(get_user()))}})" } } ] diff --git a/wwwroot/user/user_panel.ui b/wwwroot/user/user_panel.ui index 361c407..e80acaa 100644 --- a/wwwroot/user/user_panel.ui +++ b/wwwroot/user/user_panel.ui @@ -2,7 +2,7 @@ "id":"user_panel", "widgettype":"VBox", "options":{ - "width":"100px" + "width":"auto" }, "subwidgets":[ { diff --git a/wwwroot/userpassword_login.dspy b/wwwroot/userpassword_login.dspy new file mode 100644 index 0000000..883e3f0 --- /dev/null +++ b/wwwroot/userpassword_login.dspy @@ -0,0 +1,11 @@ +username = params_kw.get('username') +passwd = params_kw.get('passwd') +if not passwd: + return UiError(title='Login failed', message='Password is required') +passwd = password(passwd) +rzt = await check_user_password(request, username, passwd) +if rzt: + return UiMessage(title='Logined', message=f'Welcome back ') +return UiError(title='login failed', message='user and password mismatch') + + diff --git a/wwwroot/userpassword_login.ui b/wwwroot/userpassword_login.ui new file mode 100644 index 0000000..e8933ad --- /dev/null +++ b/wwwroot/userpassword_login.ui @@ -0,0 +1,43 @@ +{ + "id":"login_window", + "widgettype":"PopupWindow", + "options":{ + "auto_open":true, + "anthor":"cc", + "cwidth":20, + "cheight":"14" + }, + "subwidgets":[ + { + "widgettype":"Form", + "id":"userpasswd", + "options":{ + "cols":1, + "fields":[ + { + "name":"username", + "label":"用户名", + "uitype":"str" + }, + { + "name":"passwd", + "label":"密码", + "uitype":"password" + } + ] + } + } + ], + "binds":[ + { + "wid":"userpasswd", + "event":"submit", + "actiontype":"urlwidget", + "target":"self", + "options":{ + "url":"{{entire_url('userpassword_login.dspy')}}" + } + } + ] +} +