add erase data function

This commit is contained in:
Bob Sun 2017-02-07 16:45:14 +08:00
parent 373c6500f0
commit e2a2774664
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
6 changed files with 173 additions and 12 deletions

View file

@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
94BA784B85E071D25EE89B59 /* libPods-pass.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */; };
DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC1208571E35EBE60042942E /* ObjectiveGit.framework */; };
DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */; };
DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914941E434301007FF592 /* LabelTableViewCell.swift */; };
DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */; };
DC5734AE1E439AD400D09270 /* PasswordsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5734AD1E439AD400D09270 /* PasswordsViewController.swift */; };
@ -39,6 +40,7 @@
ADCE7A5C3CCC67D7D21BB3C4 /* libPods-pass.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-pass.a"; sourceTree = BUILT_PRODUCTS_DIR; };
AEAD6B31EAF5D061447A68CC /* Pods-pass.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pass.release.xcconfig"; path = "Pods/Target Support Files/Pods-pass/Pods-pass.release.xcconfig"; sourceTree = "<group>"; };
DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = "<group>"; };
DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsTableViewController.swift; sourceTree = "<group>"; };
DC4914941E434301007FF592 /* LabelTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelTableViewCell.swift; sourceTree = "<group>"; };
DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTableViewController.swift; sourceTree = "<group>"; };
DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Objective-CBridgingHeader.h"; sourceTree = "<group>"; };
@ -113,6 +115,7 @@
DC917BD51E2E8231000FDF54 /* pass */ = {
isa = PBXGroup;
children = (
DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */,
DC4A746D1E30FBDE00E8EB18 /* Objective-CBridgingHeader.h */,
DC917BE21E2E8231000FDF54 /* Info.plist */,
DC917BD61E2E8231000FDF54 /* AppDelegate.swift */,
@ -297,6 +300,7 @@
files = (
DCC408A41E2FCC9E00F29B0E /* PasswordStore.swift in Sources */,
DC8963C01E38EEB900828B09 /* SSHKeySettingTableViewController.swift in Sources */,
DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */,
DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */,
DC7E6EEA1E432E48006C2443 /* Password.swift in Sources */,
DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */,

View file

@ -0,0 +1,33 @@
//
// AdvancedSettingsTableViewController.swift
// pass
//
// Created by Mingshen Sun on 7/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class AdvancedSettingsTableViewController: UITableViewController {
@IBOutlet weak var eraseDataTableViewCell: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView.cellForRow(at: indexPath) == eraseDataTableViewCell {
print("erase data")
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
PasswordStore.shared.erase()
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreErased")))
self.navigationController!.popViewController(animated: true)
}))
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.cancel, handler:nil))
self.present(alert, animated: true, completion: nil)
tableView.deselectRow(at: indexPath, animated: true)
}
}
}

View file

@ -148,6 +148,30 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="6U8-ue-MhL">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="advancedTableViewCell" textLabel="MKj-d0-8q3" style="IBUITableViewCellStyleDefault" id="tQN-gu-iRe">
<rect key="frame" x="0.0" y="279.5" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="tQN-gu-iRe" id="Xs0-LN-r43">
<rect key="frame" x="0.0" y="0.0" width="381" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Advanced" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="MKj-d0-8q3">
<rect key="frame" x="15" y="0.0" width="364" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Rqu-AW-ZNQ" kind="show" id="Wpt-vk-aK8"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="h1X-0d-XeE" id="fLr-S4-22Y"/>
@ -730,5 +754,49 @@
</objects>
<point key="canvasLocation" x="3430" y="3286"/>
</scene>
<!--Advanced Settings Table View Controller-->
<scene sceneID="ipZ-fd-H8e">
<objects>
<tableViewController id="Rqu-AW-ZNQ" customClass="AdvancedSettingsTableViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="HJS-4B-x1b">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections>
<tableViewSection id="ugP-R2-9M7">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="K2K-Bx-g7Z" style="IBUITableViewCellStyleDefault" id="NI1-Kd-hyH">
<rect key="frame" x="0.0" y="35" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="NI1-Kd-hyH" id="yLe-T2-TWF">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Erase All Password Store Data" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="K2K-Bx-g7Z">
<rect key="frame" x="15" y="0.0" width="384" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.50196081400000003" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="Rqu-AW-ZNQ" id="nMf-E9-ekz"/>
<outlet property="delegate" destination="Rqu-AW-ZNQ" id="FIc-7F-8PL"/>
</connections>
</tableView>
<connections>
<outlet property="eraseDataTableViewCell" destination="NI1-Kd-hyH" id="NtJ-f4-oxb"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="adh-5o-YYB" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3429" y="4028"/>
</scene>
</scenes>
</document>

