add validation after choosing authentication method

This commit is contained in:
Bob Sun 2017-01-31 21:20:39 +08:00
parent cd8364fd09
commit 7a3f05701b
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 47 additions and 27 deletions

View file

@ -16,6 +16,9 @@ class GitServerSettingTableViewController: UITableViewController {
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var authenticationTableViewCell: UITableViewCell!
var authenticationMethod = "Password"
override func viewDidLoad() {
super.viewDidLoad()
if let url = Defaults[.gitRepositoryURL] {
@ -28,19 +31,36 @@ class GitServerSettingTableViewController: UITableViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
gitRepositoryURLTextField.becomeFirstResponder()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if authenticationMethod == "SSH Key" {
if Defaults[.gitRepositorySSHPublicKeyURL] == nil && Defaults[.gitRepositorySSHPrivateKeyURL] == nil {
authenticationMethod = "Password"
let alertController = UIAlertController(title: "Attention", message: "Please setup SSH key first.", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
present(alertController, animated: true, completion: nil)
} else {
authenticationMethod = "SSH Key"
}
}
authenticationTableViewCell.detailTextLabel?.text = authenticationMethod
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
view.endEditing(true)
}
@IBAction func save(segue: UIStoryboardSegue) {
if let controller = segue.source as? UITableViewController {
if controller.tableView.indexPathForSelectedRow == IndexPath(row: 0, section:0) {
authenticationTableViewCell.detailTextLabel?.text = "Password"
authenticationMethod = "Password"
} else {
authenticationTableViewCell.detailTextLabel?.text = "SSH Key"
authenticationMethod = "SSH Key"
}
}
}