增加登陆相关api
This commit is contained in:
parent
bfb9dca56a
commit
0cce311cae
@ -248,13 +248,16 @@ async def get_user_permissions_route(session_cookie: Optional[str] = Depends(get
|
|||||||
@router.post("/api/action/login")
|
@router.post("/api/action/login")
|
||||||
async def saas_login(request: Request):
|
async def saas_login(request: Request):
|
||||||
"""兼容 SaaS 版前端登录"""
|
"""兼容 SaaS 版前端登录"""
|
||||||
|
from urllib.parse import unquote
|
||||||
|
|
||||||
content_type = request.headers.get('content-type', '')
|
content_type = request.headers.get('content-type', '')
|
||||||
|
|
||||||
if 'application/x-www-form-urlencoded' in content_type:
|
if 'application/x-www-form-urlencoded' in content_type:
|
||||||
body = await request.body()
|
body = await request.body()
|
||||||
params = dict(pair.split('=', 1) for pair in body.decode().split('&') if '=' in pair)
|
params = dict(pair.split('=', 1) for pair in body.decode().split('&') if '=' in pair)
|
||||||
username = params.get('usr', params.get('username', ''))
|
# URL 解码参数
|
||||||
password = params.get('pwd', params.get('password', ''))
|
username = unquote(params.get('usr', params.get('username', '')))
|
||||||
|
password = unquote(params.get('pwd', params.get('password', '')))
|
||||||
else:
|
else:
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
username = data.get('usr', data.get('username', ''))
|
username = data.get('usr', data.get('username', ''))
|
||||||
|
|||||||
43
apps/jingrow/jingrow/sessions.py
Normal file
43
apps/jingrow/jingrow/sessions.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Copyright (c) 2025, JINGROW and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
"""
|
||||||
|
会话相关白名单函数 - 转发到 SaaS 端
|
||||||
|
"""
|
||||||
|
|
||||||
|
import jingrow
|
||||||
|
import requests
|
||||||
|
from jingrow.config import Config
|
||||||
|
from jingrow.utils.auth import get_request_session_cookie
|
||||||
|
|
||||||
|
|
||||||
|
@jingrow.whitelist()
|
||||||
|
def get_boot_info():
|
||||||
|
"""获取启动信息 - 转发到 SaaS 端"""
|
||||||
|
url = f"{Config.jingrow_server_url}/api/action/jingrow.sessions.get_boot_info"
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
|
||||||
|
session_cookie = get_request_session_cookie()
|
||||||
|
if session_cookie:
|
||||||
|
headers["Cookie"] = f"sid={session_cookie}"
|
||||||
|
|
||||||
|
resp = requests.get(url, headers=headers, timeout=30)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
return resp.json().get("message", {})
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
@jingrow.whitelist()
|
||||||
|
def get_translations():
|
||||||
|
"""获取翻译 - 转发到 SaaS 端"""
|
||||||
|
url = f"{Config.jingrow_server_url}/api/action/jingrow.sessions.get_translations"
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
|
||||||
|
session_cookie = get_request_session_cookie()
|
||||||
|
if session_cookie:
|
||||||
|
headers["Cookie"] = f"sid={session_cookie}"
|
||||||
|
|
||||||
|
resp = requests.get(url, headers=headers, timeout=30)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
return resp.json().get("message", {})
|
||||||
|
return {}
|
||||||
Loading…
x
Reference in New Issue
Block a user