From f59c4a8ea75d300385ddb7349d35923c1e58c65d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 3 Jan 2025 17:42:22 +0800 Subject: [PATCH] bugfix --- www/user/login.ui | 121 ++++++++++++++++++++ www/user/register.dspy | 9 ++ www/user/register.ui | 80 +++++++++++++ www/user/reset_password/reset_password.dspy | 3 +- www/user/up_login.dspy | 59 ++++++++++ www/user/user_panel.ui | 15 +++ www/user/wechat_login.ui | 5 + 7 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 www/user/login.ui create mode 100644 www/user/register.dspy create mode 100644 www/user/register.ui create mode 100644 www/user/up_login.dspy create mode 100644 www/user/user_panel.ui create mode 100644 www/user/wechat_login.ui diff --git a/www/user/login.ui b/www/user/login.ui new file mode 100644 index 0000000..1ce2ddc --- /dev/null +++ b/www/user/login.ui @@ -0,0 +1,121 @@ +{ + "id":"login_window", + "widgettype":"PopupWindow", + "options":{ + "auto_open":true, + "anthor":"cc", + "cwidth":22, + "cheight":19 + }, + "subwidgets":[ +{ + "widgettype":"TabPanel", + "options":{ + "tab_wide":"auto", + "height":"100%", + "width":"100%", + "tab_pos":"top", + "items":[ + { + "name":"userpasswd", + "label":"用户密码", + "content":{ + "widgettype":"Form", + "options":{ + "cols":1, + "fields":[ + { + "name":"username", + "label":"用户名", + "uitype":"str" + }, + { + "name":"password", + "label":"密码", + "uitype":"password" + } + ] + }, + "binds":[ + { + "wid":"self", + "event":"submit", + "actiontype":"urlwidget", + "target":"self", + "options":{ + "method":"POST", + "url":"{{entire_url('up_login.dspy')}}" + } + } + ] + } + }, + { + "name":"checkcode", + "label":"手机验证码", + "content":{ + "widgettype":"Form", + "options":{ + "toolbar":{ + "tools":[ + { + "name":"gen_code", + "label":"发送验证码" + } + ] + }, + "description":"限中国国内手机", + "fields":[ + { + "name":"cell_no", + "label":"手机号", + "uitype":"str" + },{ + "name":"codeid", + "uitype":"hide", + "value":"{{uuid()}}" + },{ + "name":"check_code", + "uitype":"str" + } + ] + }, + "binds":[ + { + "wid":"self", + "event":"gen_code", + "actiontype":"urlwidget", + "datawidget":"self", + "datamethod":"getValue", + "target":"self", + "options":{ + "url":"{{entire_url('gen_code.dspy')}}" + } + }, + { + "wid":"self", + "event":"submit", + "actiontype":"urlwidget", + "target":"self", + "options":{ + "url":"{{entire_url('code_login.dspy')}}" + } + } + ] + } + }, + { + "name":"wechat", + "label":"微信", + "content":{ + "widgettype":"urlwidget", + "options":{ + "url":"{{entire_url('wechat_login.ui')}}" + } + } + } + ] + } +} + ] +} diff --git a/www/user/register.dspy b/www/user/register.dspy new file mode 100644 index 0000000..20232c3 --- /dev/null +++ b/www/user/register.dspy @@ -0,0 +1,9 @@ +debug(f'{params_kw=}') +db = DBPools() +dbname = await rfexe('get_module_dbname', 'sage') +async with db.sqlorContext(dbname) as sor: + orgid = await register_user(sor, params_kw) + # ownerid = await get_owner_orgid(sor) + # await openCustomerAccounts(sor, ownerid, orgid) + return UiMessage(title="Success", message="register success") +return UiError(title='Error', message="register failed") diff --git a/www/user/register.ui b/www/user/register.ui new file mode 100644 index 0000000..3a25c1d --- /dev/null +++ b/www/user/register.ui @@ -0,0 +1,80 @@ +{ + "widgettype":"PopupWindow", + "options":{ + "cwidth":22, + "height":"75%", + "archor":"cc", + "auto_open":true + }, + "subwidgets":[ + { + "widgettype":"Form", + "options":{ + "title":"user register", + "description":"base info we need is username, password and a cell phone number", + + "fields":[ + { + "name": "username", + "title": "\u7528\u6237\u540d", + "type": "str", + "length": 255, + "uitype": "str", + "datatype": "str", + "required":true, + "label": "\u7528\u6237\u540d" + }, + { + "name": "password", + "type": "str", + "length": 255, + "uitype": "password", + "datatype": "str", + "required":true, + "label": "\u5bc6\u7801" + }, + { + "name": "cfm_password", + "type": "str", + "length": 255, + "uitype": "password", + "datatype": "str", + "required":true, + "label": "\u5bc6\u7801" + }, + { + "name": "email", + "title": "\u90ae\u4ef6\u5730\u5740", + "type": "str", + "length": 255, + "uitype": "str", + "datatype": "str", + "required":true, + "label": "\u90ae\u4ef6\u5730\u5740" + }, + { + "name": "mobile", + "title": "\u624b\u673a", + "type": "str", + "length": 255, + "uitype": "str", + "datatype": "str", + "required":true, + "label": "\u624b\u673a" + } + ] + }, + "binds":[ + { + "wid":"self", + "event":"submit", + "actiontype":"urlwidget", + "target":"self", + "options":{ + "url":"{{entire_url('register.dspy')}}" + } + } + ] + } + ] +} diff --git a/www/user/reset_password/reset_password.dspy b/www/user/reset_password/reset_password.dspy index 1ce256e..367b902 100644 --- a/www/user/reset_password/reset_password.dspy +++ b/www/user/reset_password/reset_password.dspy @@ -10,7 +10,8 @@ ns = { 'password':params_kw.password } db = DBPools() -async with db.sqlorContext('sage') as sor: +dbname = await rfexe('get_module_dbname', 'rbac') +async with db.sqlorContext(dbname) as sor: await sor.U('users', ns) return UiMessage(title='Success', message='Password reset success') return UiError(title='Error', message='Reset password failed') diff --git a/www/user/up_login.dspy b/www/user/up_login.dspy new file mode 100644 index 0000000..2b27374 --- /dev/null +++ b/www/user/up_login.dspy @@ -0,0 +1,59 @@ + +debug(f'{params_kw=}, {password=}') +await rfexe('password', params_kw) +ns = { + "username":params_kw.username, + "password":params_kw.password +} + +info(f'{ns=}') +db = DBPools() +dbname = await rfexe('get_module_dbname', 'rbac') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlExe('select * from users where username=${username}$ and password=${password}$', ns.copy()) + if len(r) == 0: + return { + "widgettype":"Error", + "options":{ + "timeout":3, + "title":"Login Error", + "message":"user name or password error" + } + } + await remember_user(r[0].id, username=r[0].username, userorgid=r[0].orgid) + return { + "widgettype":"Message", + "options":{ + "timeout":3, + "auto_open":true, + "title":"Login", + "message":"Welcome back" + }, + "binds":[ + { + "wid":"self", + "event":"dismissed", + "actiontype":"urlwidget", + "target":"window", + "options":{ + "url":entire_url('/index.ui') + } + }, + { + "wid":"self", + "event":"opened", + "actiontype":"script", + "target":"window.login_window", + "script":"this.destroy()" + } + ] + } +return { + "widgettype":"Error", + "options":{ + "timeout":3, + "title":"Login Error", + "message":"system error" + } +} + diff --git a/www/user/user_panel.ui b/www/user/user_panel.ui new file mode 100644 index 0000000..361c407 --- /dev/null +++ b/www/user/user_panel.ui @@ -0,0 +1,15 @@ +{ + "id":"user_panel", + "widgettype":"VBox", + "options":{ + "width":"100px" + }, + "subwidgets":[ + { + "widgettype":"urlwidget", + "options":{ + "url":"{{entire_url('user.ui')}}" + } + } + ] +} diff --git a/www/user/wechat_login.ui b/www/user/wechat_login.ui new file mode 100644 index 0000000..9f65d1d --- /dev/null +++ b/www/user/wechat_login.ui @@ -0,0 +1,5 @@ +{ + "widgettype":"VBox", + "options":{ + } +}