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!
|
2017-04-02 11:21:24 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2017-01-28 00:21:17 +08:00
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-04-02 11:21:24 -07:00
|
|
|
privateKeyURLTextField.text = Defaults[.gitSSHPrivateKeyURL]?.absoluteString
|
|
|
|
|
publicKeyURLTextField.text = Defaults[.gitSSHPublicKeyURL]?.absoluteString
|
2017-01-28 00:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
2017-04-06 22:44:44 +08:00
|
|
|
|
|
|
|
|
@IBAction func doneButtonTapped(_ sender: UIButton) {
|
2017-03-21 22:46:05 -07:00
|
|
|
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
|
|
|
|
|
}
|
2017-03-21 22:46:05 -07:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-02 11:21:24 -07:00
|
|
|
Defaults[.gitSSHPublicKeyURL] = publicKeyURL
|
|
|
|
|
Defaults[.gitSSHPrivateKeyURL] = privateKeyURL
|
2017-01-31 22:54:58 +08:00
|
|
|
|
|
|
|
|
do {
|
2017-04-02 11:21:24 -07:00
|
|
|
try Data(contentsOf: publicKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPublicKeyPath), options: .atomic)
|
|
|
|
|
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: Globals.gitSSHPrivateKeyPath), options: .atomic)
|
2017-01-31 22:54:58 +08:00
|
|
|
} catch {
|
2017-03-16 23:12:31 -07:00
|
|
|
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
|
2017-01-31 22:54:58 +08:00
|
|
|
}
|
2017-04-02 11:21:24 -07:00
|
|
|
Defaults[.gitSSHKeySource] = "url"
|
2017-04-28 20:33:41 -07:00
|
|
|
self.navigationController!.popViewController(animated: true)
|
2017-01-28 00:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|