fix: API field mapping, HealthKit entitlement, profile tab, forgot password
This commit is contained in:
@@ -9,6 +9,7 @@ struct LoginView: View {
|
||||
@State private var errorMessage = ""
|
||||
@State private var showPassword = false
|
||||
@State private var isRegistering = false
|
||||
@State private var showForgotSheet = false
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
@@ -83,6 +84,14 @@ struct LoginView: View {
|
||||
.cornerRadius(12)
|
||||
.disabled(isLoading || email.isEmpty || password.isEmpty)
|
||||
|
||||
if !isRegistering {
|
||||
Button(action: { showForgotSheet = true }) {
|
||||
Text("Забыли пароль?")
|
||||
.font(.footnote)
|
||||
.foregroundColor(Color(hex: "00d4aa"))
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle login/register
|
||||
HStack {
|
||||
Text(isRegistering ? "Уже есть аккаунт?" : "Нет аккаунта?")
|
||||
@@ -103,6 +112,9 @@ struct LoginView: View {
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showForgotSheet) {
|
||||
ForgotPasswordView(isPresented: $showForgotSheet)
|
||||
}
|
||||
}
|
||||
|
||||
func login() {
|
||||
@@ -144,3 +156,54 @@ struct LoginView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ForgotPasswordView
|
||||
|
||||
struct ForgotPasswordView: View {
|
||||
@Binding var isPresented: Bool
|
||||
@State private var email = ""
|
||||
@State private var isSent = false
|
||||
@State private var isLoading = false
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(hex: "0a0a1a").ignoresSafeArea()
|
||||
VStack(spacing: 24) {
|
||||
Text("Сброс пароля").font(.title2.bold()).foregroundColor(.white)
|
||||
if isSent {
|
||||
VStack(spacing: 12) {
|
||||
Text("✅").font(.system(size: 50))
|
||||
Text("Письмо отправлено!\nПроверьте \(email)")
|
||||
.foregroundColor(.white).multilineTextAlignment(.center)
|
||||
}
|
||||
Button("Закрыть") { isPresented = false }.foregroundColor(Color(hex: "00d4aa"))
|
||||
} else {
|
||||
Text("Введите email — пришлём ссылку для сброса пароля")
|
||||
.foregroundColor(.white.opacity(0.6)).multilineTextAlignment(.center)
|
||||
TextField("Email", text: $email)
|
||||
.keyboardType(.emailAddress).autocapitalization(.none)
|
||||
.padding().background(Color.white.opacity(0.1)).cornerRadius(12).foregroundColor(.white)
|
||||
Button(action: send) {
|
||||
if isLoading { ProgressView().tint(.black) }
|
||||
else { Text("Отправить").font(.headline).foregroundColor(.black) }
|
||||
}
|
||||
.frame(maxWidth: .infinity).padding()
|
||||
.background(Color(hex: "00d4aa")).cornerRadius(12).disabled(email.isEmpty || isLoading)
|
||||
Button("Отмена") { isPresented = false }.foregroundColor(.white.opacity(0.5))
|
||||
}
|
||||
}.padding(32)
|
||||
}
|
||||
}
|
||||
|
||||
func send() {
|
||||
isLoading = true
|
||||
Task {
|
||||
var req = URLRequest(url: URL(string: "https://api.digital-home.site/auth/forgot-password")!)
|
||||
req.httpMethod = "POST"
|
||||
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
req.httpBody = try? JSONEncoder().encode(["email": email])
|
||||
_ = try? await URLSession.shared.data(for: req)
|
||||
await MainActor.run { isSent = true; isLoading = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user