From 8834823d3016393c30d5b97fe5dd9d48df961c09 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 22 Apr 2022 18:10:14 +0100 Subject: [PATCH] adding credential checking on login screen, big playlist title --- Music Tools.xcodeproj/project.pbxproj | 17 +++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 ++++++ .../xcschemes/Music Tools.xcscheme | 2 +- Music Tools/Views/LoginScreen.swift | 29 ++++++++++++++++++- Music Tools/Views/Playlist/PlaylistView.swift | 2 +- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Music Tools.xcodeproj/project.pbxproj b/Music Tools.xcodeproj/project.pbxproj index dfc9c77..1201083 100644 --- a/Music Tools.xcodeproj/project.pbxproj +++ b/Music Tools.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + A10C8D29281302050018AE12 /* ToastUI in Frameworks */ = {isa = PBXBuildFile; productRef = A10C8D28281302050018AE12 /* ToastUI */; }; E906F7F42414019C004E1E31 /* NetworkPersister.swift in Sources */ = {isa = PBXBuildFile; fileRef = E906F7F32414019C004E1E31 /* NetworkPersister.swift */; }; E906F7F724143AA7004E1E31 /* SwiftUICharts in Frameworks */ = {isa = PBXBuildFile; productRef = E906F7F624143AA7004E1E31 /* SwiftUICharts */; }; E934AC99240DD0E4009869F4 /* AddTagSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = E934AC98240DD0E4009869F4 /* AddTagSheet.swift */; }; @@ -108,6 +109,7 @@ E97AF45923FC50EC00635494 /* SwiftyJSON in Frameworks */, E98254D923FB53780056D9D3 /* Alamofire in Frameworks */, E97AF45E23FC83AF00635494 /* KeychainAccess in Frameworks */, + A10C8D29281302050018AE12 /* ToastUI in Frameworks */, E906F7F724143AA7004E1E31 /* SwiftUICharts in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -289,6 +291,7 @@ E97AF45823FC50EC00635494 /* SwiftyJSON */, E97AF45D23FC83AF00635494 /* KeychainAccess */, E906F7F624143AA7004E1E31 /* SwiftUICharts */, + A10C8D28281302050018AE12 /* ToastUI */, ); productName = "Music Tools"; productReference = E9EA690723F9A5430012C3E8 /* Music Tools.app */; @@ -367,6 +370,7 @@ E97AF45723FC50EC00635494 /* XCRemoteSwiftPackageReference "swiftyjson" */, E97AF45C23FC83AF00635494 /* XCRemoteSwiftPackageReference "keychainaccess" */, E906F7F524143AA7004E1E31 /* XCRemoteSwiftPackageReference "chartview" */, + A10C8D27281302050018AE12 /* XCRemoteSwiftPackageReference "ToastUI" */, ); productRefGroup = E9EA690823F9A5430012C3E8 /* Products */; projectDirPath = ""; @@ -768,6 +772,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + A10C8D27281302050018AE12 /* XCRemoteSwiftPackageReference "ToastUI" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/quanshousio/ToastUI"; + requirement = { + branch = main; + kind = branch; + }; + }; E906F7F524143AA7004E1E31 /* XCRemoteSwiftPackageReference "chartview" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/apppear/chartview"; @@ -803,6 +815,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + A10C8D28281302050018AE12 /* ToastUI */ = { + isa = XCSwiftPackageProductDependency; + package = A10C8D27281302050018AE12 /* XCRemoteSwiftPackageReference "ToastUI" */; + productName = ToastUI; + }; E906F7F624143AA7004E1E31 /* SwiftUICharts */ = { isa = XCSwiftPackageProductDependency; package = E906F7F524143AA7004E1E31 /* XCRemoteSwiftPackageReference "chartview" */; diff --git a/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5361dfc..3b381ee 100644 --- a/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Music Tools.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -35,6 +35,15 @@ "revision" : "2b6054efa051565954e1d2b9da831680026cd768", "version" : "5.0.0" } + }, + { + "identity" : "toastui", + "kind" : "remoteSourceControl", + "location" : "https://github.com/quanshousio/ToastUI", + "state" : { + "branch" : "main", + "revision" : "b064788dd92a64fbd01208a65af10beded99062c" + } } ], "version" : 2 diff --git a/Music Tools.xcodeproj/xcshareddata/xcschemes/Music Tools.xcscheme b/Music Tools.xcodeproj/xcshareddata/xcschemes/Music Tools.xcscheme index c1e58d9..e39914e 100644 --- a/Music Tools.xcodeproj/xcshareddata/xcschemes/Music Tools.xcscheme +++ b/Music Tools.xcodeproj/xcshareddata/xcschemes/Music Tools.xcscheme @@ -74,7 +74,7 @@ + isEnabled = "NO"> diff --git a/Music Tools/Views/LoginScreen.swift b/Music Tools/Views/LoginScreen.swift index 0e63625..4f4aa08 100644 --- a/Music Tools/Views/LoginScreen.swift +++ b/Music Tools/Views/LoginScreen.swift @@ -7,6 +7,7 @@ // import SwiftUI +import ToastUI import KeychainAccess struct LoginScreen: View { @@ -16,6 +17,9 @@ struct LoginScreen: View { @State private var username: String = "" @State private var password: String = "" + @State private var showingToast = false + @State private var toastText = "" + var body: some View { VStack { Image("MusicToolsLogo") @@ -36,7 +40,25 @@ struct LoginScreen: View { keychain["username"] = username keychain["password"] = password - self.liveUser.loggedIn = true + let api = UserApi.getUser + RequestBuilder.buildRequest(apiRequest: api) + .validate() + .responseData { response in + + switch response.result { + case .success: + makingRequest = false + self.liveUser.loggedIn = true + case .failure: + makingRequest = false + + keychain["username"] = nil + keychain["password"] = nil + + toastText = "Login Failed" + showingToast = true + } + } }) { Text("Log In") } @@ -45,6 +67,11 @@ struct LoginScreen: View { Text("Register") } } + .toast(isPresented: $showingToast, dismissAfter: 3.0){ + ToastView(toastText) + .toastViewStyle(.failure) + } + .toastDimmedBackground(false) } .padding() } diff --git a/Music Tools/Views/Playlist/PlaylistView.swift b/Music Tools/Views/Playlist/PlaylistView.swift index c03f0f7..234794c 100644 --- a/Music Tools/Views/Playlist/PlaylistView.swift +++ b/Music Tools/Views/Playlist/PlaylistView.swift @@ -199,7 +199,7 @@ struct PlaylistView: View { } } - .navigationBarTitle(Text(playlist.name), displayMode: .inline) + .navigationBarTitle(Text(playlist.name)) .refreshable { self.refreshPlaylist() }