57 lines
1.6 KiB
Swift
57 lines
1.6 KiB
Swift
//
|
|
// LoginState.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/1/16.
|
|
//
|
|
|
|
import Foundation
|
|
import Observation
|
|
|
|
@Observable
|
|
class ResetPasswordModel {
|
|
|
|
enum Stage {
|
|
case requestVerifyCode
|
|
case submitVerifyCode(username: String)
|
|
case resetPassword(username: String)
|
|
}
|
|
|
|
var stage: Stage = .requestVerifyCode
|
|
|
|
private let baseParams: [String: Any] = [
|
|
"client_id": SystemConfig.getClientId(),
|
|
"mac": SystemConfig.macAddressString(mac: SystemConfig.getMacAddress())
|
|
]
|
|
|
|
func requestVerifyCode(username: String) async throws -> String {
|
|
var params: [String: Any] = [
|
|
"username": username
|
|
]
|
|
params.merge(baseParams) {$1}
|
|
|
|
return try await SDLAPIClient.doPost(path: "/auth/sendVerifyCode", params: params, as: String.self)
|
|
}
|
|
|
|
func submitVerifyCode(username: String, verifyCode: String) async throws -> String {
|
|
var params: [String: Any] = [
|
|
"username": username,
|
|
"verify_code": verifyCode,
|
|
]
|
|
params.merge(baseParams) {$1}
|
|
|
|
return try await SDLAPIClient.doPost(path: "/auth/submitVerifyCode", params: params, as: String.self)
|
|
}
|
|
|
|
func resetPassword(username: String, password: String) async throws -> String {
|
|
var params: [String: Any] = [
|
|
"username": username,
|
|
"password": password,
|
|
]
|
|
params.merge(baseParams) {$1}
|
|
|
|
return try await SDLAPIClient.doPost(path: "/auth/resetPassword", params: params, as: String.self)
|
|
}
|
|
|
|
}
|