View file

@ -123,17 +123,8 @@ class PasswordStore {
}
func updatePasswordEntityCoreData() {
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
let passwordCategoryEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordCategoryEntity")
let passwordEntityDeleteRequest = NSBatchDeleteRequest(fetchRequest: passwordEntityFetchRequest)
let passwordCategoryEntityDeleteRequest = NSBatchDeleteRequest(fetchRequest: passwordCategoryEntityFetchRequest)
do {
try context.execute(passwordEntityDeleteRequest)
try context.execute(passwordCategoryEntityDeleteRequest)
} catch let error as NSError {
print(error)
}
deleteCoreData(entityName: "PasswordEntity")
deleteCoreData(entityName: "PasswordCategoryEntity")
let fm = FileManager.default
fm.enumerator(atPath: storeURL.path)?.forEach({ (e) in
@ -186,4 +177,56 @@ class PasswordStore {
func updateRemoteRepo() {
}
func deleteCoreData(entityName: String) {
let deleteFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: entityName)
let deleteRequest = NSBatchDeleteRequest(fetchRequest: deleteFetchRequest)
do {
try context.execute(deleteRequest)
} catch let error as NSError {
print(error)
}
}
func erase() {
let fm = FileManager.default
do {
if fm.fileExists(atPath: storeURL.path) {
try fm.removeItem(at: storeURL)
}
if fm.fileExists(atPath: Globals.shared.secringPath) {
try fm.removeItem(atPath: Globals.shared.secringPath)
}
if fm.fileExists(atPath: Globals.shared.sshPrivateKeyPath.path) {
try fm.removeItem(at: Globals.shared.sshPrivateKeyPath)
}
if fm.fileExists(atPath: Globals.shared.sshPublicKeyPath.path) {
try fm.removeItem(at: Globals.shared.sshPublicKeyPath)
}
} catch {
print(error)
}
deleteCoreData(entityName: "PasswordEntity")
deleteCoreData(entityName: "PasswordCategoryEntity")
Defaults[.pgpKeyURL] = nil
Defaults[.pgpKeyPassphrase] = ""
Defaults[.pgpKeyID] = ""
Defaults[.pgpKeyUserID] = ""
Defaults[.gitRepositoryURL] = nil
Defaults[.gitRepositoryAuthenticationMethod] = ""
Defaults[.gitRepositoryUsername] = ""
Defaults[.gitRepositoryPassword] = ""
Defaults[.gitRepositorySSHPublicKeyURL] = nil
Defaults[.gitRepositorySSHPrivateKeyURL] = nil
Defaults[.gitRepositorySSHPrivateKeyPassphrase] = nil
Defaults[.lastUpdatedTime] = nil
}
}

View file

@ -55,6 +55,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
super.viewDidLoad()
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
generateSections(item: passwordEntities!)
tableView.delegate = self
tableView.dataSource = self
@ -160,6 +162,13 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
print("actOnPasswordUpdatedNotification")
}
func actOnPasswordStoreErasedNotification() {
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
reloadTableView(data: passwordEntities!)
print("actOnPasswordErasedNotification")
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "showPasswordDetail" {
if Defaults[.pgpKeyID] == "" {

View file

@ -105,6 +105,10 @@ class SettingsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if Defaults[.pgpKeyID] == "" {
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
} else {