passforios/pass/Controllers/EditPasswordTableViewController.swift

49 lines
1.9 KiB
Swift
Raw Normal View History

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
import passKit
2017-02-13 01:15:42 +08:00
class EditPasswordTableViewController: PasswordEditorTableViewController {
override func viewDidLoad() {
tableData = [
2019-02-13 21:31:40 +01:00
[[.type: PasswordEditorCellType.nameCell, .title: "Name".localize(), .content: password!.namePath]],
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "Password".localize(), .content: password!.password]],
[[.type: PasswordEditorCellType.additionsCell, .title: "Additions".localize(), .content: password!.additionsPlainText]],
[[.type: PasswordEditorCellType.scanQRCodeCell],
[.type: PasswordEditorCellType.deletePasswordCell]]
2017-02-13 01:15:42 +08:00
]
if PasswordGeneratorFlavour.from(Defaults.passwordGeneratorFlavor) == .RANDOM {
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
}
tableData[1].append([.type: PasswordEditorCellType.memorablePasswordGeneratorCell])
2017-02-13 01:15:42 +08:00
super.viewDidLoad()
}
2018-12-09 16:59:07 -08:00
2017-02-13 01:15:42 +08:00
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
}
2018-12-09 16:59:07 -08:00
2017-02-13 01:15:42 +08:00
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
2017-02-13 11:42:28 +08:00
if segue.identifier == "saveEditPasswordSegue" {
let editedPlainText = plainText
2017-10-15 21:37:00 +08:00
let (name, url) = getNameURL()
if password!.plainText != editedPlainText || password!.url.path != url.path {
password!.updatePassword(name: name, url: url, plainText: editedPlainText)
2017-02-15 21:25:26 +08:00
}
2017-02-13 01:15:42 +08:00
}
}
}