Ivan Valkou 5 лет назад
Родитель
Сommit
e4421fa8a3

+ 4 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -74,6 +74,7 @@
 		3811DEE825CA063400A708ED /* Injected.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DEE425CA063400A708ED /* Injected.swift */; };
 		3811DEEA25CA063400A708ED /* SyncAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DEE625CA063400A708ED /* SyncAccess.swift */; };
 		3811DEEB25CA063400A708ED /* PersistedProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DEE725CA063400A708ED /* PersistedProperty.swift */; };
+		3811DF0225CA9FEA00A708ED /* Credentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3811DF0125CA9FEA00A708ED /* Credentials.swift */; };
 		384E803425C385E60086DB71 /* JavaScriptWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384E803325C385E60086DB71 /* JavaScriptWorker.swift */; };
 		384E803825C388640086DB71 /* Script.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384E803725C388640086DB71 /* Script.swift */; };
 		388E595C25AD948C0019842D /* FreeAPSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388E595B25AD948C0019842D /* FreeAPSApp.swift */; };
@@ -159,6 +160,7 @@
 		3811DEE425CA063400A708ED /* Injected.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Injected.swift; sourceTree = "<group>"; };
 		3811DEE625CA063400A708ED /* SyncAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncAccess.swift; sourceTree = "<group>"; };
 		3811DEE725CA063400A708ED /* PersistedProperty.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistedProperty.swift; sourceTree = "<group>"; };
+		3811DF0125CA9FEA00A708ED /* Credentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Credentials.swift; sourceTree = "<group>"; };
 		384E803325C385E60086DB71 /* JavaScriptWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JavaScriptWorker.swift; sourceTree = "<group>"; };
 		384E803725C388640086DB71 /* Script.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Script.swift; sourceTree = "<group>"; };
 		388E595825AD948C0019842D /* FreeAPS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FreeAPS.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -561,6 +563,7 @@
 				3811DE8E25C9D80400A708ED /* User.swift */,
 				388E5A5F25B6F2310019842D /* Autosens.swift */,
 				3895E4C525B9E00D00214B37 /* Preferences.swift */,
+				3811DF0125CA9FEA00A708ED /* Credentials.swift */,
 			);
 			path = Models;
 			sourceTree = "<group>";
@@ -717,6 +720,7 @@
 				3811DE8C25C9D6DD00A708ED /* RequestPermissionsViewModel.swift in Sources */,
 				3811DE3125C9D49500A708ED /* HomeProvider.swift in Sources */,
 				388E5A5C25B6F0770019842D /* JSON.swift in Sources */,
+				3811DF0225CA9FEA00A708ED /* Credentials.swift in Sources */,
 				3811DEB625C9D88300A708ED /* UnlockManager.swift in Sources */,
 				3811DE1825C9D40400A708ED /* Router.swift in Sources */,
 				3811DEE825CA063400A708ED /* Injected.swift in Sources */,

+ 1 - 6
FreeAPS/Resources/FreeAPS.entitlements

@@ -1,10 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
-<dict>
-	<key>com.apple.developer.applesignin</key>
-	<array>
-		<string>Default</string>
-	</array>
-</dict>
+<dict/>
 </plist>

+ 5 - 0
FreeAPS/Sources/Models/Credentials.swift

@@ -0,0 +1,5 @@
+import Foundation
+
+struct Credentials: Codable {
+    var id = UUID()
+}

+ 2 - 27
FreeAPS/Sources/Modules/Login/LoginDataFlow.swift

