diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index 28015d0..0965ecb 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -12,7 +12,10 @@ DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC1208571E35EBE60042942E /* ObjectiveGit.framework */; }; DC286D461E37444D00DBF9C8 /* Former.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC286D451E37444D00DBF9C8 /* Former.framework */; }; DC286D4A1E374AF100DBF9C8 /* SSHKeySettingFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC286D491E374AF100DBF9C8 /* SSHKeySettingFormViewController.swift */; }; + DC286D4E1E37B53F00DBF9C8 /* TextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC286D4C1E37B53E00DBF9C8 /* TextFieldTableViewCell.swift */; }; + DC286D4F1E37B53F00DBF9C8 /* TextFieldTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC286D4D1E37B53F00DBF9C8 /* TextFieldTableViewCell.xib */; }; DC3DC8391E2F63240062A988 /* PasswordDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */; }; + DC8963BE1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */; }; DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC917BD61E2E8231000FDF54 /* AppDelegate.swift */; }; DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDA1E2E8231000FDF54 /* Main.storyboard */; }; DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; }; @@ -37,8 +40,11 @@ DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = ""; }; DC286D451E37444D00DBF9C8 /* Former.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Former.framework; path = Carthage/Build/iOS/Former.framework; sourceTree = ""; }; DC286D491E374AF100DBF9C8 /* SSHKeySettingFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeySettingFormViewController.swift; sourceTree = ""; }; + DC286D4C1E37B53E00DBF9C8 /* TextFieldTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldTableViewCell.swift; sourceTree = ""; }; + DC286D4D1E37B53F00DBF9C8 /* TextFieldTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextFieldTableViewCell.xib; sourceTree = ""; }; DC3DC8381E2F63240062A988 /* PasswordDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailViewController.swift; sourceTree = ""; }; DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Objective-CBridgingHeader.h"; sourceTree = ""; }; + DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitRepositoryAuthenticationSettingTableViewController.swift; sourceTree = ""; }; DC917BD31E2E8231000FDF54 /* pass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = pass.app; sourceTree = BUILT_PRODUCTS_DIR; }; DC917BD61E2E8231000FDF54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DC917BDB1E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -105,10 +111,13 @@ isa = PBXGroup; children = ( DC286D491E374AF100DBF9C8 /* SSHKeySettingFormViewController.swift */, + DC286D4C1E37B53E00DBF9C8 /* TextFieldTableViewCell.swift */, + DC286D4D1E37B53F00DBF9C8 /* TextFieldTableViewCell.xib */, DC1208551E35D0BA0042942E /* PasswordsTableViewController.swift */, DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */, DC917BD61E2E8231000FDF54 /* AppDelegate.swift */, DC917BDA1E2E8231000FDF54 /* Main.storyboard */, + DC8963BD1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift */, DCA0499B1E3362F400522E8F /* PGPKeySettingTableViewController.swift */, DCA049991E335CC800522E8F /* GitServerSettingTableViewController.swift */, DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */, @@ -204,6 +213,7 @@ DC917BE11E2E8231000FDF54 /* LaunchScreen.storyboard in Resources */, DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */, DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */, + DC286D4F1E37B53F00DBF9C8 /* TextFieldTableViewCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -283,10 +293,12 @@ DCC408A41E2FCC9E00F29B0E /* PasswordStore.swift in Sources */, DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */, DC1208561E35D0BA0042942E /* PasswordsTableViewController.swift in Sources */, + DC286D4E1E37B53F00DBF9C8 /* TextFieldTableViewCell.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, DCA0499A1E335CC800522E8F /* GitServerSettingTableViewController.swift in Sources */, DC286D4A1E374AF100DBF9C8 /* SSHKeySettingFormViewController.swift in Sources */, DCC277D21E30D6EA00402246 /* pass.xcdatamodeld in Sources */, + DC8963BE1E38AD8300828B09 /* GitRepositoryAuthenticationSettingTableViewController.swift in Sources */, DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */, DCA049981E33586A00522E8F /* DefaultKeys.swift in Sources */, DCA0499E1E33BAC100522E8F /* Globals.swift in Sources */, diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index 3c3a03b..e8b7bad 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -94,7 +94,7 @@ - + @@ -165,10 +165,10 @@ - + - + @@ -273,6 +273,37 @@ + + + + + + + + + + + + + + + + + + + @@ -294,6 +325,7 @@ + @@ -302,7 +334,76 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pass/DefaultKeys.swift b/pass/DefaultKeys.swift index 0a10759..e54f7c7 100644 --- a/pass/DefaultKeys.swift +++ b/pass/DefaultKeys.swift @@ -17,6 +17,7 @@ extension DefaultsKeys { static let pgpKeyUserID = DefaultsKey("pgpKeyUserID") static let gitRepositoryURL = DefaultsKey("gitRepositoryURL") + static let gitRepositoryAuthenticationMethod = DefaultsKey("gitRepositoryAuthenticationMethod") static let gitRepositoryUsername = DefaultsKey("gitRepositoryUsername") static let gitRepositoryPassword = DefaultsKey("gitRepositoryPassword") static let gitRepositorySSHPublicKeyURL = DefaultsKey("gitRepositorySSHPublicKeyURL") diff --git a/pass/GitRepositoryAuthenticationSettingTableViewController.swift b/pass/GitRepositoryAuthenticationSettingTableViewController.swift new file mode 100644 index 0000000..42c385a --- /dev/null +++ b/pass/GitRepositoryAuthenticationSettingTableViewController.swift @@ -0,0 +1,30 @@ +// +// GitRepositoryAuthenticationSettingTableViewController.swift +// pass +// +// Created by Mingshen Sun on 25/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit + +class GitRepositoryAuthenticationSettingTableViewController: UITableViewController { + + var selectedMethod: String? + + @IBOutlet weak var sshKeyCell: UITableViewCell! + @IBOutlet weak var passwordCell: UITableViewCell! + + override func viewDidLoad() { + super.viewDidLoad() + switch selectedMethod! { + case "Password": + passwordCell.accessoryType = UITableViewCellAccessoryType.checkmark + case "SSH Key": + sshKeyCell.accessoryType = UITableViewCellAccessoryType.checkmark + default: + break + } + } + +} diff --git a/pass/GitServerSettingTableViewController.swift b/pass/GitServerSettingTableViewController.swift index 458dd7c..6a817b9 100644 --- a/pass/GitServerSettingTableViewController.swift +++ b/pass/GitServerSettingTableViewController.swift @@ -26,6 +26,7 @@ class GitServerSettingTableViewController: UITableViewController { } usernameTextField.text = Defaults[.gitRepositoryUsername] passwordTextField.text = Defaults[.gitRepositoryPassword] + authenticationTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryAuthenticationMethod] } override func viewDidAppear(_ animated: Bool) { @@ -37,4 +38,21 @@ class GitServerSettingTableViewController: UITableViewController { 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" + } else { + authenticationTableViewCell.detailTextLabel?.text = "SSH Key" + } + } + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "selectAuthenticationMethod" { + if let controller = segue.destination as? GitRepositoryAuthenticationSettingTableViewController { + controller.selectedMethod = authenticationTableViewCell.detailTextLabel!.text + } + } + } } diff --git a/pass/SSHKeySettingFormViewController.swift b/pass/SSHKeySettingFormViewController.swift index cb456bd..921ba62 100644 --- a/pass/SSHKeySettingFormViewController.swift +++ b/pass/SSHKeySettingFormViewController.swift @@ -12,5 +12,24 @@ class SSHKeySettingFormViewController: FormViewController { override func viewDidLoad() { super.viewDidLoad() + + let publicKeyURLTextFieldRow = TextFieldRowFormer(instantiateType: .Nib(nibName: "TextFieldTableViewCell")) { (row: TextFieldTableViewCell) -> Void in + row.titleLabel.text = "SSH Public Key URL" + }.configure { (row) in + row.rowHeight = 52 + } + let privateKeyURLTextFieldRow = TextFieldRowFormer(instantiateType: .Nib(nibName: "TextFieldTableViewCell")) { (row: TextFieldTableViewCell) -> Void in + row.titleLabel.text = "SSH Private Key URL" + }.configure { (row) in + row.rowHeight = 52 + } + + let privateKeyPhassphraseTextFieldRow = TextFieldRowFormer(instantiateType: .Nib(nibName: "TextFieldTableViewCell")) { (row: TextFieldTableViewCell) -> Void in + row.titleLabel.text = "Phassphrase" + row.textField.isSecureTextEntry = true + }.configure { (row) in + row.rowHeight = 52 + } + former.append(sectionFormer: SectionFormer(rowFormer: publicKeyURLTextFieldRow, privateKeyURLTextFieldRow, privateKeyPhassphraseTextFieldRow)) } } diff --git a/pass/SettingsTableViewController.swift b/pass/SettingsTableViewController.swift index c9731f6..14fd65b 100644 --- a/pass/SettingsTableViewController.swift +++ b/pass/SettingsTableViewController.swift @@ -23,6 +23,13 @@ class SettingsTableViewController: UITableViewController { let gitRepostiroyURL = controller.gitRepositoryURLTextField.text! let username = controller.usernameTextField.text! let password = controller.passwordTextField.text! + let auth = controller.authenticationTableViewCell.detailTextLabel!.text! + + + Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL) + Defaults[.gitRepositoryUsername] = username + Defaults[.gitRepositoryPassword] = password + Defaults[.gitRepositoryAuthenticationMethod] = auth if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString { SVProgressHUD.setDefaultMaskType(.black) @@ -47,9 +54,6 @@ class SettingsTableViewController: UITableViewController { if ret { SVProgressHUD.showSuccess(withStatus: "Done") SVProgressHUD.dismiss(withDelay: 1) - Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL) - Defaults[.gitRepositoryUsername] = username - Defaults[.gitRepositoryPassword] = password NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated"))) } else { diff --git a/pass/TextFieldTableViewCell.swift b/pass/TextFieldTableViewCell.swift new file mode 100644 index 0000000..81e4087 --- /dev/null +++ b/pass/TextFieldTableViewCell.swift @@ -0,0 +1,30 @@ +// +// TextFieldTableViewCell.swift +// pass +// +// Created by Mingshen Sun on 25/1/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit +import Former + +class TextFieldTableViewCell: UITableViewCell, TextFieldFormableRow { + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var textField: UITextField! + + override func awakeFromNib() { + super.awakeFromNib() + } + + func formTextField() -> UITextField { + return textField + } + + func formTitleLabel() -> UILabel? { + return titleLabel + } + + func updateWithRowFormer(_ rowFormer: RowFormer) {} + +} diff --git a/pass/TextFieldTableViewCell.xib b/pass/TextFieldTableViewCell.xib new file mode 100644 index 0000000..613d83d --- /dev/null +++ b/pass/TextFieldTableViewCell.xib @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +