mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
Sign In instead of Login
This commit is contained in:
parent
5149e817da
commit
bfb56660bf
4 changed files with 9 additions and 16 deletions
|
|
@ -31,7 +31,7 @@ class AppState: ObservableObject {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func loginIfNeeded() -> AnyPublisher<Void, Error> {
|
||||
func signInIfNeeded() -> AnyPublisher<Void, Error> {
|
||||
validateSession()
|
||||
.catch { (error) -> AnyPublisher<Void, Error> in
|
||||
guard
|
||||
|
|
@ -42,15 +42,15 @@ class AppState: ObservableObject {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return self.login(username: username, password: password)
|
||||
return self.signIn(username: username, password: password)
|
||||
.map { _ in Void() }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func login(username: String, password: String) {
|
||||
login(username: username, password: password)
|
||||
func signIn(username: String, password: String) {
|
||||
signIn(username: username, password: password)
|
||||
.sink(
|
||||
receiveCompletion: { _ in },
|
||||
receiveValue: { _ in }
|
||||
|
|
@ -58,7 +58,7 @@ class AppState: ObservableObject {
|
|||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func login(username: String, password: String) -> AnyPublisher<AuthenticationState, Error> {
|
||||
func signIn(username: String, password: String) -> AnyPublisher<AuthenticationState, Error> {
|
||||
try? Current.keychain.set(password, key: username)
|
||||
Current.defaults.set(username, forKey: "username")
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ class AppState: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
func logOut() {
|
||||
func signOut() {
|
||||
let username = Current.defaults.string(forKey: "username")
|
||||
Current.defaults.removeObject(forKey: "username")
|
||||
if let username = username {
|
||||
|
|
@ -161,7 +161,7 @@ class AppState: ObservableObject {
|
|||
}
|
||||
|
||||
public func update() -> AnyPublisher<[Xcode], Never> {
|
||||
loginIfNeeded()
|
||||
signInIfNeeded()
|
||||
.flatMap {
|
||||
// Wrap the Promise API in a Publisher for now
|
||||
Deferred {
|
||||
|
|
|
|||
|
|
@ -122,13 +122,6 @@ public struct Network {
|
|||
public func downloadTask(with convertible: URLRequestConvertible, to saveLocation: URL, resumingWith resumeData: Data?) -> (progress: Progress, promise: Promise<(saveLocation: URL, response: URLResponse)>) {
|
||||
return downloadTask(convertible, saveLocation, resumeData)
|
||||
}
|
||||
|
||||
// public var validateSession: () -> Promise<Void> = client.validateSession
|
||||
//
|
||||
// public var login: (String, String) -> Promise<Void> = { client.login(accountName: $0, password: $1) }
|
||||
// public func login(accountName: String, password: String) -> Promise<Void> {
|
||||
// login(accountName, password)
|
||||
// }
|
||||
}
|
||||
|
||||
public struct Logging {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ struct SignInCredentialsView: View {
|
|||
Spacer()
|
||||
Button("Cancel") { isPresented = false }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Button("Next") { appState.login(username: username, password: password) }
|
||||
Button("Next") { appState.signIn(username: username, password: password) }
|
||||
.disabled(username.isEmpty)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ struct SettingsView: View {
|
|||
VStack(alignment: .leading) {
|
||||
if let username = Current.defaults.string(forKey: "username") {
|
||||
Text(username)
|
||||
Button("Sign Out", action: appState.logOut)
|
||||
Button("Sign Out", action: appState.signOut)
|
||||
} else {
|
||||
Button("Sign In", action: { self.appState.presentingSignInAlert = true })
|
||||
.sheet(isPresented: $appState.presentingSignInAlert) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue