过渡版:本地验发token

This commit is contained in:
sophie committed 2026-05-05 10:25:47 +08:00
1 parent fb71def840
commit a5f0ec645d
14 files changed
+313 -220

No files matched your search

+6 -7
View File
@@ -3,6 +3,8 @@ from app import db
from app.models import User, Agent, QuickQuestion, UserFavoriteAgent, UserDefaultAgent, UserHomepageConfig, Announcement, LoginAudit, WecomCallbackAudit, GeneralFeedback, ChatLog
from app.services.wecom_notify import mark_wecom_message_opened, send_wecom_event_message
from app.services.wecom_crypto import sha1_hex, decrypt_wecom_aes, extract_encrypt_field
from app.auth_jwt import get_current_user as _auth_current_user
from app.auth_jwt import issue_local_access_token
from sqlalchemy.exc import IntegrityError, OperationalError
from sqlalchemy import and_, or_, inspect, insert
from datetime import datetime, timedelta
@@ -122,13 +124,8 @@ def _execute_login_audit_insert(payload: dict):
raise
def _get_current_user():
"""
Helper to get current user from headers
"""
user_id = request.headers.get('X-User-Id')
if not user_id:
return None
return db.session.get(User, int(user_id))
"""Helper to resolve current user from JWT first, then optional legacy headers."""
return _auth_current_user()
def _is_wecom_configured():
return all([
@@ -296,6 +293,8 @@ def _build_login_payload(user: User, source: str = 'password', bind_status: str
'role': user.role,
'default_agent_id': user.default_agent_id,
'source': source,
'access_token': issue_local_access_token(user),
'token_type': 'Bearer',
}
if bind_status:
payload['bind_status'] = bind_status