Created
January 4, 2022 20:34
-
-
Save mitnick78/60cd84b128e81dee28d06d5153addf97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Login: View { | |
@StateObject var viewModel: AuthViewModel = AuthViewModel() | |
// Mark: FaceID Propreties | |
@State var useFaceID: Bool = false | |
var body: some View { | |
ZStack { | |
Image("test") | |
.resizable() | |
VStack { | |
Spacer() | |
VStack{ | |
TextField("Email", text: $viewModel.email) | |
.textFieldStyle(.roundedBorder) | |
.textInputAutocapitalization(.never) | |
SecureField("Password", text: $viewModel.password) | |
.textFieldStyle(.roundedBorder) | |
// Mark: User Prompt to ask to store Login using FaceID on next time | |
if viewModel.getBioMetricStatus(){ | |
Group { | |
if viewModel.useFaceID { | |
Button { | |
// Mark: Do FaceID action | |
Task { | |
do { | |
try await viewModel.authenticateUser() | |
} catch { | |
print(error.localizedDescription) | |
} | |
} | |
} label: { | |
VStack(alignment: .leading, spacing: 10) { | |
Label { | |
Text("Utiliser le FaceId") | |
} icon: { | |
Image(systemName: "faceid") | |
} | |
} | |
.font(.caption) | |
.foregroundColor(.gray) | |
} | |
} else { | |
Toggle(isOn: $useFaceID) { | |
Text("Use FaceID to login") | |
.foregroundColor(.gray) | |
} | |
} | |
}.padding(.vertical, 20) | |
} | |
Button { | |
// Mark: Login default | |
Task { | |
do { | |
try await viewModel.login(useFaceID: useFaceID) | |
} catch { | |
print(error.localizedDescription) | |
viewModel.showError.toggle() | |
viewModel.msgError = error.localizedDescription | |
} | |
} | |
} label: { | |
Text("Vous connectez") | |
} | |
} | |
.padding() | |
.background(Color.white) | |
Spacer() | |
NavigationLink(destination: ResetPassword()) { | |
Text("Mot passe oublié !") | |
}.padding(.bottom, 20) | |
}.alert(viewModel.msgError, isPresented: $viewModel.showError) { | |
} | |
} | |
.ignoresSafeArea(.all) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment