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
154
Sources/ManaAuthUI/Account/ManaChangeEmailView.swift
Normal file
154
Sources/ManaAuthUI/Account/ManaChangeEmailView.swift
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
import ManaCore
|
||||
import Observation
|
||||
import SwiftUI
|
||||
|
||||
/// Account-Sheet: Email-Adresse ändern.
|
||||
///
|
||||
/// Schickt eine Verifikations-Mail an die **neue** Adresse. Bis der
|
||||
/// User klickt, bleibt die alte Email aktiv.
|
||||
///
|
||||
/// **Server-Limitation (v0.1.0):** funktioniert erst nach Phase-3-
|
||||
/// Server-PR (`mana-auth` braucht Bearer-Plugin). Die UI ist fertig,
|
||||
/// der Wire ist fertig, der Server muss nachziehen.
|
||||
public struct ManaChangeEmailView: View {
|
||||
@Environment(\.manaBrand) private var brand
|
||||
@State private var model: ChangeEmailViewModel
|
||||
private let onDone: () -> Void
|
||||
|
||||
public init(auth: AuthClient, callbackUniversalLink: URL? = nil, onDone: @escaping () -> Void) {
|
||||
_model = State(initialValue: ChangeEmailViewModel(
|
||||
auth: auth,
|
||||
callbackUniversalLink: callbackUniversalLink
|
||||
))
|
||||
self.onDone = onDone
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
switch model.status {
|
||||
case .done:
|
||||
doneView
|
||||
default:
|
||||
formView
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var formView: some View {
|
||||
ManaAuthScaffold(showsHeader: false) {
|
||||
VStack(spacing: 16) {
|
||||
Text("Email ändern")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Text(
|
||||
"Wir schicken eine Bestätigungs-Mail an die neue Adresse. "
|
||||
+ "Bis du klickst, bleibt die alte Email aktiv."
|
||||
)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
ManaTextField("Neue Email", text: $model.newEmail)
|
||||
.manaEmailField()
|
||||
|
||||
ManaPrimaryButton(
|
||||
"Email ändern",
|
||||
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(showsHeader: false) {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "envelope.fill")
|
||||
.font(.system(size: 56, weight: .light))
|
||||
.foregroundStyle(brand.primary)
|
||||
|
||||
Text("Bestätigungs-Mail verschickt")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
|
||||
Text(
|
||||
"Klicke den Link in der Mail, um die Änderung zu bestätigen."
|
||||
)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
ManaPrimaryButton("Fertig") { onDone() }
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Observable
|
||||
final class ChangeEmailViewModel {
|
||||
enum Status: Equatable {
|
||||
case idle
|
||||
case submitting
|
||||
case done
|
||||
case error(String)
|
||||
}
|
||||
|
||||
var newEmail: String = ""
|
||||
private(set) var status: Status = .idle
|
||||
|
||||
private let auth: AuthClient
|
||||
private let callbackUniversalLink: URL?
|
||||
|
||||
init(auth: AuthClient, callbackUniversalLink: URL?) {
|
||||
self.auth = auth
|
||||
self.callbackUniversalLink = callbackUniversalLink
|
||||
}
|
||||
|
||||
var canSubmit: Bool {
|
||||
guard !newEmail.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return false }
|
||||
if case .submitting = status { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
var isSubmitting: Bool {
|
||||
if case .submitting = status { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
func submit() async {
|
||||
let trimmed = newEmail.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return }
|
||||
|
||||
status = .submitting
|
||||
do {
|
||||
try await auth.changeEmail(newEmail: trimmed, callbackUniversalLink: callbackUniversalLink)
|
||||
status = .done
|
||||
} catch let error as AuthError {
|
||||
status = .error(error.errorDescription ?? "Änderung fehlgeschlagen")
|
||||
} catch {
|
||||
status = .error(String(describing: error))
|
||||
}
|
||||
}
|
||||
}
|
||||
168
Sources/ManaAuthUI/Account/ManaChangePasswordView.swift
Normal file
168
Sources/ManaAuthUI/Account/ManaChangePasswordView.swift
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
import ManaCore
|
||||
import Observation
|
||||
import SwiftUI
|
||||
|
||||
/// Account-Sheet: Passwort ändern. Erfordert aktuelles Passwort (Re-Auth).
|
||||
///
|
||||
/// **Server-Limitation (v0.1.0):** funktioniert erst nach Phase-3-
|
||||
/// Server-PR (`mana-auth` braucht Bearer-Plugin).
|
||||
public struct ManaChangePasswordView: View {
|
||||
@Environment(\.manaBrand) private var brand
|
||||
@State private var model: ChangePasswordViewModel
|
||||
private let onDone: () -> Void
|
||||
|
||||
public init(auth: AuthClient, onDone: @escaping () -> Void) {
|
||||
_model = State(initialValue: ChangePasswordViewModel(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(showsHeader: false) {
|
||||
VStack(spacing: 16) {
|
||||
Text("Passwort ändern")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
ManaSecureField(
|
||||
"Aktuelles Passwort",
|
||||
text: $model.currentPassword,
|
||||
textContentType: .password
|
||||
)
|
||||
|
||||
ManaSecureField(
|
||||
"Neues Passwort",
|
||||
text: $model.newPassword,
|
||||
textContentType: .newPassword
|
||||
)
|
||||
|
||||
ManaSecureField(
|
||||
"Neues 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 ändern",
|
||||
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(showsHeader: false) {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "lock.rotation")
|
||||
.font(.system(size: 56, weight: .light))
|
||||
.foregroundStyle(brand.success)
|
||||
|
||||
Text("Passwort geändert")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
|
||||
ManaPrimaryButton("Fertig") { onDone() }
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Observable
|
||||
final class ChangePasswordViewModel {
|
||||
enum Status: Equatable {
|
||||
case idle
|
||||
case submitting
|
||||
case done
|
||||
case error(String)
|
||||
}
|
||||
|
||||
var currentPassword: String = ""
|
||||
var newPassword: String = ""
|
||||
var confirmPassword: String = ""
|
||||
private(set) var status: Status = .idle
|
||||
|
||||
private let auth: AuthClient
|
||||
|
||||
init(auth: AuthClient) {
|
||||
self.auth = auth
|
||||
}
|
||||
|
||||
var canSubmit: Bool {
|
||||
guard !currentPassword.isEmpty, !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
|
||||
}
|
||||
|
||||
var isSubmitting: Bool {
|
||||
if case .submitting = status { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
var validationHint: String? {
|
||||
if !newPassword.isEmpty, newPassword.count < 8 {
|
||||
return "Neues Passwort muss mindestens 8 Zeichen lang sein."
|
||||
}
|
||||
if !confirmPassword.isEmpty, newPassword != confirmPassword {
|
||||
return "Die neuen Passwörter stimmen nicht überein."
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func submit() async {
|
||||
guard canSubmit else { return }
|
||||
|
||||
status = .submitting
|
||||
do {
|
||||
try await auth.changePassword(currentPassword: currentPassword, newPassword: newPassword)
|
||||
currentPassword = ""
|
||||
newPassword = ""
|
||||
confirmPassword = ""
|
||||
status = .done
|
||||
} catch let error as AuthError {
|
||||
status = .error(error.errorDescription ?? "Änderung fehlgeschlagen")
|
||||
} catch {
|
||||
status = .error(String(describing: error))
|
||||
}
|
||||
}
|
||||
}
|
||||
175
Sources/ManaAuthUI/Account/ManaDeleteAccountView.swift
Normal file
175
Sources/ManaAuthUI/Account/ManaDeleteAccountView.swift
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
import ManaCore
|
||||
import Observation
|
||||
import SwiftUI
|
||||
|
||||
/// Account-Sheet: Account vollständig löschen.
|
||||
///
|
||||
/// **App-Store-Guideline 5.1.1(v):** jede App mit Account-Erstellung
|
||||
/// MUSS eine Account-Löschung anbieten, die nicht über das Web läuft.
|
||||
/// Dieser View deckt das Pflicht-Surface ab.
|
||||
///
|
||||
/// **Server-Limitation (v0.1.0):** funktioniert erst nach Phase-3-
|
||||
/// Server-PR (`mana-auth` braucht Bearer-Plugin). Die UI ist fertig,
|
||||
/// der Wire ist fertig.
|
||||
///
|
||||
/// **UX:** zweistufig — User muss ein Bestätigungs-Wort tippen
|
||||
/// (zusätzlich zur Passwort-Eingabe), bevor der destruktive Button
|
||||
/// klickbar wird. Verhindert Fehlklicks auf einem Setting-Screen.
|
||||
public struct ManaDeleteAccountView: View {
|
||||
@Environment(\.manaBrand) private var brand
|
||||
@State private var model: DeleteAccountViewModel
|
||||
private let onDone: () -> Void
|
||||
|
||||
public init(auth: AuthClient, onDone: @escaping () -> Void) {
|
||||
_model = State(initialValue: DeleteAccountViewModel(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(showsHeader: false) {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "exclamationmark.triangle.fill")
|
||||
.font(.system(size: 48, weight: .medium))
|
||||
.foregroundStyle(brand.error)
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
Text("Account löschen")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Text(
|
||||
"Das ist endgültig. Alle deine Daten werden auf allen Servern gelöscht — "
|
||||
+ "Decks, Notizen, Aufnahmen, Verläufe, alles. Kein Restore möglich."
|
||||
)
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
|
||||
Text("Tippe **LÖSCHEN** zur Bestätigung:")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.foreground)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.top, 4)
|
||||
|
||||
ManaTextField("LÖSCHEN", text: $model.confirmationText)
|
||||
.autocorrectionDisabled()
|
||||
#if os(iOS)
|
||||
.textInputAutocapitalization(.characters)
|
||||
#endif
|
||||
|
||||
ManaSecureField(
|
||||
"Passwort",
|
||||
text: $model.password,
|
||||
textContentType: .password
|
||||
)
|
||||
|
||||
ManaPrimaryButton(
|
||||
"Account endgültig löschen",
|
||||
role: .destructive,
|
||||
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(showsHeader: false) {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "trash.fill")
|
||||
.font(.system(size: 56, weight: .light))
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
|
||||
Text("Account gelöscht")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(brand.foreground)
|
||||
|
||||
Text("Schade dass du gehst. Auf Wiedersehen.")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(brand.mutedForeground)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
ManaPrimaryButton("Schließen") { onDone() }
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Observable
|
||||
final class DeleteAccountViewModel {
|
||||
enum Status: Equatable {
|
||||
case idle
|
||||
case submitting
|
||||
case done
|
||||
case error(String)
|
||||
}
|
||||
|
||||
var confirmationText: String = ""
|
||||
var password: String = ""
|
||||
private(set) var status: Status = .idle
|
||||
|
||||
private let auth: AuthClient
|
||||
|
||||
init(auth: AuthClient) {
|
||||
self.auth = auth
|
||||
}
|
||||
|
||||
var canSubmit: Bool {
|
||||
guard confirmationText.uppercased() == "LÖSCHEN" else { return false }
|
||||
guard !password.isEmpty else { return false }
|
||||
if case .submitting = status { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
var isSubmitting: Bool {
|
||||
if case .submitting = status { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
func submit() async {
|
||||
guard canSubmit else { return }
|
||||
|
||||
status = .submitting
|
||||
do {
|
||||
try await auth.deleteAccount(password: password)
|
||||
password = ""
|
||||
confirmationText = ""
|
||||
status = .done
|
||||
} catch let error as AuthError {
|
||||
status = .error(error.errorDescription ?? "Löschen fehlgeschlagen")
|
||||
} catch {
|
||||
status = .error(String(describing: error))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue