Move the request credential function into one file

This commit is contained in:
Mingshen Sun 2019-11-30 23:05:30 -08:00
parent 2f3e51947a
commit efdc45ea89
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
5 changed files with 53 additions and 39 deletions

View file

@ -0,0 +1,47 @@
//
// GitCredentialPassword.swift
// pass
//
// Created by Sun, Mingshen on 11/30/19.
// Copyright © 2019 Bob Sun. All rights reserved.
//
import Foundation
import SVProgressHUD
import passKit
public func requestGitCredentialPassword(credential: GitCredential.Credential,
lastPassword: String?,
controller: UIViewController) -> String? {
let sem = DispatchSemaphore(value: 0)
var password: String?
let message: String = {
switch credential {
case .http:
return "FillInGitAccountPassword.".localize()
case .ssh:
return "FillInSshKeyPassphrase.".localize()
}
}()
DispatchQueue.main.async {
SVProgressHUD.dismiss()
let alert = UIAlertController(title: "Password".localize(), message: message, preferredStyle: .alert)
alert.addTextField() {
$0.text = lastPassword ?? ""
$0.isSecureTextEntry = true
}
alert.addAction(UIAlertAction(title: "Ok".localize(), style: .default) { _ in
password = alert.textFields?.first?.text
sem.signal()
})
alert.addAction(UIAlertAction(title: "Cancel".localize(), style: .cancel) { _ in
password = nil
sem.signal()
})
controller.present(alert, animated: true)
}
let _ = sem.wait(timeout: .distantFuture)
return password
}