unis-oa/backend/app/public_config.py

47 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""登录页与首屏共用的那份公开配置。
两个出口共用同一个口径,别各写一份:
* ``GET /api/v1/settings/public``(``app/api/support.py``)——前端挂载之后问的那一次;
* ``index.html`` 里注进 ``window.__APP_CONFIG__`` 的那一份(:mod:`app.web_shell`)——
画第一笔之前就送到浏览器手里的那一次。
里面只有匿名可读的东西:站点名与图标、免登这一档怎么画、空闲超时开没开。
应用密钥、Hub 令牌、任何人的个人信息,一概不出这扇门。
"""
from __future__ import annotations
from . import hubconfig
from .config import settings
from .security import session_idle_minutes
def payload() -> dict:
"""当前生效的公开配置(接口 ``data`` 那一层原样)。"""
cfg = hubconfig.get()
return {
"site_name": settings.site_name,
"site_logo": settings.site_logo,
"site_description": settings.site_description,
"register_enabled": settings.register_enabled,
# 登录页据此决定要不要取验证码、要不要提示"账号由统一身份平台管理",
# 以及"只允许免登"时要不要把用户送回统一门户
"hub": {
"login_enabled": cfg.login_on,
"login_mode": cfg.hub_login_mode,
"auto_provision": cfg.hub_auto_provision,
# sso_enabled:能走免登(地址+应用编码+应用密钥齐了);
# sso_only:本系统不再收账号密码,登录页只留"去统一门户"。
# 应用密钥本身从不出接口,这里只说"配齐没有"。
"sso_enabled": cfg.sso_on,
"sso_configured": cfg.sso_ready,
"sso_only": cfg.sso_only,
"portal_url": cfg.portal_url,
"state_required": cfg.hub_sso_state_required,
},
# 本地会话生命周期归本系统管(对接指南第 8 节:Hub 登出不回收下游会话),
# 前端据此决定要不要跑心跳与空闲计时;0 表示不启用
"session": {"idle_minutes": session_idle_minutes()},
}