-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLogInView.swift
84 lines (68 loc) · 2.74 KB
/
LogInView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// LogInView.swift
// MobileAcebook
//
// Created by Ami Day on 09/10/2023.
//
import Foundation
import SwiftUI
import Combine
struct LogInView: View {
@State private var userModel = User(email: "", password: "")
@State private var loggedIn = false
private func onEmailInputChanged(changedEmail: String) {
userModel.email = changedEmail
print("changed email: \(userModel.email)")
}
private func onPasswordInputChanged(changedPassword: String) {
userModel.password = changedPassword
print("changed password: \(userModel.password)")
}
let authenticationService = AuthenticationService()
var body: some View {
NavigationView {
ZStack {
VStack {
Spacer()
Image("makers-logo")
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.accessibilityIdentifier("makers-logo")
Spacer()
LabeledContent {
TextField("Email", text: $userModel.email).textInputAutocapitalization(.never)
} label: {
Text("Email")
}.onChange(of: userModel.email, perform: onEmailInputChanged)
LabeledContent {
TextField("Password", text: $userModel.password).textInputAutocapitalization(.never)
} label: {
Text("Password")
}.onChange(of: userModel.password, perform: onPasswordInputChanged)
Button(action: {
var response = authenticationService.login(user: userModel) { isSuccess in
if isSuccess {
loggedIn = true
}
}
}) {
Text("Login")
}
.accessibilityIdentifier("LoginButton")
NavigationLink(destination: PostsView().navigationBarBackButtonHidden(true), isActive: $loggedIn) { EmptyView() }
Button("Sign Up") {
// TODO: sign up logic
}
.accessibilityIdentifier("signUpButton")
}
Spacer()
}
}
}
struct LogInView_Previews: PreviewProvider {
static var previews: some View {
LogInView()
}
}
}