Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14752747
AccountModel.swift
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
AccountModel.swift
View Options
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-c
Expires
Fri, Apr 24, 10:56 AM (1 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3682407
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment