From b7bad2d3a0d6f5b2c71dd0073a6693c6bfe37eab Mon Sep 17 00:00:00 2001 From: Yannick Spreen Date: Sun, 16 May 2021 21:09:51 +0200 Subject: [PATCH] Outdated protection. (#44) --- DGCAWallet.xcodeproj/project.pbxproj | 3 - DGCAWallet/Extensions/UIViewController.swift | 78 -------------------- DGCAWallet/Services/GatewayConnection.swift | 6 ++ DGCAWallet/ViewControllers/Home.swift | 4 + 4 files changed, 10 insertions(+), 81 deletions(-) delete mode 100644 DGCAWallet/Extensions/UIViewController.swift diff --git a/DGCAWallet.xcodeproj/project.pbxproj b/DGCAWallet.xcodeproj/project.pbxproj index 5ceb742..6c1aee7 100644 --- a/DGCAWallet.xcodeproj/project.pbxproj +++ b/DGCAWallet.xcodeproj/project.pbxproj @@ -36,7 +36,6 @@ CEA6D6F8261F8D2900715333 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEA6D6F6261F8D2900715333 /* LaunchScreen.storyboard */; }; CEA6D703261F8D2900715333 /* DGCAWalletTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6D702261F8D2900715333 /* DGCAWalletTests.swift */; }; CEA6D70E261F8D2900715333 /* DGCAWalletUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6D70D261F8D2900715333 /* DGCAWalletUITests.swift */; }; - CEA6E561264058B50066DC8E /* UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6E560264058B50066DC8E /* UIViewController.swift */; }; CEC7FEDF264C5A41005561BA /* context.jsonc in Resources */ = {isa = PBXBuildFile; fileRef = CEC7FEDE264C5A41005561BA /* context.jsonc */; }; CED2726026398683003D47A9 /* UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = CED2725F26398683003D47A9 /* UIFont.swift */; }; CED949CA263B50CE00883558 /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = CED949C9263B50CE00883558 /* List.swift */; }; @@ -164,7 +163,6 @@ children = ( CED2725F26398683003D47A9 /* UIFont.swift */, CE8096D8263B07BB00A65AD6 /* UIColor.swift */, - CEA6E560264058B50066DC8E /* UIViewController.swift */, ); path = Extensions; sourceTree = ""; @@ -472,7 +470,6 @@ CE56BC07264068110044FD3F /* GatewayConnection.swift in Sources */, CEA6D6F0261F8D2700715333 /* Scan.swift in Sources */, CE13CF23262DDF810070C80E /* RoundedButton.swift in Sources */, - CEA6E561264058B50066DC8E /* UIViewController.swift in Sources */, CEA6D6EC261F8D2700715333 /* AppDelegate.swift in Sources */, CE891305263581D900CB92AF /* Home.swift in Sources */, CEA15563262F6DAB0024B7AC /* CertViewerDelegate.swift in Sources */, diff --git a/DGCAWallet/Extensions/UIViewController.swift b/DGCAWallet/Extensions/UIViewController.swift deleted file mode 100644 index f8e853c..0000000 --- a/DGCAWallet/Extensions/UIViewController.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -/*- - * ---license-start - * eu-digital-green-certificates / dgca-wallet-app-ios - * --- - * Copyright (C) 2021 T-Systems International GmbH and all other contributors - * --- - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ---license-end - */ -// -// UIViewController.swift -// DGCAWallet -// -// Created by Yannick Spreen on 5/3/21. -// - -import UIKit -import SwiftDGC - -extension UIViewController { - func showInputDialog( - title: String? = nil, - subtitle: String? = nil, - actionTitle: String? = l10n("btn.okay"), - cancelTitle: String? = l10n("btn.cancel"), - inputPlaceholder: String? = nil, - inputKeyboardType: UIKeyboardType = UIKeyboardType.default, - handler: ((_ text: String?) -> Void)? = nil - ) { - let alert = UIAlertController(title: title, message: subtitle, preferredStyle: .alert) - alert.addTextField { (textField: UITextField) in - textField.placeholder = inputPlaceholder - textField.keyboardType = inputKeyboardType - } - alert.addAction(UIAlertAction(title: actionTitle, style: .default) { _ in - guard let textField = alert.textFields?.first else { - handler?(nil) - return - } - handler?(textField.text) - }) - alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in - handler?(nil) - }) - - present(alert, animated: true, completion: nil) - } - func showAlert( - title: String? = nil, - subtitle: String? = nil, - actionTitle: String? = l10n("btn.okay"), - cancelTitle: String? = nil, - handler: ((Bool) -> Void)? = nil - ) { - let alert = UIAlertController(title: title, message: subtitle, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: actionTitle, style: .default) { _ in - handler?(true) - }) - if let cancelTitle = cancelTitle { - alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel) { _ in - handler?(false) - }) - } - - present(alert, animated: true, completion: nil) - } -} diff --git a/DGCAWallet/Services/GatewayConnection.swift b/DGCAWallet/Services/GatewayConnection.swift index 2530805..da8ee06 100644 --- a/DGCAWallet/Services/GatewayConnection.swift +++ b/DGCAWallet/Services/GatewayConnection.swift @@ -29,6 +29,7 @@ import Foundation import Alamofire import SwiftDGC import SwiftyJSON +import UIKit struct GatewayConnection: ContextConnection { public static func claim(cert: HCert, with tan: String?, completion: ((Bool, String?) -> Void)?) { @@ -95,6 +96,11 @@ struct GatewayConnection: ContextConnection { let json = JSON(parseJSONC: string) LocalData.sharedInstance.config.merge(other: json) LocalData.sharedInstance.save() + if LocalData.sharedInstance.versionedConfig["outdated"].bool == true { + ( + UIApplication.shared.windows[0].rootViewController as? UINavigationController + )?.popToRootViewController(animated: false) + } } } static var config: JSON { diff --git a/DGCAWallet/ViewControllers/Home.swift b/DGCAWallet/ViewControllers/Home.swift index 2454fa4..fed1b42 100644 --- a/DGCAWallet/ViewControllers/Home.swift +++ b/DGCAWallet/ViewControllers/Home.swift @@ -64,6 +64,10 @@ class HomeVC: UIViewController { } func checkId() { + if LocalData.sharedInstance.versionedConfig["outdated"].bool == true { + showAlert(title: l10n("info.outdated"), subtitle: l10n("info.outdated.body")) + return + } SecureBackground.checkId { [weak self] in if $0 { self?.performSegue(withIdentifier: "list", sender: self)