41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""俱乐部是否强制收集手机号(config_json.force_phone_auth)。"""
|
||
import logging
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
CONFIG_KEY = 'force_phone_auth'
|
||
|
||
|
||
def is_club_force_phone_auth(club_id: str) -> bool:
|
||
"""
|
||
是否强制手机号认证。默认 True(与现网一致:门槛用户未认证则 need_auth)。
|
||
后台关闭后,/peizhi/yhbdsjh 恒返回 need_auth=False,前端不会再强制跳认证页。
|
||
"""
|
||
cid = (club_id or '').strip()
|
||
if not cid:
|
||
return True
|
||
try:
|
||
from jituan.models import Club
|
||
club = Club.query.filter(club_id=cid).first()
|
||
if not club and cid != cid.lower():
|
||
club = Club.query.filter(club_id=cid.lower()).first()
|
||
if not club:
|
||
return True
|
||
cfg = club.config_json or {}
|
||
if CONFIG_KEY not in cfg:
|
||
return True
|
||
raw = cfg.get(CONFIG_KEY)
|
||
if isinstance(raw, str):
|
||
return raw.strip().lower() in ('1', 'true', 'yes', 'on')
|
||
return bool(raw)
|
||
except Exception:
|
||
logger.exception('read force_phone_auth failed club=%s', cid)
|
||
return True
|
||
|
||
|
||
def set_club_force_phone_auth(club, enabled: bool) -> None:
|
||
"""写入 club.config_json,调用方负责 save。"""
|
||
cfg = dict(getattr(club, 'config_json', None) or {})
|
||
cfg[CONFIG_KEY] = bool(enabled)
|
||
club.config_json = cfg
|