passforios/pass/Controllers/SSHKeySettingTableViewController.swift

40 lines
1.4 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
2017-02-15 22:34:16 +08:00
import SVProgressHUD
import passKit
2017-01-28 00:21:17 +08:00
class SSHKeySettingTableViewController: AutoCellHeightUITableViewController {
2017-01-28 00:21:17 +08:00
@IBOutlet weak var privateKeyURLTextField: UITextField!
2020-02-09 14:06:08 +01:00
let passwordStore = PasswordStore.shared
2018-12-09 16:59:07 -08:00
@IBAction func doneButtonTapped(_ sender: UIButton) {
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
do {
try Data(contentsOf: privateKeyURL).write(to: URL(fileURLWithPath: SshKey.PRIVATE.getFileSharingPath()), options: .atomic)
try self.passwordStore.gitSSHKeyImportFromFileSharing()
Defaults.gitSSHKeySource = .file
Defaults.gitAuthenticationMethod = .key
SVProgressHUD.showSuccess(withStatus: "Imported".localize())
SVProgressHUD.dismiss(withDelay: 1)
} catch {
2019-01-14 20:57:45 +01:00
Utils.alert(title: "Error".localize(), 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
}
}