Skip to content
Snippets Groups Projects
Commit f4857a6a authored by cpilaszewicz's avatar cpilaszewicz
Browse files

Create an enum for authentication results

parent 449d0370
No related branches found
No related tags found
4 merge requests!58Onboarding screens swift ui merge dev,!55WIP: Resolve "UI for gamifcation & stats",!47Provisional fix for OpenSSL 1.1+, needs testing,!39Resolve "Restructure Authentication"
......@@ -11,7 +11,7 @@ import Combine
class AuthenticationModel: NSObject {
enum AuthenticationResult {case Success, Timeout, Error}
enum AuthenticationResult {case Success, Timeout, Error(value: MailServerConnectionError)}
static let instance: AuthenticationModel = AuthenticationModel()
......@@ -50,7 +50,6 @@ class AuthenticationModel: NSObject {
let result = self.dispatchGroup.wait(timeout: DispatchTime.now() + timeoutDelay)
DispatchQueue.main.async {
promise(.success(self.onTimeout(timeoutResult: result)))
print("promise sent")
}
}
}
......@@ -120,7 +119,15 @@ class AuthenticationModel: NSObject {
if imapConfigurationSuccessful && smtpConfigurationSuccessful {
return AuthenticationResult.Success
} else {
return AuthenticationResult.Error
var error = MailServerConnectionError.AuthenticationError
if let smtp = currentIMAP, let e = MailServerConnectionError.findPrioError(errors: smtp.errors) {
error = e
}
if let imap = currentIMAP, let e = MailServerConnectionError.findPrioError(errors: imap.errors) {
error = e
}
return AuthenticationResult.Error(value: error)
}
} else {
return AuthenticationResult.Timeout
......
......@@ -31,7 +31,7 @@ class AuthenticationViewModel : ObservableObject {
case AuthenticationModel.AuthenticationResult.Error :
self.authenticationFailed(error: MailServerConnectionError.AuthenticationError)
case AuthenticationModel.AuthenticationResult.Timeout :
self.timeoutNotification(result: promise)
self.timeoutNotification()
}
}
}
......@@ -43,10 +43,10 @@ class AuthenticationViewModel : ObservableObject {
switch promise {
case AuthenticationModel.AuthenticationResult.Success :
self.authenticationSucceed()
case AuthenticationModel.AuthenticationResult.Error :
self.authenticationFailed(error: MailServerConnectionError.AuthenticationError)
case AuthenticationModel.AuthenticationResult.Error(let value) :
self.authenticationFailed(error: value)
case AuthenticationModel.AuthenticationResult.Timeout :
self.timeoutNotification(result: promise)
self.timeoutNotification()
}
}
}
......@@ -72,7 +72,7 @@ class AuthenticationViewModel : ObservableObject {
case AuthenticationModel.AuthenticationResult.Error :
self.authenticationFailed(error: MailServerConnectionError.AuthenticationError)
case AuthenticationModel.AuthenticationResult.Timeout :
self.timeoutNotification(result: promise)
self.timeoutNotification()
}
}
})
......@@ -86,8 +86,7 @@ class AuthenticationViewModel : ObservableObject {
errorMessage = NSLocalizedString(error.localizedUIBodyString, comment: "")
}
func timeoutNotification(result: AuthenticationModel.AuthenticationResult) {
print("promise arrived")
func timeoutNotification() {
errorMessage = NSLocalizedString(MailServerConnectionError.TimeoutError.localizedUIBodyString, comment: "")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment