Polish validation logic of importing pgp key via url
This commit is contained in:
parent
275b856883
commit
d1393c6d36
1 changed files with 14 additions and 10 deletions
|
|
@ -39,22 +39,26 @@ 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
|
|
||||||
}
|
|
||||||
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 false
|
|
||||||
}
|
|
||||||
guard pgpPublicKeyURL.scheme! == "https", pgpPrivateKeyURL.scheme! == "https" else {
|
|
||||||
Utils.alert(title: "Cannot Save Settings", message: "HTTP connection is not supported.", controller: self, completion: nil)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
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
|
||||||
|
}
|
||||||
|
guard let scheme = url.scheme, scheme == "https", scheme == "https" else {
|
||||||
|
Utils.alert(title: "Cannot Save PGP Key", message: "HTTP connection is not supported.", controller: self, completion: nil)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
@IBAction func save(_ sender: Any) {
|
@IBAction func save(_ sender: Any) {
|
||||||
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
|
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
|
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue