Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10669764
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
View Options
diff --git a/Shared/Account/AccountModel.swift b/Shared/Account/AccountModel.swift
index 4027c76..77ee7a4 100644
--- a/Shared/Account/AccountModel.swift
+++ b/Shared/Account/AccountModel.swift
@@ -1,69 +1,69 @@
import Foundation
enum AccountError: Error {
case invalidPassword
case usernameNotFound
case serverNotFound
}
class AccountModel: ObservableObject {
@Published private(set) var id: UUID?
@Published private(set) var isLoggedIn: Bool = false
@Published private(set) var isLoggingIn: Bool = false
@Published var username: String = ""
@Published var password: String = ""
@Published var server: String = ""
func login(
to server: String,
as username: String,
password: String,
completion: @escaping (Result<UUID, AccountError>) -> Void
) {
self.isLoggingIn = true
let result: Result<UUID, AccountError>
if server != validServer {
result = .failure(.serverNotFound)
} else if username == validCredentials["username"] && password == validCredentials["password"] {
self.id = UUID()
self.username = username
self.password = password
self.server = server
result = .success(self.id!)
} else {
result = .failure(.invalidCredentials)
}
#if DEBUG
// Delay to simulate async network call
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.isLoggingIn = false
do {
_ = try result.get()
self.isLoggedIn = true
} catch {
self.isLoggedIn = false
}
completion(result)
}
#endif
}
func logout() {
id = nil
isLoggedIn = false
isLoggingIn = false
username = ""
password = ""
server = ""
}
}
#if DEBUG
let validCredentials = [
- "username": "name@example.com",
+ "username": "test-writer",
"password": "12345"
]
let validServer = "https://test.server.url"
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, May 16, 4:55 PM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3240234
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment