2017-02-13 01:15:42 +08:00
|
|
|
//
|
|
|
|
|
// EditPasswordTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 12/2/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2017-02-13 01:15:42 +08:00
|
|
|
|
|
|
|
|
class EditPasswordTableViewController: PasswordEditorTableViewController {
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
tableData = [
|
2017-04-27 23:07:22 +08:00
|
|
|
[[.type: PasswordEditorCellType.nameCell, .title: "name", .content: password!.namePath]],
|
2017-05-26 00:37:00 +08:00
|
|
|
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password", .content: password!.password]],
|
2018-11-11 18:09:52 +01:00
|
|
|
[[.type: PasswordEditorCellType.additionsCell, .title: "additions", .content: password!.additionsPlainText]],
|
2017-04-08 03:08:12 +08:00
|
|
|
[[.type: PasswordEditorCellType.scanQRCodeCell],
|
|
|
|
|
[.type: PasswordEditorCellType.deletePasswordCell]]
|
2017-02-13 01:15:42 +08:00
|
|
|
]
|
2017-06-13 11:42:49 +08:00
|
|
|
if let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]],
|
2017-05-26 00:37:00 +08:00
|
|
|
lengthSetting.max > lengthSetting.min {
|
|
|
|
|
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
|
|
|
|
|
}
|
2018-08-30 01:26:45 +08:00
|
|
|
tableData[1].append([.type: PasswordEditorCellType.memorablePasswordGeneratorCell])
|
2017-02-13 01:15:42 +08:00
|
|
|
super.viewDidLoad()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
|
|
|
|
if identifier == "saveEditPasswordSegue" {
|
2017-10-15 21:37:00 +08:00
|
|
|
// check name
|
|
|
|
|
guard checkName() == true else {
|
2017-04-27 23:26:12 +08:00
|
|
|
return false
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
2017-04-08 03:08:12 +08:00
|
|
|
super.prepare(for: segue, sender: sender)
|
2017-02-13 11:42:28 +08:00
|
|
|
if segue.identifier == "saveEditPasswordSegue" {
|
2017-04-27 23:26:12 +08:00
|
|
|
var plainText = (fillPasswordCell?.getContent())!
|
|
|
|
|
if let additionsString = additionsCell?.getContent(), additionsString.isEmpty == false {
|
|
|
|
|
plainText.append("\n")
|
|
|
|
|
plainText.append(additionsString)
|
2017-04-23 10:03:09 -07:00
|
|
|
}
|
2017-10-15 21:37:00 +08:00
|
|
|
let (name, url) = getNameURL()
|
2018-11-10 22:38:12 -08:00
|
|
|
if password!.plainText != plainText || password!.url.path != url.path {
|
2017-04-23 10:03:09 -07:00
|
|
|
password!.updatePassword(name: name, url: url, plainText: plainText)
|
2017-02-15 21:25:26 +08:00
|
|
|
}
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|