From 902cc1af54e4b0cb462222c50d1e5d26f74c85f2 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 19 Feb 2024 16:27:34 +0100 Subject: [PATCH] Adds login view --- PadelClub.xcodeproj/project.pbxproj | 4 ++ PadelClub/Views/ContentView.swift | 2 +- PadelClub/Views/User/LoginView.swift | 59 +++++++++++++++++++++ PadelClub/Views/User/UserCreationView.swift | 2 + 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 PadelClub/Views/User/LoginView.swift diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index e18d6d0..fdec4b5 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ C4A47D912B7BBBEC00ADC637 /* Guard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47D8E2B7BBBEC00ADC637 /* Guard.swift */; }; C4A47D922B7BBBEC00ADC637 /* StoreItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47D8F2B7BBBEC00ADC637 /* StoreItem.swift */; }; C4A47D9F2B7D0BCE00ADC637 /* StepperView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47D9E2B7D0BCE00ADC637 /* StepperView.swift */; }; + C4A47DA62B83948E00ADC637 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47DA52B83948E00ADC637 /* LoginView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -86,6 +87,7 @@ C4A47D8E2B7BBBEC00ADC637 /* Guard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Guard.swift; sourceTree = ""; }; C4A47D8F2B7BBBEC00ADC637 /* StoreItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreItem.swift; sourceTree = ""; }; C4A47D9E2B7D0BCE00ADC637 /* StepperView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepperView.swift; sourceTree = ""; }; + C4A47DA52B83948E00ADC637 /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -226,6 +228,7 @@ isa = PBXGroup; children = ( C4A47D862B7BA36D00ADC637 /* UserCreationView.swift */, + C4A47DA52B83948E00ADC637 /* LoginView.swift */, ); path = User; sourceTree = ""; @@ -416,6 +419,7 @@ C425D4012B6D249D002A7B48 /* PadelClubApp.swift in Sources */, C4A47D772B73789100ADC637 /* TournamentV1.swift in Sources */, C4A47D922B7BBBEC00ADC637 /* StoreItem.swift in Sources */, + C4A47DA62B83948E00ADC637 /* LoginView.swift in Sources */, C4A47D912B7BBBEC00ADC637 /* Guard.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/PadelClub/Views/ContentView.swift b/PadelClub/Views/ContentView.swift index dfec084..c98eb51 100644 --- a/PadelClub/Views/ContentView.swift +++ b/PadelClub/Views/ContentView.swift @@ -35,7 +35,7 @@ struct ContentView: View { .toolbar(content: { ToolbarItem { NavigationLink { - UserCreationView() + LoginView() } label: { Image(systemName: "person.circle.fill") } diff --git a/PadelClub/Views/User/LoginView.swift b/PadelClub/Views/User/LoginView.swift new file mode 100644 index 0000000..c550c25 --- /dev/null +++ b/PadelClub/Views/User/LoginView.swift @@ -0,0 +1,59 @@ +// +// LoginView.swift +// PadelClub +// +// Created by Laurent Morvillier on 19/02/2024. +// + +import SwiftUI +import LeStorage + +struct LoginView: View { + + @State var username: String = "laurent" + @State var password: String = "staxkikoo" + + var body: some View { + + Form { + + TextField("Username", text: self.$username) + .autocorrectionDisabled() + .textInputAutocapitalization(.never) + SecureField("Password", text: self.$password) + .autocorrectionDisabled() + .textInputAutocapitalization(.never) + + Section { + Button(action: { + self._login() + }, label: { + Text("Login") + }) + .frame(maxWidth: .infinity) + } + } + .navigationTitle("Login") + } + + fileprivate func _login() { + guard let service = Store.main.service else { + return + } + Task { + do { + _ = try await service.login( + username: self.username, + password: self.password) + } catch { + Logger.error(error) + } + } + + } + +} + +#Preview { + LoginView() +} diff --git a/PadelClub/Views/User/UserCreationView.swift b/PadelClub/Views/User/UserCreationView.swift index 4dd2f07..5f4a396 100644 --- a/PadelClub/Views/User/UserCreationView.swift +++ b/PadelClub/Views/User/UserCreationView.swift @@ -19,7 +19,9 @@ struct UserCreationView: View { Form { TextField("Username", text: self.$username) + .autocorrectionDisabled() TextField("Password", text: self.$password) + .autocorrectionDisabled() TextField("Email", text: self.$email) Section {