- 新增完整的XuqmGroup部署文档,包含服务器配置、Docker Compose部署策略 - 更新SDK API重设计规范至V2.0,统一各端SDK初始化和登录接口 - 添加安全设计规范文档,涵盖密码安全、AppSecret验证等内容 - 新增离线推送架构设计文档,定义厂商推送集成方案 - 重构SDK登录流程,统一使用userId + userSig鉴权模式 - 移除dbName等外部配置参数,实现零感知平台地址配置 - 完善部署架构图和配置示例文件
50 行
1.6 KiB
Swift
50 行
1.6 KiB
Swift
import Foundation
|
|
import XuqmSDK
|
|
|
|
@MainActor
|
|
final class AuthViewModel: ObservableObject {
|
|
@Published var state: LoginState = .idle
|
|
@Published var currentUserId: String = ""
|
|
@Published var currentNickname: String = ""
|
|
|
|
private struct DemoLoginResponse: Decodable, Sendable {
|
|
let imToken: String
|
|
let profile: DemoProfile
|
|
struct DemoProfile: Decodable, Sendable {
|
|
let userId: String
|
|
}
|
|
}
|
|
|
|
func login(userId: String, password: String) {
|
|
guard !userId.isEmpty, !password.isEmpty else {
|
|
state = .error("请输入用户 ID 和密码")
|
|
return
|
|
}
|
|
state = .loading
|
|
Task {
|
|
do {
|
|
let config = XuqmSDK.shared.requireConfig()
|
|
let res: DemoLoginResponse = try await ApiClient.shared.request(
|
|
path: "/api/demo/auth/login",
|
|
method: "POST",
|
|
queryItems: [URLQueryItem(name: "appId", value: config.appId)],
|
|
body: ["appId": config.appId, "userId": userId, "password": password]
|
|
)
|
|
await XuqmSDK.shared.login(userId: res.profile.userId, userSig: res.imToken)
|
|
currentUserId = res.profile.userId
|
|
currentNickname = res.profile.userId
|
|
state = .success
|
|
} catch {
|
|
state = .error(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
|
|
func logout() {
|
|
Task { await XuqmSDK.shared.logout() }
|
|
currentUserId = ""
|
|
currentNickname = ""
|
|
state = .idle
|
|
}
|
|
}
|