Files
Django/jituan/services/force_phone_auth.py

41 lines
1.4 KiB
Python
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.
"""俱乐部是否强制收集手机号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