fix: use v9 store status for deregistration login

This commit is contained in:
2026-08-31 16:36:20 +08:00
parent 4444d328df
commit b8343ad9eb
8 changed files with 194 additions and 11 deletions
@@ -164,6 +164,16 @@ final class AccountSelectionViewController: UIViewController, UITableViewDelegat
@objc private func confirmTapped() {
guard canConfirm, let selectedAccount else { return }
if selectedAccount.requiresDeregistrationConfirmation {
present(
makeDeregistrationLoginAlert(
account: selectedAccount,
onConfirm: { [weak self] in self?.onConfirm(selectedAccount) }
),
animated: true
)
return
}
onConfirm(selectedAccount)
}
@@ -177,6 +187,23 @@ final class AccountSelectionViewController: UIViewController, UITableViewDelegat
}
}
/// 创建冷静期账号登录确认弹窗,确认后 `set-user` 会由后端自动撤销原注销申请。
func makeDeregistrationLoginAlert(
account: AccountSwitchAccount,
onConfirm: @escaping () -> Void
) -> UIAlertController {
let accountName = account.title.trimmingCharacters(in: .whitespacesAndNewlines)
let displayName = accountName.isEmpty ? "该门店账号" : "“\(accountName)”"
let alert = UIAlertController(
title: "该账号正在注销",
message: "\(displayName)已提交注销申请,目前处于冷静期。确认登录后,将自动撤销之前的注销申请。",
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: "暂不登录", style: .cancel))
alert.addAction(UIAlertAction(title: "确认登录", style: .default) { _ in onConfirm() })
return alert
}
/// 账号选择列表 Cell。
private final class AccountSelectionCell: UITableViewCell {
static let reuseIdentifier = "AccountSelectionCell"
@@ -290,6 +290,8 @@ final class LoginViewController: BaseViewController {
completeLogin(with: response, account: account)
case .needsAccountSelection:
break
case let .needsDeregistrationConfirmation(confirmation):
presentDeregistrationLoginConfirmation(confirmation)
}
} catch is CancellationError {
return
@@ -335,6 +337,31 @@ final class LoginViewController: BaseViewController {
}
}
private func presentDeregistrationLoginConfirmation(_ confirmation: DeregistrationLoginConfirmation) {
let alert = makeDeregistrationLoginAlert(
account: confirmation.account,
onConfirm: { [weak self] in
self?.confirmDeregistrationLogin(confirmation)
}
)
present(alert, animated: true)
}
private func confirmDeregistrationLogin(_ confirmation: DeregistrationLoginConfirmation) {
Task {
showLoading()
defer { hideLoading() }
do {
let response = try await viewModel.confirmDeregistrationLogin(confirmation, authAPI: authAPI)
completeLogin(with: response, account: confirmation.account)
} catch is CancellationError {
return
} catch {
showToast(error.localizedDescription)
}
}
}
private func completeLogin(with response: V9AuthResponse, account: AccountSwitchAccount) {
AuthSessionHelper.completeLogin(
with: response,
+28 -3
View File
@@ -130,6 +130,28 @@ final class LoginViewModel {
guard let payload = pendingAccountSelection, payload.hasTempToken else {
throw LoginFlowError.missingToken
}
let response = try await setUser(account, tempToken: payload.tempToken, authAPI: authAPI)
pendingAccountSelection = nil
notifyStateChange()
return response
}
/// 用户确认登录冷静期账号后继续换取正式 token;`set-user` 成功即由后端撤销原注销申请。
func confirmDeregistrationLogin(
_ confirmation: DeregistrationLoginConfirmation,
authAPI: AuthAPI
) async throws -> V9AuthResponse {
try await setUser(confirmation.account, tempToken: confirmation.tempToken, authAPI: authAPI)
}
private func setUser(
_ account: AccountSwitchAccount,
tempToken: String,
authAPI: AuthAPI
) async throws -> V9AuthResponse {
guard !tempToken.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
throw LoginFlowError.missingToken
}
guard account.businessUserId > 0 else {
throw LoginFlowError.invalidAccount
}
@@ -144,12 +166,10 @@ final class LoginViewModel {
notifyStateChange()
}
let response = try await authAPI.setUser(account.toSetUserRequest(), tokenOverride: payload.tempToken)
let response = try await authAPI.setUser(account.toSetUserRequest(), tokenOverride: tempToken)
guard !response.token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
throw LoginFlowError.missingToken
}
pendingAccountSelection = nil
notifyStateChange()
return response
}
@@ -178,6 +198,11 @@ final class LoginViewModel {
}
if accounts.count == 1, let account = accounts.first {
if account.requiresDeregistrationConfirmation {
return .needsDeregistrationConfirmation(
DeregistrationLoginConfirmation(tempToken: token, account: account)
)
}
let finalResponse = try await authAPI.setUser(account.toSetUserRequest(), tokenOverride: token)
guard !finalResponse.token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
throw LoginFlowError.missingToken