添加网络层并接入 v9 登录流程及单元测试
This commit is contained in:
26
suixinkan/Features/Auth/AuthSessionHelper.swift
Normal file
26
suixinkan/Features/Auth/AuthSessionHelper.swift
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// AuthSessionHelper.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 登录会话辅助工具,负责写入本地 Token 并广播登录成功通知。
|
||||
enum AuthSessionHelper {
|
||||
|
||||
/// 完成登录,保存 Token 与用户偏好,并通知 SceneDelegate 切换根页面。
|
||||
static func completeLogin(
|
||||
with response: V9AuthResponse,
|
||||
username: String,
|
||||
privacyAgreementAccepted: Bool
|
||||
) {
|
||||
let token = response.token.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !token.isEmpty else { return }
|
||||
|
||||
AppStore.shared.saveToken(token)
|
||||
AppStore.shared.lastLoginUsername = username
|
||||
AppStore.shared.privacyAgreementAccepted = privacyAgreementAccepted
|
||||
|
||||
NotificationCenter.default.post(name: NotificationName.userDidLogin, object: nil)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user