Grey out the SSH option if keys don't exist

This commit is contained in:
Evgeny Morozov 2017-02-23 18:31:16 +03:00 committed by Bob Sun
parent 795cc41025
commit 5f872e0345

View file

@ -43,9 +43,16 @@ class GitServerSettingTableViewController: UITableViewController {
usernameTextField.text = Defaults[.gitRepositoryUsername] usernameTextField.text = Defaults[.gitRepositoryUsername]
password = PasswordStore.shared.gitRepositoryPassword password = PasswordStore.shared.gitRepositoryPassword
authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod] authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod]
if authenticationMethod == nil {
// Grey out ssh option if ssh_key and ssh_key.pub are not present
let sshLabel = authSSHKeyCell.subviews[0].subviews[0] as! UILabel
sshLabel.isEnabled = sshKeyExists()
if authenticationMethod == nil || !sshLabel.isEnabled {
authenticationMethod = "Password" authenticationMethod = "Password"
} }
checkAuthenticationMethod(method: authenticationMethod!) checkAuthenticationMethod(method: authenticationMethod!)
authSSHKeyCell.accessoryType = .detailButton authSSHKeyCell.accessoryType = .detailButton
} }
@ -84,12 +91,18 @@ class GitServerSettingTableViewController: UITableViewController {
return true return true
} }
func sshKeyExists() -> Bool {
return FileManager.default.fileExists(atPath: Globals.sshPublicKeyURL.path) &&
FileManager.default.fileExists(atPath: Globals.sshPrivateKeyURL.path)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) let cell = tableView.cellForRow(at: indexPath)
if cell == authPasswordCell { if cell == authPasswordCell {
authenticationMethod = "Password" authenticationMethod = "Password"
} else if cell == authSSHKeyCell { } else if cell == authSSHKeyCell {
if Defaults[.gitRepositorySSHPublicKeyURL] == nil && Defaults[.gitRepositorySSHPrivateKeyURL] == nil {
if !sshKeyExists() {
Utils.alert(title: "Cannot Select SSH Key", message: "Please setup SSH key first.", controller: self, completion: nil) Utils.alert(title: "Cannot Select SSH Key", message: "Please setup SSH key first.", controller: self, completion: nil)
authenticationMethod = "Password" authenticationMethod = "Password"
} else { } else {