Add simple account model for testing login screen

This commit is contained in:
Angelo Stavrow 2020-08-07 16:27:23 -04:00
parent 29f065c3d1
commit ea6e9491c2
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -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