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
|
2017-02-15 22:34:16 +08:00
|
|
|
import SVProgressHUD
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2017-01-28 00:21:17 +08:00
|
|
|
|
2019-02-17 19:01:08 +01:00
|
|
|
class SSHKeySettingTableViewController: AutoCellHeightUITableViewController {
|
2017-01-28 00:21:17 +08:00
|
|
|
|
|
|
|
|
@IBOutlet weak var privateKeyURLTextField: UITextField!
|
2017-04-02 11:21:24 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-01-28 00:21:17 +08:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-04-06 22:44:44 +08:00
|
|
|
@IBAction func doneButtonTapped(_ sender: UIButton) {
|
2018-11-13 23:54:53 +01:00
|
|
|
guard let privateKeyURL = URL(string: privateKeyURLTextField.text!.trimmed) else {
|
2019-01-14 20:57:45 +01:00
|
|
|
Utils.alert(title: "CannotSave".localize(), message: "SetPrivateKeyUrl.".localize(), controller: self, completion: nil)
|
2017-02-15 22:34:16 +08:00
|
|
|
return
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-01-31 22:54:58 +08:00
|
|
|
do {
|
2019-07-17 23:43:28 -07:00
|
|
|
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: SshKey.PRIVATE.getFileSharingPath()), options: .atomic)
|
|
|
|
|
try self.passwordStore.gitSSHKeyImportFromFileSharing()
|
2020-01-02 00:48:00 +01:00
|
|
|
Defaults.gitSSHKeySource = .file
|
|
|
|
|
Defaults.gitAuthenticationMethod = .key
|
2019-07-17 23:43:28 -07:00
|
|
|
SVProgressHUD.showSuccess(withStatus: "Imported".localize())
|
|
|
|
|
SVProgressHUD.dismiss(withDelay: 1)
|
2017-01-31 22:54:58 +08:00
|
|
|
} catch {
|
2019-01-14 20:57:45 +01:00
|
|
|
Utils.alert(title: "Error".localize(), message: error.localizedDescription, controller: self, completion: nil)
|
2017-01-31 22:54:58 +08:00
|
|
|
}
|
2020-01-02 00:48:00 +01: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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|