passforios/pass/Controllers/SSHKeySettingTableViewController.swift

50 lines
1.8 KiB
Swift
Raw Normal View History

2017-01-28 00:21:17 +08:00
//
// SSHKeySettingTableViewController.swift
// pass
//
// Created by Mingshen Sun on 25/1/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import SwiftyUserDefaults
2017-02-15 22:34:16 +08:00
import SVProgressHUD
2017-01-28 00:21:17 +08:00
class SSHKeySettingTableViewController: UITableViewController {
@IBOutlet weak var privateKeyURLTextField: UITextField!
@IBOutlet weak var publicKeyURLTextField: UITextField!
let passwordStore = PasswordStore.shared
2017-01-28 00:21:17 +08:00
override func viewDidLoad() {
super.viewDidLoad()
privateKeyURLTextField.text = Defaults[.gitSSHPrivateKeyURL]?.absoluteString
publicKeyURLTextField.text = Defaults[.gitSSHPublicKeyURL]?.absoluteString
2017-01-28 00:21:17 +08:00
}
@IBAction func doneButtonTapped(_ sender: UIButton) {
guard let publicKeyURL = URL(string: publicKeyURLTextField.text!) 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
}
guard let privateKeyURL = URL(string: privateKeyURLTextField.text!) 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
}
Defaults[.gitSSHPublicKeyURL] = publicKeyURL
Defaults[.gitSSHPrivateKeyURL] = privateKeyURL
do {
try Data(contentsOf: publicKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPublicKeyPath), options: .atomic)
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPrivateKeyPath), options: .atomic)
} catch {
2017-03-16 23:12:31 -07:00
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
}
Defaults[.gitSSHKeySource] = "url"
2017-04-28 20:33:41 -07:00
self.navigationController!.popViewController(animated: true)
2017-01-28 00:21:17 +08:00
}
}