2017-01-22 01:42:36 +08:00
//
// P G P K e y S e t t i n g T a b l e V i e w C o n t r o l l e r . s w i f t
// p a s s
//
// C r e a t e d b y M i n g s h e n S u n o n 2 1 / 1 / 2 0 1 7 .
// C o p y r i g h t © 2 0 1 7 B o b S u n . A l l r i g h t s r e s e r v e d .
//
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-02-17 14:58:27 +08:00
var pgpPassphrase : String ?
2017-03-16 22:39:03 -07:00
let passwordStore = PasswordStore . shared
2017-01-22 01:42:36 +08:00
override func viewDidLoad ( ) {
super . viewDidLoad ( )
2017-02-19 22:10:36 +08:00
tableView . rowHeight = UITableViewAutomaticDimension
2017-02-10 22:15:01 +08:00
pgpPublicKeyURLTextField . text = Defaults [ . pgpPublicKeyURL ] ? . absoluteString
pgpPrivateKeyURLTextField . text = Defaults [ . pgpPrivateKeyURL ] ? . absoluteString
2017-03-16 22:39:03 -07:00
pgpPassphrase = passwordStore . pgpKeyPassphrase
2017-01-22 01:42:36 +08:00
}
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-02-17 14:58:27 +08:00
@IBAction func save ( _ sender : Any ) {
2017-02-28 12:25:52 +08:00
let alert = UIAlertController ( title : " Passphrase " , message : " Please fill in the passphrase of your PGP secret key. " , preferredStyle : UIAlertControllerStyle . alert )
2017-02-17 14:58:27 +08:00
alert . addAction ( UIAlertAction ( title : " OK " , style : UIAlertActionStyle . default , handler : { _ in
self . pgpPassphrase = alert . textFields ? . first ? . text
self . performSegue ( withIdentifier : " savePGPKeySegue " , sender : self )
} ) )
alert . addTextField ( configurationHandler : { ( textField : UITextField ! ) in
textField . text = self . pgpPassphrase
textField . isSecureTextEntry = true
} )
self . present ( alert , animated : true , completion : nil )
}
2017-01-22 01:42:36 +08:00
}