2017-01-22 01:42:36 +08:00
|
|
|
//
|
|
|
|
|
// PGPKeySettingTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 21/1/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import SwiftyUserDefaults
|
|
|
|
|
|
|
|
|
|
class PGPKeySettingTableViewController: UITableViewController {
|
|
|
|
|
|
2017-02-10 22:15:01 +08:00
|
|
|
@IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
|
|
|
|
|
@IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
|
2017-01-22 01:42:36 +08:00
|
|
|
@IBOutlet weak var pgpKeyPassphraseTextField: UITextField!
|
|
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-02-10 22:15:01 +08:00
|
|
|
pgpPublicKeyURLTextField.text = Defaults[.pgpPublicKeyURL]?.absoluteString
|
|
|
|
|
pgpPrivateKeyURLTextField.text = Defaults[.pgpPrivateKeyURL]?.absoluteString
|
2017-01-22 01:42:36 +08:00
|
|
|
pgpKeyPassphraseTextField.text = Defaults[.pgpKeyPassphrase]
|
|
|
|
|
}
|
2017-02-06 13:25:27 +08:00
|
|
|
|
|
|
|
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
|
|
|
|
if identifier == "savePGPKeySegue" {
|
2017-02-13 15:01:04 +08:00
|
|
|
guard pgpPublicKeyURLTextField.text != nil else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
guard pgpPrivateKeyURLTextField.text != nil else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2017-02-15 22:34:16 +08:00
|
|
|
|
|
|
|
|
guard URL(string: pgpPublicKeyURLTextField.text!) != nil else {
|
2017-02-16 00:54:42 +08:00
|
|
|
Utils.alert(title: "Cannot Save", message: "Please set Public Key URL first.", controller: self, completion: nil)
|
2017-02-15 22:34:16 +08:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
guard URL(string: pgpPrivateKeyURLTextField.text!) != nil else {
|
2017-02-16 00:54:42 +08:00
|
|
|
Utils.alert(title: "Cannot Save", message: "Please set Private Key URL first.", controller: self, completion: nil)
|
2017-02-15 22:34:16 +08:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 22:15:01 +08:00
|
|
|
if URL(string: pgpPublicKeyURLTextField.text!)!.scheme! == "http" &&
|
|
|
|
|
URL(string: pgpPrivateKeyURLTextField.text!)!.scheme! == "http" {
|
2017-02-16 00:54:42 +08:00
|
|
|
Utils.alert(title: "Cannot Save Settings", message: "HTTP connection is not supported.", controller: self, completion: nil)
|
2017-02-06 13:25:27 +08:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
2017-01-22 01:42:36 +08:00
|
|
|
}
|