v0.1.0 — initialer Sprint, vollständige Auth-Reise als SwiftUI
Phase 2 aus dem Native-Auth-Vollausbau-Plan (Option A, siehe ../mana/docs/MANA_SWIFT.md). Entstanden weil drei Apps fast- byte-identische LoginView.swift hatten und Sign-Up/Forgot-PW komplett fehlten. ManaAuthUI-Library mit: - ManaBrandConfig — App-injizierte Theme-Werte (forest für Cards/ Manaspur, mana-default für Memoro), Environment-Key, View-Modifier - Base-Components: ManaAuthScaffold, ManaPrimaryButton, ManaTextField, ManaSecureField + .manaEmailField()-Modifier - ManaLoginView + LoginViewModel — Email/PW-Login, schaltet bei AuthError.emailNotVerified automatisch auf ManaEmailVerifyGateView - ManaSignUpView + SignUpViewModel — Email/Name/PW + awaiting- Verification-Hinweis-Screen - ManaEmailVerifyGateView + ViewModel — Resend-Verification - ManaForgotPasswordView + ViewModel — Reset-Mail anfordern (immer generischer Hinweis, User-Enumeration-Schutz) - ManaResetPasswordView + ViewModel — neues PW mit Token aus Universal-Link - ManaChangeEmailView, ManaChangePasswordView, ManaDeleteAccountView + internal ViewModels — Account-Bausteine - ManaDeleteAccountView ist zweistufig (Bestätigungs-Wort tippen + Passwort) → App-Store-Guideline 5.1.1(v) Pflicht-Surface 26/26 ViewModel-Tests grün via per-test-ID URLProtocol-Routing (löst Parallel-Pollution zwischen .serialized Suites). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
0a2cb349b4
29 changed files with 2614 additions and 0 deletions
60
Sources/ManaAuthUI/Reset/ForgotPasswordViewModel.swift
Normal file
60
Sources/ManaAuthUI/Reset/ForgotPasswordViewModel.swift
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import Foundation
|
||||
import ManaCore
|
||||
import Observation
|
||||
|
||||
/// State-Maschine für ``ManaForgotPasswordView``. Wraps
|
||||
/// `AuthClient.forgotPassword`.
|
||||
///
|
||||
/// **User-Enumeration-Schutz:** Server antwortet immer 200,
|
||||
/// unabhängig davon ob die Email existiert. Die UI meldet daher
|
||||
/// generisch ("Wenn dein Account existiert, ist eine Mail unterwegs").
|
||||
@MainActor
|
||||
@Observable
|
||||
public final class ForgotPasswordViewModel {
|
||||
public enum Status: Equatable, Sendable {
|
||||
case idle
|
||||
case sending
|
||||
case sent
|
||||
case error(String)
|
||||
}
|
||||
|
||||
public var email: String = ""
|
||||
public private(set) var status: Status = .idle
|
||||
|
||||
private let auth: AuthClient
|
||||
private let resetUniversalLink: URL
|
||||
|
||||
/// - Parameter resetUniversalLink: Universal-Link der App für den
|
||||
/// Reset-Klick aus der Email. Z.B.
|
||||
/// `URL(string: "https://cardecky.mana.how/auth/reset")!`.
|
||||
public init(auth: AuthClient, resetUniversalLink: URL) {
|
||||
self.auth = auth
|
||||
self.resetUniversalLink = resetUniversalLink
|
||||
}
|
||||
|
||||
public var canSubmit: Bool {
|
||||
guard !email.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return false }
|
||||
if case .sending = status { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
public var isSending: Bool {
|
||||
if case .sending = status { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public func submit() async {
|
||||
let trimmed = email.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return }
|
||||
|
||||
status = .sending
|
||||
do {
|
||||
try await auth.forgotPassword(email: trimmed, resetUniversalLink: resetUniversalLink)
|
||||
status = .sent
|
||||
} catch let error as AuthError {
|
||||
status = .error(error.errorDescription ?? "Senden fehlgeschlagen")
|
||||
} catch {
|
||||
status = .error(String(describing: error))
|
||||
}
|
||||
}
|
||||
}
|
||||
111
Sources/ManaAuthUI/Reset/ManaForgotPasswordView.swift
Normal file
111
Sources/ManaAuthUI/Reset/ManaForgotPasswordView.swift
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
import ManaCore
|
||||
import SwiftUI
|
||||
|
||||
/// "Passwort vergessen"-Screen: Email-Eingabe + Submit-Button.
|
||||
/// Bei Erfolg zeigt der View einen generischen Hinweis (User-
|
||||
/// Enumeration-Schutz).
|
||||
public struct ManaForgotPasswordView: View {
|
||||
@Environment(\.manaBrand) private var brand
|
||||
@State private var model: ForgotPasswordViewModel
|
||||
private let onDone: () -> Void
|
||||
|
||||
/// - Parameters:
|
||||
/// - auth: gemeinsamer `AuthClient` der App.
|
||||
/// - resetUniversalLink: Universal-Link für den Reset-Klick
|
||||
/// aus der Email (z.B. `https://cardecky.mana.how/auth/reset`).
|
||||
/// - onDone: Callback wenn der User "Fertig" auf dem Hinweis-
|
||||
/// Screen drückt — Apps schließen das Sheet.
|
||||
public init(
|
||||
auth: AuthClient,
|
||||
resetUniversalLink: URL,
|
||||
onDone: @escaping () -> Void
|
||||
) {
|
||||
_model = State(initialValue: ForgotPasswordViewModel(
|
||||
auth: auth,
|
||||
resetUniversalLink: resetUniversalLink
|
||||
))
|
||||
self.onDone = onDone
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
switch model.status {
|
||||
case .sent:
|
||||
sentView
|
||||
default:
|
||||
formView
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var formView: some View {
|
||||
ManaAuthScaffold {
|
||||
VStack(spacing: 16) {
|
||||
Text("Passwort vergessen?")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Text("Gib deine Email-Adresse ein. Wir schicken dir einen Link zum Zurücksetzen.")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
ManaTextField("Email", text: $model.email)
|
||||
.manaEmailField()
|
||||
|
||||
ManaPrimaryButton(
|
||||
"Reset-Link senden",
|
||||
isLoading: model.isSending,
|
||||
isEnabled: model.canSubmit
|
||||
) {
|
||||
Task { await model.submit() }
|
||||
}
|
||||
|
||||
if case let .error(message) = model.status {
|
||||
Text(message)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(brand.error)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}
|
||||
.padding(.top, 16)
|
||||
|
||||
Button("Abbrechen", action: onDone)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.padding(.top, 12)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var sentView: some View {
|
||||
ManaAuthScaffold {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "envelope.fill")
|
||||
.font(.system(size: 56, weight: .light))
|
||||
.foregroundStyle(brand.primary)
|
||||
|
||||
Text("Schau in deinen Posteingang")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
Text(
|
||||
"Wenn ein Account für diese Email existiert, ist eine Mail mit "
|
||||
+ "einem Reset-Link unterwegs."
|
||||
)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
ManaPrimaryButton("Fertig") {
|
||||
onDone()
|
||||
}
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
127
Sources/ManaAuthUI/Reset/ManaResetPasswordView.swift
Normal file
127
Sources/ManaAuthUI/Reset/ManaResetPasswordView.swift
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import ManaCore
|
||||
import SwiftUI
|
||||
|
||||
/// "Neues Passwort setzen"-Screen. Wird aus dem Universal-Link-Handler
|
||||
/// der App aufgerufen, sobald der User den Reset-Link aus der Email
|
||||
/// geklickt hat — die App extrahiert `?token=…` aus der URL und
|
||||
/// präsentiert diesen View.
|
||||
///
|
||||
/// ```swift
|
||||
/// // In App.handleUniversalLink:
|
||||
/// if url.path == "/auth/reset", let token = url.queryToken {
|
||||
/// showResetPasswordSheet(token: token)
|
||||
/// }
|
||||
/// ```
|
||||
public struct ManaResetPasswordView: View {
|
||||
@Environment(\.manaBrand) private var brand
|
||||
@State private var model: ResetPasswordViewModel
|
||||
private let onDone: () -> Void
|
||||
|
||||
/// - Parameters:
|
||||
/// - token: Reset-Token aus der Email (`?token=…`).
|
||||
/// - auth: gemeinsamer `AuthClient` der App.
|
||||
/// - onDone: Callback bei Erfolg oder Abbruch — App schließt
|
||||
/// den Sheet und navigiert zurück zum Login.
|
||||
public init(
|
||||
token: String,
|
||||
auth: AuthClient,
|
||||
onDone: @escaping () -> Void
|
||||
) {
|
||||
_model = State(initialValue: ResetPasswordViewModel(token: token, auth: auth))
|
||||
self.onDone = onDone
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
switch model.status {
|
||||
case .done:
|
||||
doneView
|
||||
default:
|
||||
formView
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var formView: some View {
|
||||
ManaAuthScaffold {
|
||||
VStack(spacing: 16) {
|
||||
Text("Neues Passwort")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Text("Wähle ein neues Passwort. Mindestens 8 Zeichen.")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
ManaSecureField(
|
||||
"Neues Passwort",
|
||||
text: $model.newPassword,
|
||||
textContentType: .newPassword
|
||||
)
|
||||
|
||||
ManaSecureField(
|
||||
"Passwort bestätigen",
|
||||
text: $model.confirmPassword,
|
||||
textContentType: .newPassword
|
||||
)
|
||||
|
||||
if let hint = model.validationHint {
|
||||
Text(hint)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
ManaPrimaryButton(
|
||||
"Passwort setzen",
|
||||
isLoading: model.isSubmitting,
|
||||
isEnabled: model.canSubmit
|
||||
) {
|
||||
Task { await model.submit() }
|
||||
}
|
||||
|
||||
if case let .error(message) = model.status {
|
||||
Text(message)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(brand.error)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}
|
||||
.padding(.top, 16)
|
||||
|
||||
Button("Abbrechen", action: onDone)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.padding(.top, 12)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var doneView: some View {
|
||||
ManaAuthScaffold {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "lock.open.fill")
|
||||
.font(.system(size: 56, weight: .light))
|
||||
.foregroundStyle(brand.success)
|
||||
|
||||
Text("Passwort aktualisiert")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
|
||||
Text("Du kannst dich jetzt mit deinem neuen Passwort anmelden.")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
ManaPrimaryButton("Zum Login") {
|
||||
onDone()
|
||||
}
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Sources/ManaAuthUI/Reset/ResetPasswordViewModel.swift
Normal file
69
Sources/ManaAuthUI/Reset/ResetPasswordViewModel.swift
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import Foundation
|
||||
import ManaCore
|
||||
import Observation
|
||||
|
||||
/// State-Maschine für ``ManaResetPasswordView``. Wraps
|
||||
/// `AuthClient.resetPassword`. Wird aus dem Universal-Link-Handler
|
||||
/// der App aufgerufen mit dem Token aus dem `?token=…`-Query-Param.
|
||||
@MainActor
|
||||
@Observable
|
||||
public final class ResetPasswordViewModel {
|
||||
public enum Status: Equatable, Sendable {
|
||||
case idle
|
||||
case submitting
|
||||
case done
|
||||
case error(String)
|
||||
}
|
||||
|
||||
public let token: String
|
||||
public var newPassword: String = ""
|
||||
public var confirmPassword: String = ""
|
||||
public private(set) var status: Status = .idle
|
||||
|
||||
private let auth: AuthClient
|
||||
|
||||
public init(token: String, auth: AuthClient) {
|
||||
self.token = token
|
||||
self.auth = auth
|
||||
}
|
||||
|
||||
public var canSubmit: Bool {
|
||||
guard !newPassword.isEmpty, !confirmPassword.isEmpty else { return false }
|
||||
guard newPassword == confirmPassword else { return false }
|
||||
guard newPassword.count >= 8 else { return false }
|
||||
if case .submitting = status { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
public var isSubmitting: Bool {
|
||||
if case .submitting = status { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
/// UI-Hint je nach Eingabe-Status. Nil = alles ok oder noch leer.
|
||||
public var validationHint: String? {
|
||||
if !newPassword.isEmpty, newPassword.count < 8 {
|
||||
return "Passwort muss mindestens 8 Zeichen lang sein."
|
||||
}
|
||||
if !confirmPassword.isEmpty, newPassword != confirmPassword {
|
||||
return "Die Passwörter stimmen nicht überein."
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public func submit() async {
|
||||
guard canSubmit else { return }
|
||||
|
||||
status = .submitting
|
||||
do {
|
||||
try await auth.resetPassword(token: token, newPassword: newPassword)
|
||||
newPassword = ""
|
||||
confirmPassword = ""
|
||||
status = .done
|
||||
} catch let error as AuthError {
|
||||
status = .error(error.errorDescription ?? "Reset fehlgeschlagen")
|
||||
} catch {
|
||||
status = .error(String(describing: error))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue