feat: add Space aggregate login

This commit is contained in:
237899745
2026-05-27 20:39:46 +08:00
parent e725db79a9
commit 056948612a
136 changed files with 2405 additions and 322 deletions

View File

@@ -76,6 +76,7 @@ def _get_migration_steps():
(19, _migrate_to_v19),
(20, _migrate_to_v20),
(21, _migrate_to_v21),
(22, _migrate_to_v22),
]
@@ -933,3 +934,71 @@ def _migrate_to_v21(conn):
)
conn.commit()
def _migrate_to_v22(conn):
"""迁移到版本22 - Space 聚合登录配置、绑定与短期待绑定凭证。"""
cursor = conn.cursor()
system_columns = _get_table_columns(cursor, "system_config")
system_fields = [
("social_login_enabled", "INTEGER DEFAULT 0"),
("social_login_endpoint", "TEXT DEFAULT 'https://www.spacezs.cn/connect.php'"),
("social_login_appid", "TEXT DEFAULT ''"),
("social_login_appkey", "TEXT DEFAULT ''"),
("social_login_providers", "TEXT DEFAULT 'qq,wx,alipay'"),
]
for field, ddl in system_fields:
_add_column_if_missing(
cursor,
"system_config",
system_columns,
field,
ddl,
ok_message=f" [OK] 添加 system_config.{field} 字段",
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS social_login_bindings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
provider TEXT NOT NULL,
social_uid TEXT NOT NULL,
nickname TEXT DEFAULT '',
avatar_url TEXT DEFAULT '',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_login_at TIMESTAMP,
UNIQUE (provider, social_uid),
UNIQUE (user_id, provider),
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
)
"""
)
cursor.execute("CREATE INDEX IF NOT EXISTS idx_social_login_bindings_user ON social_login_bindings(user_id)")
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_social_login_bindings_provider_uid ON social_login_bindings(provider, social_uid)"
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS social_pending_binds (
id INTEGER PRIMARY KEY AUTOINCREMENT,
token TEXT NOT NULL UNIQUE,
provider TEXT NOT NULL,
social_uid TEXT NOT NULL,
nickname TEXT DEFAULT '',
avatar_url TEXT DEFAULT '',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expires_at TIMESTAMP NOT NULL
)
"""
)
cursor.execute("CREATE INDEX IF NOT EXISTS idx_social_pending_binds_token ON social_pending_binds(token)")
cursor.execute(
"CREATE INDEX IF NOT EXISTS idx_social_pending_binds_provider_uid ON social_pending_binds(provider, social_uid)"
)
cursor.execute("CREATE INDEX IF NOT EXISTS idx_social_pending_binds_expires ON social_pending_binds(expires_at)")
conn.commit()