This commit is contained in:
yumoqing 2025-01-03 17:42:22 +08:00
parent 0c16deab08
commit f59c4a8ea7
7 changed files with 291 additions and 1 deletions

121
www/user/login.ui Normal file
View File

@ -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')}}"
}
}
}
]
}
}
]
}

9
www/user/register.dspy Normal file
View File

@ -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")

80
www/user/register.ui Normal file
View File

@ -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')}}"
}
}
]
}
]
}

View File

@ -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')

59
www/user/up_login.dspy Normal file
View File

@ -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"
}
}

15
www/user/user_panel.ui Normal file
View File

@ -0,0 +1,15 @@
{
"id":"user_panel",
"widgettype":"VBox",
"options":{
"width":"100px"
},
"subwidgets":[
{
"widgettype":"urlwidget",
"options":{
"url":"{{entire_url('user.ui')}}"
}
}
]
}

5
www/user/wechat_login.ui Normal file
View File

@ -0,0 +1,5 @@
{
"widgettype":"VBox",
"options":{
}
}