@@ -1,4 +1,3 @@
-import AuthenticationServices
 
 enum Login {
     enum Config {
@@ -7,30 +6,6 @@ enum Login {
 }
 
 protocol LoginProvider: Provider {
-    func authorize(credentials: ASAuthorizationAppleIDCredential)
-    var credentials: ASAuthorizationAppleIDCredential? { get }
-}
-
-struct CredentialsWrapper: Codable {
-    enum CodingKeys: String, CodingKey {
-        case credentials
-    }
-
-    var credentials: ASAuthorizationAppleIDCredential
-
-    init(_ credentials: ASAuthorizationAppleIDCredential) {
-        self.credentials = credentials
-    }
-
-    func encode(to encoder: Encoder) throws {
-        var container = encoder.container(keyedBy: CodingKeys.self)
-        let data = try NSKeyedArchiver.archivedData(withRootObject: credentials, requiringSecureCoding: true)
-        try container.encode(data, forKey: .credentials)
-    }
-
-    init(from decoder: Decoder) throws {
-        let container = try decoder.container(keyedBy: CodingKeys.self)
-        let data = try container.decode(Data.self, forKey: .credentials)
-        credentials = try (NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? ASAuthorizationAppleIDCredential)!
-    }
+    func authorize(credentials: Credentials)
+    var credentials: Credentials? { get }
 }

+ 4 - 4
FreeAPS/Sources/Modules/Login/LoginProvider.swift

@@ -5,16 +5,16 @@ extension Login {
         @Injected() var authorizationManager: AuthorizationManager!
         @Injected() private var keychain: Keychain!
 
-        func authorize(credentials: ASAuthorizationAppleIDCredential) {
+        func authorize(credentials: Credentials) {
             authorizationManager.authorize(credentials: credentials)
                 .sink { _ in
-                    self.keychain.setValue(CredentialsWrapper(credentials), forKey: Config.credentialsKey)
+                    self.keychain.setValue(credentials, forKey: Config.credentialsKey)
                 }
                 .store(in: &lifetime)
         }
 
-        var credentials: ASAuthorizationAppleIDCredential? {
-            keychain.getValue(CredentialsWrapper.self, forKey: Config.credentialsKey)?.credentials
+        var credentials: Credentials? {
+            keychain.getValue(Credentials.self, forKey: Config.credentialsKey)
         }
     }
 }

+ 5 - 1
FreeAPS/Sources/Modules/Login/LoginViewModel.swift

@@ -3,7 +3,7 @@ import SwiftUI
 
 extension Login {
     class ViewModel<Provider>: BaseViewModel<Provider>, ObservableObject where Provider: LoginProvider {
-        @Published var credentials: ASAuthorizationAppleIDCredential?
+        @Published var credentials: Credentials?
 
         override func subscribe() {
             credentials = provider.credentials
@@ -13,5 +13,9 @@ extension Login {
                 .sink { self.provider.authorize(credentials: $0) }
                 .store(in: &lifetime)
         }
+
+        func login() {
+            credentials = Credentials()
+        }
     }
 }

+ 6 - 15
FreeAPS/Sources/Modules/Login/View/LoginRootView.swift

@@ -1,4 +1,3 @@
-import AuthenticationServices
 import SwiftUI
 
 extension Login {
@@ -7,22 +6,14 @@ extension Login {
 
         var body: some View {
             VStack {
-                Text("FreeAPS").font(.largeTitle)
+                Text("Disclaimer").font(.title)
                 Spacer()
-                SignInWithAppleButton(.signIn) { request in
-                    request.requestedScopes = [.fullName, .email]
+                Button(action: viewModel.login) {
+                    Text("Continue")
+                        .frame(maxWidth: .infinity)
+                        .foregroundColor(.white)
+                        .buttonBackground()
                 }
-                onCompletion: { result in
-                    switch result {
-                    case let .success(authorisation):
-                        viewModel.credentials = authorisation.credential as? ASAuthorizationAppleIDCredential
-                    case .failure:
-                        viewModel.credentials = nil
-                    }
-                }
-                .frame(width: 300, height: 50)
-                .signInWithAppleButtonStyle(.whiteOutline)
-                Spacer()
             }.padding()
         }
     }

+ 2 - 3
FreeAPS/Sources/Services/AuthorizationManager/AuthorizationManager.swift

@@ -5,7 +5,7 @@ import Swinject
 protocol AuthorizationManager {
     var isAuthorized: Bool { get }
     var authorizationPublisher: AnyPublisher<Bool, Never> { get }
-    func authorize(credentials: ASAuthorizationAppleIDCredential) -> AnyPublisher<Void, Never>
+    func authorize(credentials: Credentials) -> AnyPublisher<Void, Never>
     func logout()
 }
 
@@ -23,9 +23,8 @@ final class BaseAuthorizationManager: AuthorizationManager, Injectable {
         injectServices(resolver)
     }
 
-    func authorize(credentials _: ASAuthorizationAppleIDCredential) -> AnyPublisher<Void, Never> {
+    func authorize(credentials _: Credentials) -> AnyPublisher<Void, Never> {
         isAuthorizedSubject.send(true)
-        // TODO: send data to server
         return Just(()).eraseToAnyPublisher()
     }
 

+ 1 - 0
Templates/swift_pvvm/Code/View/RootView.swift.liquid

@@ -8,6 +8,7 @@ extension {{ module_info.name }} {
             Text("{{ module_info.name }} screen")
             	.toolbar { ToolbarItem(placement: .principal) { Text("{{ module_info.name }}") } }
                 .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
+                .navigationBarTitleDisplayMode(.inline)
         }
     }
 }