Put PasswordStore as instance in controllers
This commit is contained in:
parent
d338e725d5
commit
d2cff20131
12 changed files with 67 additions and 55 deletions
|
|
@ -13,6 +13,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
var needRefresh = false
|
var needRefresh = false
|
||||||
var indicatorLabel: UILabel!
|
var indicatorLabel: UILabel!
|
||||||
var indicator: UIActivityIndicatorView!
|
var indicator: UIActivityIndicatorView!
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
navigationItemTitle = "About Repository"
|
navigationItemTitle = "About Repository"
|
||||||
|
|
@ -57,20 +58,20 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
numberFormatter.numberStyle = NumberFormatter.Style.decimal
|
numberFormatter.numberStyle = NumberFormatter.Style.decimal
|
||||||
let fm = FileManager.default
|
let fm = FileManager.default
|
||||||
|
|
||||||
let passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false)
|
let passwordEntities = self.passwordStore.fetchPasswordEntityCoreData(withDir: false)
|
||||||
let numberOfPasswords = numberFormatter.string(from: NSNumber(value: passwordEntities.count))!
|
let numberOfPasswords = numberFormatter.string(from: NSNumber(value: passwordEntities.count))!
|
||||||
|
|
||||||
var size = UInt64(0)
|
var size = UInt64(0)
|
||||||
do {
|
do {
|
||||||
if fm.fileExists(atPath: PasswordStore.shared.storeURL.path) {
|
if fm.fileExists(atPath: self.passwordStore.storeURL.path) {
|
||||||
size = try fm.allocatedSizeOfDirectoryAtURL(directoryURL: PasswordStore.shared.storeURL)
|
size = try fm.allocatedSizeOfDirectoryAtURL(directoryURL: self.passwordStore.storeURL)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
let sizeOfRepository = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: ByteCountFormatter.CountStyle.file)
|
let sizeOfRepository = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: ByteCountFormatter.CountStyle.file)
|
||||||
|
|
||||||
let numberOfCommits = PasswordStore.shared.storeRepository?.numberOfCommits(inCurrentBranch: NSErrorPointer(nilLiteral: ())) ?? 0
|
let numberOfCommits = self.passwordStore.storeRepository?.numberOfCommits(inCurrentBranch: NSErrorPointer(nilLiteral: ())) ?? 0
|
||||||
let numberOfCommitsString = numberFormatter.string(from: NSNumber(value: numberOfCommits))!
|
let numberOfCommitsString = numberFormatter.string(from: NSNumber(value: numberOfCommits))!
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
self?.tableData = [
|
self?.tableData = [
|
||||||
// section 0
|
// section 0
|
||||||
[[.style: CellDataStyle.value1, .accessoryType: type, .title: "Passwords", .detailText: numberOfPasswords],
|
[[.style: CellDataStyle.value1, .accessoryType: type, .title: "Passwords", .detailText: numberOfPasswords],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Size", .detailText: sizeOfRepository], [.style: CellDataStyle.value1, .accessoryType: type, .title: "Unsynced", .detailText: String(PasswordStore.shared.getNumberOfUnsyncedPasswords())],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Size", .detailText: sizeOfRepository], [.style: CellDataStyle.value1, .accessoryType: type, .title: "Unsynced", .detailText: String(self?.passwordStore.getNumberOfUnsyncedPasswords() ?? 0)],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()],
|
||||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Commits", .detailText: numberOfCommitsString],
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Commits", .detailText: numberOfCommitsString],
|
||||||
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
|
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class AddPasswordTableViewController: PasswordEditorTableViewController {
|
||||||
|
|
||||||
var password: Password?
|
var password: Password?
|
||||||
var tempContent: String = ""
|
var tempContent: String = ""
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
tableData = [
|
tableData = [
|
||||||
|
|
@ -27,7 +28,7 @@ class AddPasswordTableViewController: PasswordEditorTableViewController {
|
||||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||||
if identifier == "saveAddPasswordSegue" {
|
if identifier == "saveAddPasswordSegue" {
|
||||||
// check PGP key
|
// check PGP key
|
||||||
if PasswordStore.shared.privateKey == nil {
|
if passwordStore.privateKey == nil {
|
||||||
let alertTitle = "Cannot Add Password"
|
let alertTitle = "Cannot Add Password"
|
||||||
let alertMessage = "PGP Key is not set. Please set your PGP Key first."
|
let alertMessage = "PGP Key is not set. Please set your PGP Key first."
|
||||||
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ class AdvancedSettingsTableViewController: UITableViewController {
|
||||||
|
|
||||||
@IBOutlet weak var eraseDataTableViewCell: UITableViewCell!
|
@IBOutlet weak var eraseDataTableViewCell: UITableViewCell!
|
||||||
@IBOutlet weak var discardChangesTableViewCell: UITableViewCell!
|
@IBOutlet weak var discardChangesTableViewCell: UITableViewCell!
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +25,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
|
||||||
let alert = UIAlertController(title: "Erase Password Store Data?", message: "This will delete all local data and settings. Password store data on your remote server will not be affected.", preferredStyle: UIAlertControllerStyle.alert)
|
let alert = UIAlertController(title: "Erase Password Store Data?", message: "This will delete all local data and settings. Password store data on your remote server will not be affected.", preferredStyle: UIAlertControllerStyle.alert)
|
||||||
alert.addAction(UIAlertAction(title: "Erase Password Data", style: UIAlertActionStyle.destructive, handler: {[unowned self] (action) -> Void in
|
alert.addAction(UIAlertAction(title: "Erase Password Data", style: UIAlertActionStyle.destructive, handler: {[unowned self] (action) -> Void in
|
||||||
SVProgressHUD.show(withStatus: "Erasing ...")
|
SVProgressHUD.show(withStatus: "Erasing ...")
|
||||||
PasswordStore.shared.erase()
|
self.passwordStore.erase()
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreErased")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreErased")))
|
||||||
self.navigationController!.popViewController(animated: true)
|
self.navigationController!.popViewController(animated: true)
|
||||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||||
|
|
@ -40,7 +41,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
|
||||||
SVProgressHUD.show(withStatus: "Resetting ...")
|
SVProgressHUD.show(withStatus: "Resetting ...")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
do {
|
do {
|
||||||
let numberDiscarded = try PasswordStore.shared.reset()
|
let numberDiscarded = try self.passwordStore.reset()
|
||||||
if numberDiscarded > 0 {
|
if numberDiscarded > 0 {
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreChangeDiscarded")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreChangeDiscarded")))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,11 @@ import ObjectiveGit
|
||||||
|
|
||||||
class CommitLogsTableViewController: UITableViewController {
|
class CommitLogsTableViewController: UITableViewController {
|
||||||
var commits: [GTCommit] = []
|
var commits: [GTCommit] = []
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
commits = PasswordStore.shared.getRecentCommits(count: 20)
|
commits = passwordStore.getRecentCommits(count: 20)
|
||||||
navigationItem.title = "Recent Commit Logs"
|
navigationItem.title = "Recent Commit Logs"
|
||||||
navigationController!.navigationBar.topItem!.title = "About"
|
navigationController!.navigationBar.topItem!.title = "About"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ import UIKit
|
||||||
import SwiftyUserDefaults
|
import SwiftyUserDefaults
|
||||||
|
|
||||||
class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
let hideUnknownSwitch: UISwitch = {
|
let hideUnknownSwitch: UISwitch = {
|
||||||
let uiSwitch = UISwitch()
|
let uiSwitch = UISwitch()
|
||||||
uiSwitch.onTintColor = Globals.blue
|
uiSwitch.onTintColor = Globals.blue
|
||||||
|
|
@ -177,7 +178,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
func rememberPassphraseSwitchAction(_ sender: Any?) {
|
func rememberPassphraseSwitchAction(_ sender: Any?) {
|
||||||
Defaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
|
Defaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
|
||||||
if rememberPassphraseSwitch.isOn == false {
|
if rememberPassphraseSwitch.isOn == false {
|
||||||
PasswordStore.shared.pgpKeyPassphrase = nil
|
passwordStore.pgpKeyPassphrase = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
@IBOutlet weak var usernameTextField: UITextField!
|
@IBOutlet weak var usernameTextField: UITextField!
|
||||||
@IBOutlet weak var authSSHKeyCell: UITableViewCell!
|
@IBOutlet weak var authSSHKeyCell: UITableViewCell!
|
||||||
@IBOutlet weak var authPasswordCell: UITableViewCell!
|
@IBOutlet weak var authPasswordCell: UITableViewCell!
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
var password: String?
|
var password: String?
|
||||||
|
|
||||||
var authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod]
|
var authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod]
|
||||||
|
|
@ -41,7 +42,7 @@ class GitServerSettingTableViewController: UITableViewController {
|
||||||
gitRepositoryURLTextField.text = url.absoluteString
|
gitRepositoryURLTextField.text = url.absoluteString
|
||||||
}
|
}
|
||||||
usernameTextField.text = Defaults[.gitRepositoryUsername]
|
usernameTextField.text = Defaults[.gitRepositoryUsername]
|
||||||
password = PasswordStore.shared.gitRepositoryPassword
|
password = passwordStore.gitRepositoryPassword
|
||||||
authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod]
|
authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod]
|
||||||
|
|
||||||
// Grey out ssh option if ssh_key and ssh_key.pub are not present
|
// Grey out ssh option if ssh_key and ssh_key.pub are not present
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,13 @@ class PGPKeyArmorSettingTableViewController: UITableViewController {
|
||||||
@IBOutlet weak var armorPublicKeyTextView: UITextView!
|
@IBOutlet weak var armorPublicKeyTextView: UITextView!
|
||||||
@IBOutlet weak var armorPrivateKeyTextView: UITextView!
|
@IBOutlet weak var armorPrivateKeyTextView: UITextView!
|
||||||
var pgpPassphrase: String?
|
var pgpPassphrase: String?
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
armorPublicKeyTextView.text = Defaults[.pgpPublicKeyArmor]
|
armorPublicKeyTextView.text = Defaults[.pgpPublicKeyArmor]
|
||||||
armorPrivateKeyTextView.text = Defaults[.pgpPrivateKeyArmor]
|
armorPrivateKeyTextView.text = Defaults[.pgpPrivateKeyArmor]
|
||||||
pgpPassphrase = PasswordStore.shared.pgpKeyPassphrase
|
pgpPassphrase = passwordStore.pgpKeyPassphrase
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createSavePassphraseAlert() -> UIAlertController {
|
private func createSavePassphraseAlert() -> UIAlertController {
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,14 @@ class PGPKeySettingTableViewController: UITableViewController {
|
||||||
@IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
|
@IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
|
||||||
@IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
|
@IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
|
||||||
var pgpPassphrase: String?
|
var pgpPassphrase: String?
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
tableView.rowHeight = UITableViewAutomaticDimension
|
tableView.rowHeight = UITableViewAutomaticDimension
|
||||||
pgpPublicKeyURLTextField.text = Defaults[.pgpPublicKeyURL]?.absoluteString
|
pgpPublicKeyURLTextField.text = Defaults[.pgpPublicKeyURL]?.absoluteString
|
||||||
pgpPrivateKeyURLTextField.text = Defaults[.pgpPrivateKeyURL]?.absoluteString
|
pgpPrivateKeyURLTextField.text = Defaults[.pgpPrivateKeyURL]?.absoluteString
|
||||||
pgpPassphrase = PasswordStore.shared.pgpKeyPassphrase
|
pgpPassphrase = passwordStore.pgpKeyPassphrase
|
||||||
}
|
}
|
||||||
|
|
||||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
var passwordImage: UIImage?
|
var passwordImage: UIImage?
|
||||||
var oneTimePasswordIndexPath : IndexPath?
|
var oneTimePasswordIndexPath : IndexPath?
|
||||||
var shouldPopCurrentView = false
|
var shouldPopCurrentView = false
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
let indicatorLable: UILabel = {
|
let indicatorLable: UILabel = {
|
||||||
let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 21))
|
let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 21))
|
||||||
|
|
@ -91,8 +92,8 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
}
|
}
|
||||||
|
|
||||||
var passphrase = ""
|
var passphrase = ""
|
||||||
if Defaults[.isRememberPassphraseOn] && PasswordStore.shared.pgpKeyPassphrase != nil {
|
if Defaults[.isRememberPassphraseOn] && self.passwordStore.pgpKeyPassphrase != nil {
|
||||||
passphrase = PasswordStore.shared.pgpKeyPassphrase!
|
passphrase = self.passwordStore.pgpKeyPassphrase!
|
||||||
self.decryptThenShowPassword(passphrase: passphrase)
|
self.decryptThenShowPassword(passphrase: passphrase)
|
||||||
} else {
|
} else {
|
||||||
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
|
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
|
||||||
|
|
@ -114,7 +115,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
|
|
||||||
func decryptThenShowPassword(passphrase: String) {
|
func decryptThenShowPassword(passphrase: String) {
|
||||||
if Defaults[.isRememberPassphraseOn] {
|
if Defaults[.isRememberPassphraseOn] {
|
||||||
PasswordStore.shared.pgpKeyPassphrase = passphrase
|
self.passwordStore.pgpKeyPassphrase = passphrase
|
||||||
}
|
}
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
do {
|
do {
|
||||||
|
|
@ -188,14 +189,14 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
if self.password!.changed {
|
if self.password!.changed {
|
||||||
SVProgressHUD.show(withStatus: "Saving")
|
SVProgressHUD.show(withStatus: "Saving")
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
PasswordStore.shared.update(passwordEntity: self.passwordEntity!, password: self.password!, progressBlock: { progress in
|
self.passwordStore.update(passwordEntity: self.passwordEntity!, password: self.password!, progressBlock: { progress in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(progress, status: "Encrypting")
|
SVProgressHUD.showProgress(progress, status: "Encrypting")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.passwordEntity!.synced = false
|
self.passwordEntity!.synced = false
|
||||||
PasswordStore.shared.saveUpdated(passwordEntity: self.passwordEntity!)
|
self.passwordStore.saveUpdated(passwordEntity: self.passwordEntity!)
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
self.setTableData()
|
self.setTableData()
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
|
|
@ -296,7 +297,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
self?.tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
|
self?.tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
|
||||||
let imageData = UIImageJPEGRepresentation(image, 1)
|
let imageData = UIImageJPEGRepresentation(image, 1)
|
||||||
if let entity = self?.passwordEntity {
|
if let entity = self?.passwordEntity {
|
||||||
PasswordStore.shared.updateImage(passwordEntity: entity, image: imageData)
|
self?.passwordStore.updateImage(passwordEntity: entity, image: imageData)
|
||||||
}
|
}
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
print(error)
|
print(error)
|
||||||
|
|
@ -373,7 +374,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
footerLabel.numberOfLines = 0
|
footerLabel.numberOfLines = 0
|
||||||
footerLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
|
footerLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
|
||||||
footerLabel.textColor = UIColor.gray
|
footerLabel.textColor = UIColor.gray
|
||||||
let dateString = PasswordStore.shared.getLatestUpdateInfo(filename: (passwordEntity?.path)!)
|
let dateString = self.passwordStore.getLatestUpdateInfo(filename: (passwordEntity?.path)!)
|
||||||
footerLabel.text = "Last Updated: \(dateString)"
|
footerLabel.text = "Last Updated: \(dateString)"
|
||||||
view.addSubview(footerLabel)
|
view.addSubview(footerLabel)
|
||||||
return view
|
return view
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
private var passwordsTableEntries: [PasswordsTableEntry] = []
|
private var passwordsTableEntries: [PasswordsTableEntry] = []
|
||||||
private var filteredPasswordsTableEntries: [PasswordsTableEntry] = []
|
private var filteredPasswordsTableEntries: [PasswordsTableEntry] = []
|
||||||
private var parentPasswordEntity: PasswordEntity? = nil
|
private var parentPasswordEntity: PasswordEntity? = nil
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
private var tapTabBarTime: TimeInterval = 0
|
private var tapTabBarTime: TimeInterval = 0
|
||||||
|
|
||||||
|
|
@ -61,9 +62,9 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
filteredPasswordsTableEntries.removeAll()
|
filteredPasswordsTableEntries.removeAll()
|
||||||
var passwordEntities = [PasswordEntity]()
|
var passwordEntities = [PasswordEntity]()
|
||||||
if Defaults[.isShowFolderOn] {
|
if Defaults[.isShowFolderOn] {
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData(parent: parent)
|
passwordEntities = self.passwordStore.fetchPasswordEntityCoreData(parent: parent)
|
||||||
} else {
|
} else {
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false)
|
passwordEntities = self.passwordStore.fetchPasswordEntityCoreData(withDir: false)
|
||||||
|
|
||||||
}
|
}
|
||||||
passwordsTableEntries = passwordEntities.map {
|
passwordsTableEntries = passwordEntities.map {
|
||||||
|
|
@ -82,7 +83,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.show(withStatus: "Saving")
|
SVProgressHUD.show(withStatus: "Saving")
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
do {
|
do {
|
||||||
try PasswordStore.shared.add(password: controller.password!, progressBlock: { progress in
|
try self.passwordStore.add(password: controller.password!, progressBlock: { progress in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(progress, status: "Encrypting")
|
SVProgressHUD.showProgress(progress, status: "Encrypting")
|
||||||
}
|
}
|
||||||
|
|
@ -107,26 +108,26 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
SVProgressHUD.setDefaultStyle(.light)
|
||||||
SVProgressHUD.show(withStatus: "Sync Password Store")
|
SVProgressHUD.show(withStatus: "Sync Password Store")
|
||||||
let numberOfUnsyncedPasswords = PasswordStore.shared.getNumberOfUnsyncedPasswords()
|
let numberOfUnsyncedPasswords = self.passwordStore.getNumberOfUnsyncedPasswords()
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
do {
|
do {
|
||||||
try PasswordStore.shared.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in
|
try self.passwordStore.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Pull Remote Repository")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if numberOfUnsyncedPasswords > 0 {
|
if numberOfUnsyncedPasswords > 0 {
|
||||||
try PasswordStore.shared.pushRepository(transferProgressBlock: {(current, total, bytes, stop) in
|
try self.passwordStore.pushRepository(transferProgressBlock: {(current, total, bytes, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SVProgressHUD.showProgress(Float(current)/Float(total), status: "Push Remote Repository")
|
SVProgressHUD.showProgress(Float(current)/Float(total), status: "Push Remote Repository")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
PasswordStore.shared.updatePasswordEntityCoreData()
|
self.passwordStore.updatePasswordEntityCoreData()
|
||||||
self.initPasswordsTableEntries(parent: nil)
|
self.initPasswordsTableEntries(parent: nil)
|
||||||
self.reloadTableView(data: self.passwordsTableEntries)
|
self.reloadTableView(data: self.passwordsTableEntries)
|
||||||
PasswordStore.shared.setAllSynced()
|
self.passwordStore.setAllSynced()
|
||||||
self.setNavigationItemTitle()
|
self.setNavigationItemTitle()
|
||||||
Defaults[.lastUpdatedTime] = Date()
|
Defaults[.lastUpdatedTime] = Date()
|
||||||
Defaults[.gitRepositoryPasswordAttempts] = 0
|
Defaults[.gitRepositoryPasswordAttempts] = 0
|
||||||
|
|
@ -283,15 +284,15 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyToPasteboard(from indexPath: IndexPath) {
|
func copyToPasteboard(from indexPath: IndexPath) {
|
||||||
guard PasswordStore.shared.privateKey != nil else {
|
guard self.passwordStore.privateKey != nil else {
|
||||||
Utils.alert(title: "Cannot Copy Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil)
|
Utils.alert(title: "Cannot Copy Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let password = getPasswordEntry(by: indexPath).passwordEntity!
|
let password = getPasswordEntry(by: indexPath).passwordEntity!
|
||||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||||
var passphrase = ""
|
var passphrase = ""
|
||||||
if Defaults[.isRememberPassphraseOn] && PasswordStore.shared.pgpKeyPassphrase != nil {
|
if Defaults[.isRememberPassphraseOn] && self.passwordStore.pgpKeyPassphrase != nil {
|
||||||
passphrase = PasswordStore.shared.pgpKeyPassphrase!
|
passphrase = self.passwordStore.pgpKeyPassphrase!
|
||||||
self.decryptThenCopyPassword(passwordEntity: password, passphrase: passphrase)
|
self.decryptThenCopyPassword(passwordEntity: password, passphrase: passphrase)
|
||||||
} else {
|
} else {
|
||||||
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
|
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
|
||||||
|
|
@ -366,7 +367,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
} else {
|
} else {
|
||||||
title = "Password Store"
|
title = "Password Store"
|
||||||
}
|
}
|
||||||
let numberOfUnsynced = PasswordStore.shared.getNumberOfUnsyncedPasswords()
|
let numberOfUnsynced = self.passwordStore.getNumberOfUnsyncedPasswords()
|
||||||
if numberOfUnsynced == 0 {
|
if numberOfUnsynced == 0 {
|
||||||
navigationItem.title = "\(title)"
|
navigationItem.title = "\(title)"
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -387,7 +388,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
|
|
||||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||||
if identifier == "showPasswordDetail" {
|
if identifier == "showPasswordDetail" {
|
||||||
guard PasswordStore.shared.privateKey != nil else {
|
guard self.passwordStore.privateKey != nil else {
|
||||||
Utils.alert(title: "Cannot Show Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil)
|
Utils.alert(title: "Cannot Show Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil)
|
||||||
if let s = sender as? UITableViewCell {
|
if let s = sender as? UITableViewCell {
|
||||||
let selectedIndexPath = tableView.indexPath(for: s)!
|
let selectedIndexPath = tableView.indexPath(for: s)!
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ class SettingsTableViewController: UITableViewController {
|
||||||
@IBOutlet weak var touchIDTableViewCell: UITableViewCell!
|
@IBOutlet weak var touchIDTableViewCell: UITableViewCell!
|
||||||
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
|
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
|
||||||
@IBOutlet weak var passwordRepositoryTableViewCell: UITableViewCell!
|
@IBOutlet weak var passwordRepositoryTableViewCell: UITableViewCell!
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
@IBAction func cancelPGPKey(segue: UIStoryboardSegue) {
|
@IBAction func cancelPGPKey(segue: UIStoryboardSegue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,7 +34,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
if let controller = segue.source as? PGPKeySettingTableViewController {
|
if let controller = segue.source as? PGPKeySettingTableViewController {
|
||||||
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
|
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
|
||||||
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
|
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
|
||||||
PasswordStore.shared.pgpKeyPassphrase = controller.pgpPassphrase
|
self.passwordStore.pgpKeyPassphrase = controller.pgpPassphrase
|
||||||
Defaults[.pgpKeySource] = "url"
|
Defaults[.pgpKeySource] = "url"
|
||||||
|
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
|
|
@ -41,10 +42,10 @@ class SettingsTableViewController: UITableViewController {
|
||||||
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
do {
|
do {
|
||||||
try PasswordStore.shared.initPGPKey(from: Defaults[.pgpPublicKeyURL]!, keyType: .public)
|
try self.passwordStore.initPGPKey(from: Defaults[.pgpPublicKeyURL]!, keyType: .public)
|
||||||
try PasswordStore.shared.initPGPKey(from: Defaults[.pgpPrivateKeyURL]!, keyType: .secret)
|
try self.passwordStore.initPGPKey(from: Defaults[.pgpPrivateKeyURL]!, keyType: .secret)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.pgpKeyTableViewCell.detailTextLabel?.text = PasswordStore.shared.pgpKeyID
|
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
|
||||||
SVProgressHUD.showSuccess(withStatus: "Success")
|
SVProgressHUD.showSuccess(withStatus: "Success")
|
||||||
SVProgressHUD.dismiss(withDelay: 1)
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
Utils.alert(title: "Rememver to Remove the Key", message: "Remember to remove the key from the server.", controller: self, completion: nil)
|
Utils.alert(title: "Rememver to Remove the Key", message: "Remember to remove the key from the server.", controller: self, completion: nil)
|
||||||
|
|
@ -60,7 +61,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
|
|
||||||
} else if let controller = segue.source as? PGPKeyArmorSettingTableViewController {
|
} else if let controller = segue.source as? PGPKeyArmorSettingTableViewController {
|
||||||
Defaults[.pgpKeySource] = "armor"
|
Defaults[.pgpKeySource] = "armor"
|
||||||
PasswordStore.shared.pgpKeyPassphrase = controller.pgpPassphrase
|
self.passwordStore.pgpKeyPassphrase = controller.pgpPassphrase
|
||||||
if Defaults[.isRememberPassphraseOn] {
|
if Defaults[.isRememberPassphraseOn] {
|
||||||
Utils.addPasswordToKeychain(name: "pgpKeyPassphrase", password: controller.pgpPassphrase!)
|
Utils.addPasswordToKeychain(name: "pgpKeyPassphrase", password: controller.pgpPassphrase!)
|
||||||
}
|
}
|
||||||
|
|
@ -73,10 +74,10 @@ class SettingsTableViewController: UITableViewController {
|
||||||
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
do {
|
do {
|
||||||
try PasswordStore.shared.initPGPKey(with: controller.armorPublicKeyTextView.text, keyType: .public)
|
try self.passwordStore.initPGPKey(with: controller.armorPublicKeyTextView.text, keyType: .public)
|
||||||
try PasswordStore.shared.initPGPKey(with: controller.armorPrivateKeyTextView.text, keyType: .secret)
|
try self.passwordStore.initPGPKey(with: controller.armorPrivateKeyTextView.text, keyType: .secret)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.pgpKeyTableViewCell.detailTextLabel?.text = PasswordStore.shared.pgpKeyID
|
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
|
||||||
SVProgressHUD.showSuccess(withStatus: "Success")
|
SVProgressHUD.showSuccess(withStatus: "Success")
|
||||||
SVProgressHUD.dismiss(withDelay: 1)
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
}
|
}
|
||||||
|
|
@ -105,8 +106,8 @@ class SettingsTableViewController: UITableViewController {
|
||||||
Defaults[.gitRepositoryURL]!.absoluteString != gitRepostiroyURL ||
|
Defaults[.gitRepositoryURL]!.absoluteString != gitRepostiroyURL ||
|
||||||
auth != Defaults[.gitRepositoryAuthenticationMethod] ||
|
auth != Defaults[.gitRepositoryAuthenticationMethod] ||
|
||||||
username != Defaults[.gitRepositoryUsername] ||
|
username != Defaults[.gitRepositoryUsername] ||
|
||||||
password != PasswordStore.shared.gitRepositoryPassword ||
|
password != self.passwordStore.gitRepositoryPassword ||
|
||||||
PasswordStore.shared.repositoryExisted() == false {
|
self.passwordStore.repositoryExisted() == false {
|
||||||
|
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.setDefaultStyle(.light)
|
SVProgressHUD.setDefaultStyle(.light)
|
||||||
|
|
@ -128,7 +129,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
|
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
|
||||||
dispatchQueue.async {
|
dispatchQueue.async {
|
||||||
do {
|
do {
|
||||||
try PasswordStore.shared.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
|
try self.passwordStore.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
|
||||||
credential: gitCredential,
|
credential: gitCredential,
|
||||||
transferProgressBlock:{ (git_transfer_progress, stop) in
|
transferProgressBlock:{ (git_transfer_progress, stop) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
@ -141,7 +142,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
PasswordStore.shared.updatePasswordEntityCoreData()
|
self.passwordStore.updatePasswordEntityCoreData()
|
||||||
Defaults[.lastUpdatedTime] = Date()
|
Defaults[.lastUpdatedTime] = Date()
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
|
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
|
||||||
|
|
@ -187,7 +188,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setPGPKeyTableViewCellDetailText() {
|
private func setPGPKeyTableViewCellDetailText() {
|
||||||
if let pgpKeyID = PasswordStore.shared.pgpKeyID {
|
if let pgpKeyID = self.passwordStore.pgpKeyID {
|
||||||
pgpKeyTableViewCell.detailTextLabel?.text = pgpKeyID
|
pgpKeyTableViewCell.detailTextLabel?.text = pgpKeyID
|
||||||
} else {
|
} else {
|
||||||
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
|
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
|
||||||
|
|
@ -224,7 +225,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
alert.addTextField(configurationHandler: {(textField: UITextField!) in
|
alert.addTextField(configurationHandler: {(textField: UITextField!) in
|
||||||
textField.text = PasswordStore.shared.gitRepositoryPassword
|
textField.text = self.passwordStore.gitRepositoryPassword
|
||||||
textField.isSecureTextEntry = true
|
textField.isSecureTextEntry = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -337,9 +338,9 @@ class SettingsTableViewController: UITableViewController {
|
||||||
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
PasswordStore.shared.initPGPKeys()
|
self.passwordStore.initPGPKeys()
|
||||||
|
|
||||||
let key: PGPKey = PasswordStore.shared.getPgpPrivateKey()
|
let key: PGPKey = self.passwordStore.getPgpPrivateKey()
|
||||||
Defaults[.pgpKeySource] = "file"
|
Defaults[.pgpKeySource] = "file"
|
||||||
|
|
||||||
if (key.isEncrypted) {
|
if (key.isEncrypted) {
|
||||||
|
|
@ -348,7 +349,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
SVProgressHUD.dismiss()
|
SVProgressHUD.dismiss()
|
||||||
self.pgpKeyTableViewCell.detailTextLabel?.text = PasswordStore.shared.pgpKeyID
|
self.pgpKeyTableViewCell.detailTextLabel?.text = self.passwordStore.pgpKeyID
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ class LabelTableViewCell: UITableViewCell {
|
||||||
|
|
||||||
@IBOutlet weak var contentLabel: UILabel!
|
@IBOutlet weak var contentLabel: UILabel!
|
||||||
@IBOutlet weak var titleLabel: UILabel!
|
@IBOutlet weak var titleLabel: UILabel!
|
||||||
|
let passwordStore = PasswordStore.shared
|
||||||
|
|
||||||
var isPasswordCell = false
|
var isPasswordCell = false
|
||||||
var isURLCell = false
|
var isURLCell = false
|
||||||
|
|
@ -126,10 +127,10 @@ class LabelTableViewCell: UITableViewCell {
|
||||||
// commit
|
// commit
|
||||||
if password.changed {
|
if password.changed {
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
PasswordStore.shared.update(passwordEntity: passwordEntity, password: password, progressBlock: {_ in })
|
self.passwordStore.update(passwordEntity: passwordEntity, password: password, progressBlock: {_ in })
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
passwordEntity.synced = false
|
passwordEntity.synced = false
|
||||||
PasswordStore.shared.saveUpdated(passwordEntity: passwordEntity)
|
self.passwordStore.saveUpdated(passwordEntity: passwordEntity)
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
// reload so that the "unsynced" symbol could be added
|
// reload so that the "unsynced" symbol could be added
|
||||||
self.passwordTableView?.tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: UITableViewRowAnimation.automatic)
|
self.passwordTableView?.tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: UITableViewRowAnimation.automatic)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue