59 lines
1.7 KiB
Swift
59 lines
1.7 KiB
Swift
//
|
|
// LoginState.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/1/16.
|
|
//
|
|
|
|
import Foundation
|
|
import Observation
|
|
|
|
@Observable
|
|
class RegisterModel {
|
|
|
|
enum Stage {
|
|
case requestVerifyCode(username: String?)
|
|
case submitVerifyCode(username: String)
|
|
case setPassword(username: String)
|
|
}
|
|
|
|
var stage: Stage = .requestVerifyCode(username: nil)
|
|
|
|
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 register(username: String, password: String) async throws -> String {
|
|
var params: [String: Any] = [
|
|
"username": username,
|
|
"password": password,
|
|
"version": SystemConfig.version_name,
|
|
"system": SystemConfig.systemInfo
|
|
]
|
|
params.merge(baseParams) {$1}
|
|
|
|
return try await SDLAPIClient.doPost(path: "/auth/register", params: params, as: String.self)
|
|
}
|
|
|
|
}
|