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
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2017-02-10 22:15:01 +08:00
|
|
|
|
2017-03-09 03:19:36 +08:00
|
|
|
class AddPasswordTableViewController: PasswordEditorTableViewController {
|
2017-03-16 22:39:03 -07:00
|
|
|
let passwordStore = PasswordStore.shared
|
2017-10-15 16:49:33 +08:00
|
|
|
var defaultDirPrefix = ""
|
2017-02-10 22:15:01 +08:00
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
2017-03-09 03:19:36 +08:00
|
|
|
tableData = [
|
2017-04-27 23:07:22 +08:00
|
|
|
[[.type: PasswordEditorCellType.nameCell, .title: "name"]],
|
2017-05-26 00:37:00 +08:00
|
|
|
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password"]],
|
2017-04-27 23:07:22 +08:00
|
|
|
[[.type: PasswordEditorCellType.additionsCell, .title: "additions"]],
|
2017-04-08 03:08:12 +08:00
|
|
|
[[.type: PasswordEditorCellType.scanQRCodeCell]]
|
2017-03-09 03:19:36 +08:00
|
|
|
]
|
2018-11-28 22:58:24 +01:00
|
|
|
if PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]) == PasswordGeneratorFlavour.RANDOM {
|
2017-05-26 00:37:00 +08:00
|
|
|
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
|
|
|
|
|
}
|
2018-08-30 01:26:45 +08:00
|
|
|
tableData[1].append([.type: PasswordEditorCellType.memorablePasswordGeneratorCell])
|
2017-10-15 16:49:33 +08:00
|
|
|
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
|
|
|
|
2017-03-09 02:39:13 +08:00
|
|
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
|
|
|
|
if identifier == "saveAddPasswordSegue" {
|
|
|
|
|
// check PGP key
|
2017-03-22 17:42:37 -07:00
|
|
|
guard passwordStore.privateKey != nil else {
|
2017-03-09 02:39:13 +08:00
|
|
|
let alertTitle = "Cannot Add Password"
|
|
|
|
|
let alertMessage = "PGP Key is not set. Please set your PGP Key first."
|
|
|
|
|
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
|
|
|
|
return false
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-09 02:39:13 +08:00
|
|
|
// check name
|
2017-10-15 21:37:00 +08:00
|
|
|
guard checkName() == true else {
|
2017-03-09 02:39:13 +08:00
|
|
|
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?) {
|
2017-04-08 03:08:12 +08:00
|
|
|
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()
|
2017-04-23 10:03:09 -07:00
|
|
|
password = Password(name: name, url: url, plainText: plainText)
|
2017-02-11 16:12:10 +08:00
|
|
|
}
|
2017-02-10 22:15:01 +08:00
|
|
|
}
|
|
|
|
|
}
|