Polish validation logic of importing pgp key via url

This commit is contained in:
Bob Sun 2017-05-11 22:55:55 -07:00
parent 275b856883
commit d1393c6d36
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -39,19 +39,23 @@ class PGPKeySettingTableViewController: UITableViewController {
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "savePGPKeySegue" { if identifier == "savePGPKeySegue" {
guard let pgpPublicKeyURL = URL(string: pgpPublicKeyURLTextField.text!) else { guard validatePGPKeyURL(input: pgpPublicKeyURLTextField.text) == true,
Utils.alert(title: "Cannot Save", message: "Please set Public Key URL first.", controller: self, completion: nil) validatePGPKeyURL(input: pgpPrivateKeyURLTextField.text) == true else {
return false return false
} }
guard let pgpPrivateKeyURL = URL(string: pgpPrivateKeyURLTextField.text!) else { }
Utils.alert(title: "Cannot Save", message: "Please set Private Key URL first.", controller: self, completion: nil) return true
}
private func validatePGPKeyURL(input: String?) -> Bool {
guard let path = input, let url = URL(string: path) else {
Utils.alert(title: "Cannot Save PGP Key", message: "Please set PGP Key URL first.", controller: self, completion: nil)
return false return false
} }
guard pgpPublicKeyURL.scheme! == "https", pgpPrivateKeyURL.scheme! == "https" else { guard let scheme = url.scheme, scheme == "https", scheme == "https" else {
Utils.alert(title: "Cannot Save Settings", message: "HTTP connection is not supported.", controller: self, completion: nil) Utils.alert(title: "Cannot Save PGP Key", message: "HTTP connection is not supported.", controller: self, completion: nil)
return false return false
} }
}
return true return true
} }