passforios/pass/Controllers/AddPasswordTableViewController.swift

62 lines
2.3 KiB
Swift
Raw Normal View History

2017-02-10 22:15:01 +08:00
//
// AddPasswordTableViewController.swift
// pass
//
// Created by Mingshen Sun on 10/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import passKit
2017-02-10 22:15:01 +08:00
2017-03-09 03:19:36 +08:00
class AddPasswordTableViewController: PasswordEditorTableViewController {
let passwordStore = PasswordStore.shared
var defaultDirPrefix = ""
2017-02-10 22:15:01 +08:00
override func viewDidLoad() {
2017-03-09 03:19:36 +08:00
tableData = [
[[.type: PasswordEditorCellType.nameCell, .title: "name"]],
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password"]],
[[.type: PasswordEditorCellType.additionsCell, .title: "additions"]],
[[.type: PasswordEditorCellType.scanQRCodeCell]]
2017-03-09 03:19:36 +08:00
]
if PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]) == .RANDOM {
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
}
tableData[1].append([.type: PasswordEditorCellType.memorablePasswordGeneratorCell])
tableData[0][0][PasswordEditorCellKey.content] = defaultDirPrefix
2017-02-10 22:15:01 +08:00
super.viewDidLoad()
2017-02-11 20:45:56 +08:00
}
2018-12-09 16:59:07 -08:00
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "saveAddPasswordSegue" {
// check PGP key
2019-07-20 00:16:51 +08:00
guard passwordStore.pgpAgent?.isImported ?? false else {
2019-01-14 20:57:45 +01:00
let alertTitle = "CannotAddPassword".localize()
let alertMessage = "PgpKeyNotSet.".localize()
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
return false
}
2018-12-09 16:59:07 -08:00
// check name
2017-10-15 21:37:00 +08:00
guard checkName() == true else {
return false
}
}
return true
}
2018-12-09 16:59:07 -08:00
2017-02-10 22:15:01 +08:00
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if segue.identifier == "saveAddPasswordSegue" {
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-03-09 03:19:36 +08:00
}
2017-10-15 21:37:00 +08:00
let (name, url) = getNameURL()
password = Password(name: name, url: url, plainText: plainText)
2017-02-11 16:12:10 +08:00
}
2017-02-10 22:15:01 +08:00
}
}