fix
This commit is contained in:
parent
5a2521424e
commit
809d85dff5
@ -74,7 +74,7 @@ class AppContext {
|
||||
}
|
||||
|
||||
func loginWith(token: String) async throws {
|
||||
let networkSession = try await SDLAPIClient.loginWithToken(token: token)
|
||||
let networkSession = try await AuthService.loginWithToken(token: token)
|
||||
self.loginCredit = .token(token: token, session: networkSession)
|
||||
self.selectedExitNodeIp = self.loadExitNodeIp(networkId: networkSession.networkId)
|
||||
// 将数据缓存到keychain
|
||||
@ -84,7 +84,7 @@ class AppContext {
|
||||
}
|
||||
|
||||
func loginWith(username: String, password: String) async throws {
|
||||
let networkSession = try await SDLAPIClient.loginWithAccountAndPassword(username: username, password: password)
|
||||
let networkSession = try await AuthService.loginWithAccountAndPassword(username: username, password: password)
|
||||
self.loginCredit = .accountAndPasword(account: username, password: password, session: networkSession)
|
||||
self.selectedExitNodeIp = self.loadExitNodeIp(networkId: networkSession.networkId)
|
||||
// 将数据缓存到keychain
|
||||
@ -104,7 +104,7 @@ class AppContext {
|
||||
throw AppContextError(message: "网络已经连接")
|
||||
}
|
||||
|
||||
self.networkContext = try await SDLAPIClient.connectNetwork(accesToken: session.accessToken)
|
||||
self.networkContext = try await NetworkService.connectNetwork(accesToken: session.accessToken)
|
||||
}
|
||||
|
||||
func changeExitNodeIp(exitNodeIp: String) async throws -> Data {
|
||||
|
||||
@ -7,6 +7,28 @@
|
||||
import Foundation
|
||||
|
||||
struct AuthService {
|
||||
private static let baseParams: [String: Any] = [
|
||||
"client_id": SystemConfig.getClientId(),
|
||||
"mac": SystemConfig.macAddressString(mac: SystemConfig.getMacAddress())
|
||||
]
|
||||
|
||||
// 注册会话信息
|
||||
struct RegisterSession: Codable {
|
||||
let sessionId: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case sessionId = "session_id"
|
||||
}
|
||||
}
|
||||
|
||||
// 重置会话信息
|
||||
struct ResetPasswordSession: Codable {
|
||||
let sessionId: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case sessionId = "session_id"
|
||||
}
|
||||
}
|
||||
|
||||
static func loginWithAccountAndPassword(username: String, password: String) async throws -> NetworkSession {
|
||||
var params: [String: Any] = [
|
||||
@ -31,4 +53,62 @@ struct AuthService {
|
||||
return try await SDLAPIClient.doPost(path: "/auth/token", params: params, as: NetworkSession.self)
|
||||
}
|
||||
|
||||
static func requestRegisterVerifyCode(username: String) async throws -> RegisterSession {
|
||||
var params: [String: Any] = [
|
||||
"username": username
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/register/sendVerfiyCode", params: params, as: RegisterSession.self)
|
||||
}
|
||||
|
||||
static func submitRegisterVerifyCode(sessionId: Int, verifyCode: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"code": verifyCode,
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/register/verfiyCode", params: params, as: String.self)
|
||||
}
|
||||
|
||||
static func register(sessionId: Int, password: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"password": password
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/register/submit", params: params, as: String.self)
|
||||
}
|
||||
|
||||
static func requestResetPasswordVerifyCode(username: String) async throws -> ResetPasswordSession {
|
||||
var params: [String: Any] = [
|
||||
"username": username
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/password/sendVerfiyCode", params: params, as: ResetPasswordSession.self)
|
||||
}
|
||||
|
||||
static func submitResetPasswordVerifyCode(sessionId: Int, verifyCode: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"code": verifyCode,
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/password/verfiyCode", params: params, as: String.self)
|
||||
}
|
||||
|
||||
static func resetPassword(sessionId: Int, newPassword: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"new_password": newPassword,
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/password/reset", params: params, as: String.self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,54 +19,23 @@ class RegisterModel {
|
||||
case success
|
||||
}
|
||||
|
||||
// 注册会话信息
|
||||
struct RegisterSession: Codable {
|
||||
let sessionId: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case sessionId = "session_id"
|
||||
}
|
||||
}
|
||||
|
||||
// 保存临时变量
|
||||
var username: String = ""
|
||||
var sessionId: Int = 0
|
||||
|
||||
var stage: Stage = .requestVerifyCode
|
||||
var transitionEdge: Edge = .trailing // 默认从右进入
|
||||
|
||||
private let baseParams: [String: Any] = [
|
||||
"client_id": SystemConfig.getClientId(),
|
||||
"mac": SystemConfig.macAddressString(mac: SystemConfig.getMacAddress())
|
||||
]
|
||||
|
||||
func requestVerifyCode(username: String) async throws -> RegisterSession {
|
||||
var params: [String: Any] = [
|
||||
"username": username
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/register/sendVerfiyCode", params: params, as: RegisterSession.self)
|
||||
|
||||
func requestVerifyCode(username: String) async throws -> AuthService.RegisterSession {
|
||||
return try await AuthService.requestRegisterVerifyCode(username: username)
|
||||
}
|
||||
|
||||
func submitVerifyCode(sessionId: Int, verifyCode: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"code": verifyCode,
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/register/verfiyCode", params: params, as: String.self)
|
||||
return try await AuthService.submitRegisterVerifyCode(sessionId: sessionId, verifyCode: verifyCode)
|
||||
}
|
||||
|
||||
func register(sessionId: Int, password: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"password": password
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/register/submit", params: params, as: String.self)
|
||||
return try await AuthService.register(sessionId: sessionId, password: password)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,47 +26,16 @@ class ResetPasswordModel {
|
||||
var username: String = ""
|
||||
var sessionId: Int = 0
|
||||
|
||||
// 重置会话信息
|
||||
struct ResetPasswordSession: Codable {
|
||||
let sessionId: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case sessionId = "session_id"
|
||||
}
|
||||
}
|
||||
|
||||
private let baseParams: [String: Any] = [
|
||||
"client_id": SystemConfig.getClientId(),
|
||||
"mac": SystemConfig.macAddressString(mac: SystemConfig.getMacAddress())
|
||||
]
|
||||
|
||||
func requestVerifyCode(username: String) async throws -> ResetPasswordSession {
|
||||
var params: [String: Any] = [
|
||||
"username": username
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/password/sendVerfiyCode", params: params, as: ResetPasswordSession.self)
|
||||
func requestVerifyCode(username: String) async throws -> AuthService.ResetPasswordSession {
|
||||
return try await AuthService.requestResetPasswordVerifyCode(username: username)
|
||||
}
|
||||
|
||||
func submitVerifyCode(sessionId: Int, verifyCode: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"code": verifyCode,
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/password/verfiyCode", params: params, as: String.self)
|
||||
return try await AuthService.submitResetPasswordVerifyCode(sessionId: sessionId, verifyCode: verifyCode)
|
||||
}
|
||||
|
||||
func resetPassword(sessionId: Int, newPassword: String) async throws -> String {
|
||||
var params: [String: Any] = [
|
||||
"session_id": sessionId,
|
||||
"new_password": newPassword,
|
||||
]
|
||||
params.merge(baseParams) {$1}
|
||||
|
||||
return try await SDLAPIClient.doPost(path: "/password/reset", params: params, as: String.self)
|
||||
return try await AuthService.resetPassword(sessionId: sessionId, newPassword: newPassword)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ final class NetworkModel {
|
||||
self.loadingNodeIDs.remove(nodeId)
|
||||
}
|
||||
|
||||
let resources = await SDLAPIClient.loadNodeResources(accesToken: session.accessToken, id: nodeId)
|
||||
let resources = await NetworkService.loadNodeResources(accesToken: session.accessToken, id: nodeId)
|
||||
|
||||
guard currentContextIdentity == self.contextIdentity(self.networkContext) else {
|
||||
return
|
||||
|
||||
@ -151,9 +151,9 @@ struct SettingsAboutView: View {
|
||||
Alert(title: Text("检查更新"), message: Text("您当前使用的是最新版本。"))
|
||||
}
|
||||
.task {
|
||||
self.appPoliciesInfo = try? await SDLAPIClient.appPolicies()
|
||||
self.appPoliciesInfo = try? await AppService.appPolicies()
|
||||
|
||||
_ = try? await SDLAPIClient.appCheckUpdate()
|
||||
_ = try? await AppService.appCheckUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -128,17 +128,12 @@ struct SettingsUserIssueView: View {
|
||||
isSubmitting = true
|
||||
}
|
||||
|
||||
let params: [String: Any] = [
|
||||
"access_token": self.appContext.networkSession?.accessToken ?? "",
|
||||
"contact": self.account,
|
||||
"platform": SystemConfig.systemInfo,
|
||||
"content": self.text,
|
||||
"client_id": SystemConfig.getClientId(),
|
||||
"mac": SystemConfig.macAddressString(mac: SystemConfig.getMacAddress())
|
||||
]
|
||||
|
||||
do {
|
||||
_ = try await SDLAPIClient.doPost(path: "/app/issue", params: params, as: String.self)
|
||||
_ = try await AppService.appIssue(
|
||||
accessToken: self.appContext.networkSession?.accessToken ?? "",
|
||||
contact: self.account,
|
||||
content: self.text
|
||||
)
|
||||
withAnimation(.spring(response: 0.4, dampingFraction: 0.7)) {
|
||||
isSubmitting = false
|
||||
showSuccessToast = true
|
||||
|
||||
@ -23,7 +23,7 @@ class AppUpdateManager {
|
||||
}
|
||||
|
||||
do {
|
||||
let updateInfo = try await SDLAPIClient.appCheckUpdate()
|
||||
let updateInfo = try await AppService.appCheckUpdate()
|
||||
// 核心逻辑:比对本地版本
|
||||
let currentVersion = SystemConfig.version_name
|
||||
let needsUpdate = VersionComparator.isVersion(currentVersion, olderThan: updateInfo.latestVersion)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user