feat(rbac): 登录检查refer,非用户点击登录成功后不刷新页面
- login.ui 密码/手机登录透传 login_source - up_login 条件化 /index.ui 跳转(仅主动登录刷新) - code_login 三处登录分支收敛 _login_msg,auto 时不 dispatch
This commit is contained in:
parent
3e21ee6e6e
commit
a72d7ef112
@ -2,6 +2,45 @@
|
|||||||
# 调用sms_engine验证后完成登录或自动注册
|
# 调用sms_engine验证后完成登录或自动注册
|
||||||
debug(f'code_login.dspy: {params_kw=}')
|
debug(f'code_login.dspy: {params_kw=}')
|
||||||
|
|
||||||
|
def _login_msg(username, welcome):
|
||||||
|
# 登录成功 Message;非用户主动点击登录(login_source=auto,如401自动弹窗)时不刷新页面
|
||||||
|
msg = {
|
||||||
|
"widgettype": "Message",
|
||||||
|
"options": {
|
||||||
|
"timeout": 3,
|
||||||
|
"auto_open": True,
|
||||||
|
"title": "登录成功",
|
||||||
|
"message": welcome
|
||||||
|
},
|
||||||
|
"binds": [
|
||||||
|
{
|
||||||
|
"wid": "self",
|
||||||
|
"event": "dismissed",
|
||||||
|
"actiontype": "urlwidget",
|
||||||
|
"target": "window.user_container",
|
||||||
|
"options": {"url": entire_url('/rbac/user/userinfo.ui')}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wid": "self",
|
||||||
|
"event": "dismissed",
|
||||||
|
"actiontype": "script",
|
||||||
|
"target": "body.login_window",
|
||||||
|
"script": "this.destroy()"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if params_kw.get('login_source', 'manual') == 'auto':
|
||||||
|
msg["options"]["refresh"] = False
|
||||||
|
else:
|
||||||
|
msg["binds"].append({
|
||||||
|
"wid": "self",
|
||||||
|
"event": "dismissed",
|
||||||
|
"actiontype": "script",
|
||||||
|
"target": "self",
|
||||||
|
"script": "if(bricks.app && bricks.app.dispatch) bricks.app.dispatch('user_logined')"
|
||||||
|
})
|
||||||
|
return msg
|
||||||
|
|
||||||
cellphone = params_kw.cell_no
|
cellphone = params_kw.cell_no
|
||||||
key = params_kw.codeid
|
key = params_kw.codeid
|
||||||
sms_code = params_kw.check_code
|
sms_code = params_kw.check_code
|
||||||
@ -70,40 +109,7 @@ try:
|
|||||||
WHERE id = ${id}$
|
WHERE id = ${id}$
|
||||||
""", {'id': r.id, 'now': now_str})
|
""", {'id': r.id, 'now': now_str})
|
||||||
await remember_user(r.id, username=r.username, userorgid=r.orgid)
|
await remember_user(r.id, username=r.username, userorgid=r.orgid)
|
||||||
return {
|
return _login_msg(r.username, f"{r.username} 欢迎回来")
|
||||||
"widgettype": "Message",
|
|
||||||
"options": {
|
|
||||||
"timeout": 3,
|
|
||||||
"auto_open": True,
|
|
||||||
"title": "登录成功",
|
|
||||||
"message": f"{r.username} 欢迎回来"
|
|
||||||
},
|
|
||||||
"binds": [
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "urlwidget",
|
|
||||||
"target": "window.user_container",
|
|
||||||
"options": {
|
|
||||||
"url": entire_url('/rbac/user/userinfo.ui')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "script",
|
|
||||||
"target": "body.login_window",
|
|
||||||
"script": "this.destroy()"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "script",
|
|
||||||
"target": "self",
|
|
||||||
"script": "if(bricks.app && bricks.app.dispatch) bricks.app.dispatch('user_logined')"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
# 多个用户绑定同一手机号
|
# 多个用户绑定同一手机号
|
||||||
if params_kw.selected_id:
|
if params_kw.selected_id:
|
||||||
for r in recs:
|
for r in recs:
|
||||||
@ -116,40 +122,7 @@ try:
|
|||||||
WHERE id = ${id}$
|
WHERE id = ${id}$
|
||||||
""", {'id': r.id, 'now': now_str})
|
""", {'id': r.id, 'now': now_str})
|
||||||
await remember_user(r.id, username=r.username, userorgid=r.orgid)
|
await remember_user(r.id, username=r.username, userorgid=r.orgid)
|
||||||
return {
|
return _login_msg(r.username, f"{r.username} 欢迎回来")
|
||||||
"widgettype": "Message",
|
|
||||||
"options": {
|
|
||||||
"timeout": 3,
|
|
||||||
"auto_open": True,
|
|
||||||
"title": "登录成功",
|
|
||||||
"message": f"{r.username} 欢迎回来"
|
|
||||||
},
|
|
||||||
"binds": [
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "urlwidget",
|
|
||||||
"target": "window.user_container",
|
|
||||||
"options": {
|
|
||||||
"url": entire_url('/rbac/user/userinfo.ui')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "script",
|
|
||||||
"target": "body.login_window",
|
|
||||||
"script": "this.destroy()"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "script",
|
|
||||||
"target": "self",
|
|
||||||
"script": "if(bricks.app && bricks.app.dispatch) bricks.app.dispatch('user_logined')"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
# 返回用户选择列表
|
# 返回用户选择列表
|
||||||
buttons = []
|
buttons = []
|
||||||
@ -221,40 +194,7 @@ try:
|
|||||||
|
|
||||||
r = d['data']['user']
|
r = d['data']['user']
|
||||||
await remember_user(r.id, username=r.username, userorgid=r.orgid)
|
await remember_user(r.id, username=r.username, userorgid=r.orgid)
|
||||||
return {
|
return _login_msg(r.username, f"{r.username} 欢迎")
|
||||||
"widgettype": "Message",
|
|
||||||
"options": {
|
|
||||||
"timeout": 3,
|
|
||||||
"auto_open": True,
|
|
||||||
"title": "登录成功",
|
|
||||||
"message": f"{r.username} 欢迎"
|
|
||||||
},
|
|
||||||
"binds": [
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "urlwidget",
|
|
||||||
"target": "window.user_container",
|
|
||||||
"options": {
|
|
||||||
"url": entire_url('/rbac/user/userinfo.ui')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "script",
|
|
||||||
"target": "body.login_window",
|
|
||||||
"script": "this.destroy()"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"wid": "self",
|
|
||||||
"event": "dismissed",
|
|
||||||
"actiontype": "script",
|
|
||||||
"target": "self",
|
|
||||||
"script": "if(bricks.app && bricks.app.dispatch) bricks.app.dispatch('user_logined')"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception(f'code_login error: {e}')
|
exception(f'code_login error: {e}')
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -47,7 +47,10 @@
|
|||||||
"target": "self",
|
"target": "self",
|
||||||
"options": {
|
"options": {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "{{entire_url('up_login.dspy')}}"
|
"url": "{{entire_url('up_login.dspy')}}",
|
||||||
|
"params": {
|
||||||
|
"login_source": "{{params_kw.get('login_source', 'manual')}}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -93,7 +96,10 @@
|
|||||||
"target": "self",
|
"target": "self",
|
||||||
"options": {
|
"options": {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "{{code_login_url}}"
|
"url": "{{code_login_url}}",
|
||||||
|
"params": {
|
||||||
|
"login_source": "{{params_kw.get('login_source', 'manual')}}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -109,7 +109,8 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
""", {'id': user.id, 'now': now_str})
|
""", {'id': user.id, 'now': now_str})
|
||||||
await remember_user(r[0].id, username=r[0].username, userorgid=r[0].orgid)
|
await remember_user(r[0].id, username=r[0].username, userorgid=r[0].orgid)
|
||||||
await _audit_login(sor, r[0].id, r[0].username, 'login', 'ok')
|
await _audit_login(sor, r[0].id, r[0].username, 'login', 'ok')
|
||||||
return {
|
login_source = params_kw.get('login_source', 'manual')
|
||||||
|
msg = {
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"data": { "user": r[0]},
|
"data": { "user": r[0]},
|
||||||
"widgettype":"Message",
|
"widgettype":"Message",
|
||||||
@ -121,15 +122,6 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
"message":f"{r[0].username} Welcome back"
|
"message":f"{r[0].username} Welcome back"
|
||||||
},
|
},
|
||||||
"binds":[
|
"binds":[
|
||||||
{
|
|
||||||
"wid":"self",
|
|
||||||
"event":"dismissed",
|
|
||||||
"actiontype":"urlwidget",
|
|
||||||
"target":"window",
|
|
||||||
"options":{
|
|
||||||
"url":entire_url('/index.ui')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"wid":"self",
|
"wid":"self",
|
||||||
"event":"opened",
|
"event":"opened",
|
||||||
@ -139,6 +131,21 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
if login_source == 'auto':
|
||||||
|
# 非用户主动点击登录(如401自动弹窗):不刷新页面,标记不刷新
|
||||||
|
msg["options"]["refresh"] = False
|
||||||
|
else:
|
||||||
|
# 用户主动点击登录:登录成功后刷新页面(跳转/index.ui)
|
||||||
|
msg["binds"].insert(0, {
|
||||||
|
"wid":"self",
|
||||||
|
"event":"dismissed",
|
||||||
|
"actiontype":"urlwidget",
|
||||||
|
"target":"window",
|
||||||
|
"options":{
|
||||||
|
"url":entire_url('/index.ui')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return msg
|
||||||
return {
|
return {
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"data": {
|
"data": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user