Merge and resolve conflits

This commit is contained in:
Bob Sun 2017-04-23 10:06:31 -07:00
commit 914f072ab2
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 27 additions and 68 deletions

View file

@ -11,7 +11,6 @@ import AVFoundation
class OTPScannerController: QRScannerController {
var tempPassword: Password?
var scannedOTP: String?
// MARK: - AVCaptureMetadataOutputObjectsDelegate Methods
@ -27,14 +26,11 @@ class OTPScannerController: QRScannerController {
// check whether it is a valid result
if let scannedString = metadataObj.stringValue {
if let (accept, message) = delegate?.checkScannedOutput(line: scannedString) {
scannerOutput.text = message
if accept == true {
captureSession?.stopRunning()
scannedOTP = scannedString
tempPassword = Password(name: "empty", url: nil, plainText: scannedString)
// set scannerOutput
setupOneTimePasswordMessage()
} else {
scannerOutput.text = message
presentSaveAlert()
}
} else {
// no delegate, show the scanned result
@ -50,34 +46,28 @@ class OTPScannerController: QRScannerController {
}
}
private func setupOneTimePasswordMessage() {
if let password = tempPassword {
if password.otpType == .hotp {
// hotp, no need to refresh
let (title, content) = password.getOtpStrings()!
scannerOutput.text = "\(title):\(content)"
} else if password.otpType == .totp {
// totp, refresh
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {
[weak weakSelf = self] timer in
private func presentSaveAlert() {
// initialize alert
let password = Password(name: "empty", url: nil, plainText: scannedOTP!)
let (title, content) = password.getOtpStrings()!
let alert = UIAlertController(title: "Success", message: "\(title): \(content)", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.default, handler: {[unowned self] (action) -> Void in
self.delegate?.handleScannedOutput(line: self.scannedOTP!)
self.navigationController?.popViewController(animated: true)
}))
if password.otpType == .hotp {
// hotp, no need to refresh
self.present(alert, animated: true, completion: nil)
} else if password.otpType == .totp {
// totp, refresh otp
self.present(alert, animated: true) {
let alertController = self.presentedViewController as! UIAlertController
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {_ in
let (title, content) = password.getOtpStrings()!
weakSelf?.scannerOutput.text = "\(title):\(content)"
alertController.message = "\(title): \(content)"
}
}
}
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "saveAddScannedOTPSegue" {
return tempPassword != nil
}
return true
}
// override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// super.prepare(for: segue, sender: sender)
// if segue.identifier == "saveAddScannedOTPSegue" {
// delegate?.handleScannedOutput(line: scannedOTP)
// }
// }
}

View file

@ -226,12 +226,4 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
@IBAction private func cancelOTPScanner(segue: UIStoryboardSegue) {
}
@IBAction func saveScannedOTP(segue: UIStoryboardSegue) {
if let controller = segue.source as? OTPScannerController {
if let scannedOTP = controller.scannedOTP {
insertScannedOTPFields(scannedOTP)
}
}
}
}