rbac/wwwroot/user/up_login.dspy
2025-02-11 11:02:50 +08:00

59 lines
1.2 KiB
Plaintext

debug(f'{params_kw=}, {password=}')
ns = {
"username":params_kw.username,
"password":password_encode(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"
}
}