sage/wwwroot/up_login.dspy

63 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

debug(f'{params_kw=}, {password=}')
await rfexe('password', params_kw)
ns = {
"username":params_kw.username,
"password":params_kw.password
}
info(f'{ns=}')
db = DBPools()
async with db.sqlorContext('sage') as sor:
r = await sor.sqlExe('select * from users where username=${username}$ and password=${password}$', ns.copy())
if len(r) == 0:
# 登录失败:连续失败次数 +1(超过5分钟则重置为1)
await sor.sqlExe("UPDATE users SET login_fail_count = CASE WHEN last_login_fail IS NULL OR last_login_fail < NOW() - INTERVAL 5 MINUTE THEN 1 ELSE login_fail_count + 1 END, last_login_fail = NOW() WHERE username=${username}$", {'username': ns['username']})
return {
"widgettype":"Error",
"options":{
"timeout":3,
"title":"Login Error",
"message":"user name or password error"
}
}
# 登录成功:清除连续失败次数
await sor.sqlExe("UPDATE users SET login_fail_count = 0, last_login_fail = NULL, last_login = NOW() WHERE id=${id}$", {'id': r[0].id})
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"
}
}