mirror of
https://github.com/confirmedcode/Lockdown-iOS.git
synced 2025-12-21 12:14:02 +01:00
fix: update Account tab after signing up / in from Protect tab, + other fixes
This commit is contained in:
@@ -15,12 +15,6 @@ import CocoaLumberjackSwift
|
||||
|
||||
class EmailSignInViewController: BaseViewController, UITextFieldDelegate, Loadable {
|
||||
|
||||
struct Delegate {
|
||||
var accountStateDidChange: () -> () = { }
|
||||
}
|
||||
|
||||
var delegate = Delegate()
|
||||
|
||||
@IBOutlet weak var emailField: UITextField!
|
||||
@IBOutlet weak var passwordField: UITextField!
|
||||
|
||||
@@ -70,9 +64,9 @@ class EmailSignInViewController: BaseViewController, UITextFieldDelegate, Loadab
|
||||
try setAPICredentials(email: email, password: password)
|
||||
setAPICredentialsConfirmed(confirmed: true)
|
||||
self.hideLoadingView()
|
||||
self.delegate.accountStateDidChange()
|
||||
NotificationCenter.default.post(name: AccountUI.accountStateDidChange, object: self)
|
||||
self.showPopupDialog(title: "Success! 🎉", message: "You've successfully signed in.", acceptButton: "Okay") {
|
||||
self.dismiss(animated: true, completion: {
|
||||
self.presentingViewController?.dismiss(animated: true, completion: {
|
||||
// logged in and confirmed - update this email with the receipt and refresh VPN credentials
|
||||
firstly { () -> Promise<SubscriptionEvent> in
|
||||
try Client.subscriptionEvent()
|
||||
|
||||
@@ -15,7 +15,6 @@ import PromiseKit
|
||||
class EmailSignUpViewController: BaseViewController, UITextFieldDelegate, Loadable {
|
||||
|
||||
struct Delegate {
|
||||
var accountStateDidChange: () -> () = { }
|
||||
var showSignIn: () -> () = { }
|
||||
}
|
||||
|
||||
@@ -120,11 +119,11 @@ class EmailSignUpViewController: BaseViewController, UITextFieldDelegate, Loadab
|
||||
popup.addButtons([
|
||||
DefaultButton(title: NSLocalizedString("Okay", comment: ""), dismissOnTap: true) {
|
||||
self.hideLoadingView()
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
self.presentingViewController?.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
])
|
||||
self.present(popup, animated: true, completion: nil)
|
||||
self.delegate.accountStateDidChange()
|
||||
NotificationCenter.default.post(name: AccountUI.accountStateDidChange, object: self)
|
||||
}
|
||||
catch {
|
||||
self.showPopupDialog(title: "Error Saving Credentials", message: "Couldn't save credentials to local keychain. Please report this error to team@lockdownprivacy.com.", acceptButton: "Okay")
|
||||
|
||||
@@ -10,23 +10,23 @@ import UIKit
|
||||
|
||||
enum AccountUI {
|
||||
|
||||
static func presentCreateAccount(on vc: UIViewController, completion: @escaping () -> () = { }) {
|
||||
static let accountStateDidChange = Notification.Name("AccountUIAccountStateDidChangeNotification")
|
||||
|
||||
static func presentCreateAccount(on vc: UIViewController) {
|
||||
let storyboard = UIStoryboard.main
|
||||
let viewController = storyboard.instantiateViewController(withIdentifier: "emailSignUpViewController") as! EmailSignUpViewController
|
||||
viewController.delegate.showSignIn = { [weak vc] in
|
||||
if let strongVC = vc {
|
||||
AccountUI.presentSignInToAccount(on: strongVC, completion: completion)
|
||||
AccountUI.presentSignInToAccount(on: strongVC)
|
||||
}
|
||||
}
|
||||
viewController.delegate.accountStateDidChange = completion
|
||||
|
||||
vc.present(viewController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
static func presentSignInToAccount(on vc: UIViewController, completion: @escaping () -> () = { }) {
|
||||
static func presentSignInToAccount(on vc: UIViewController) {
|
||||
let storyboard = UIStoryboard.main
|
||||
let viewController = storyboard.instantiateViewController(withIdentifier: "emailSignInViewController") as! EmailSignInViewController
|
||||
viewController.delegate.accountStateDidChange = completion
|
||||
|
||||
vc.present(viewController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
@@ -28,17 +28,23 @@ final class AccountViewController: BaseViewController, Loadable {
|
||||
tableView.contentInset.top += 12
|
||||
tableView.tableFooterView = UIView()
|
||||
|
||||
tableView.clear()
|
||||
createTable()
|
||||
}
|
||||
|
||||
do {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountStateDidChange), name: AccountUI.accountStateDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func accountStateDidChange() {
|
||||
assert(Thread.isMainThread)
|
||||
self.reloadTable()
|
||||
}
|
||||
|
||||
func reloadTable() {
|
||||
// always reload when called
|
||||
// guard isViewLoaded else {
|
||||
// return
|
||||
// }
|
||||
|
||||
tableView.rows = []
|
||||
tableView.clear()
|
||||
createTable()
|
||||
tableView.reloadData()
|
||||
}
|
||||
@@ -49,9 +55,9 @@ final class AccountViewController: BaseViewController, Loadable {
|
||||
var title = "⚠️ Not Signed In"
|
||||
var message: String? = "Sign up below to unlock benefits of a Lockdown account."
|
||||
var firstButton = DefaultCell(title: NSLocalizedString("Sign Up | Sign In", comment: ""), height: buttonHeight, dismissOnTap: true) {
|
||||
AccountUI.presentCreateAccount(on: self) { [weak self] in
|
||||
self?.reloadTable()
|
||||
}
|
||||
// AccountViewController will update itself by observing
|
||||
// AccountUI.accountStateDidChange notification
|
||||
AccountUI.presentCreateAccount(on: self)
|
||||
}
|
||||
firstButton.backgroundView = UIView()
|
||||
firstButton.backgroundView?.backgroundColor = UIColor.tunnelsBlue
|
||||
|
||||
@@ -489,7 +489,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
])
|
||||
self.getCurrentViewController()?.present(popup, animated: true, completion: nil)
|
||||
DispatchQueue.main.async {
|
||||
(self.window?.rootViewController as? MainTabBarController)?.accountViewController.reloadTable()
|
||||
NotificationCenter.default.post(name: AccountUI.accountStateDidChange, object: self)
|
||||
}
|
||||
}
|
||||
.catch { error in
|
||||
|
||||
Reference in New Issue
Block a user