add PGP key url check

This commit is contained in:
Bob Sun 2017-02-06 13:25:27 +08:00
parent 27c12abdc4
commit 6e5f6d9360
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 16 additions and 3 deletions

View file

@ -485,7 +485,7 @@
</barButtonItem>
<barButtonItem key="rightBarButtonItem" systemItem="done" id="TNt-ne-l7W">
<connections>
<segue destination="jjl-Xi-fkn" kind="unwind" unwindAction="saveWithSegue:" id="aKP-AF-lfv"/>
<segue destination="jjl-Xi-fkn" kind="unwind" identifier="savePGPKeySegue" unwindAction="saveWithSegue:" id="aKP-AF-lfv"/>
</connections>
</barButtonItem>
</navigationItem>

View file

@ -19,4 +19,17 @@ class PGPKeySettingTableViewController: UITableViewController {
pgpKeyURLTextField.text = Defaults[.pgpKeyURL]?.absoluteString
pgpKeyPassphraseTextField.text = Defaults[.pgpKeyPassphrase]
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "savePGPKeySegue" {
if URL(string: pgpKeyURLTextField.text!)!.scheme! == "http" {
let alertMessage = "HTTP connection is not supported."
let alert = UIAlertController(title: "Cannot Save Settings", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
return false
}
}
return true
}
}

View file

@ -75,9 +75,9 @@ class SettingsTableViewController: UITableViewController {
}
}
} else if let controller = segue.source as? PGPKeySettingTableViewController {
if Defaults[.pgpKeyURL] != URL(string: controller.pgpKeyURLTextField.text!) ||
Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text!
{
Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text! {
Defaults[.pgpKeyURL] = URL(string: controller.pgpKeyURLTextField.text!)
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!