Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10493996
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/Shared/Account/AccountModel.swift b/Shared/Account/AccountModel.swift
new file mode 100644
index 0000000..e460f48
--- /dev/null
+++ b/Shared/Account/AccountModel.swift
@@ -0,0 +1,49 @@
+import Foundation
+
+enum AccountError: Error {
+ case invalidCredentials
+ case serverNotFound
+}
+
+struct AccountModel {
+ private(set) var id: UUID?
+ var username: String?
+ var password: String?
+ var server: String?
+
+ mutating func login(
+ to server: String,
+ as username: String,
+ password: String,
+ completion: @escaping (Result<UUID, AccountError>) -> Void
+ ) {
+ 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) {
+ completion(result)
+ }
+ #endif
+ }
+}
+
+#if DEBUG
+let validCredentials = [
+ "username": "name@example.com",
+ "password": "12345"
+]
+let validServer = "https://test.server.url"
+#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Mar 6, 3:13 AM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3166426
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment