Polish credential related logic

This commit is contained in:
Bob Sun 2017-04-28 20:33:41 -07:00
parent 649d709369
commit 1311962dc1
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
7 changed files with 140 additions and 213 deletions

View file

@ -98,7 +98,6 @@ class SettingsTableViewController: UITableViewController {
if let controller = segue.source as? GitServerSettingTableViewController {
let gitRepostiroyURL = controller.gitURLTextField.text!
let username = controller.usernameTextField.text!
let password = controller.password
let auth = controller.authenticationMethod
SVProgressHUD.setDefaultMaskType(.black)
@ -106,15 +105,14 @@ class SettingsTableViewController: UITableViewController {
SVProgressHUD.show(withStatus: "Prepare Repository")
var gitCredential: GitCredential
if auth == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password!, requestGitPassword: requestGitPassword))
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, controller: self))
} else {
gitCredential = GitCredential(
credential: GitCredential.Credential.ssh(
userName: username,
password: Utils.getPasswordFromKeychain(name: "gitSSHPrivateKeyPassphrase") ?? "",
publicKeyFile: Globals.gitSSHPublicKeyURL,
privateKeyFile: Globals.gitSSHPrivateKeyURL,
requestSSHKeyPassword: self.requestGitPassword
controller: self
)
)
}
@ -137,7 +135,6 @@ class SettingsTableViewController: UITableViewController {
Defaults[.gitURL] = URL(string: gitRepostiroyURL)
Defaults[.gitUsername] = username
Defaults[.gitAuthenticationMethod] = auth
Defaults[.gitPasswordAttempts] = 0
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host
SVProgressHUD.showSuccess(withStatus: "Done")
SVProgressHUD.dismiss(withDelay: 1)
@ -196,32 +193,6 @@ class SettingsTableViewController: UITableViewController {
touchIDSwitch.isOn = false
}
}
private func requestGitPassword(message: String) -> String? {
let sem = DispatchSemaphore(value: 0)
var password: String?
DispatchQueue.main.async {
SVProgressHUD.dismiss()
let alert = UIAlertController(title: "Password", message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addTextField(configurationHandler: {(textField: UITextField!) in
textField.text = self.passwordStore.gitPassword
textField.isSecureTextEntry = true
})
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
password = alert.textFields!.first!.text
sem.signal()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in
password = nil
sem.signal()
})
self.present(alert, animated: true, completion: nil)
}
let _ = sem.wait(timeout: .distantFuture)
return password
}
func actOnPasswordStoreErasedNotification() {
setPGPKeyTableViewCellDetailText()