From 589876bb36cc77d40eb84b811675d11d2dbf3b86 Mon Sep 17 00:00:00 2001 From: Enayatullah Naseri Date: Mon, 6 Jan 2020 20:21:08 -0800 Subject: [PATCH 1/2] Added signout code for firebase, and a simple alert for public to sign up. --- .../PrivateJokesTableViewController.swift | 10 +++++++++- .../PublicJokesTableViewController.swift | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/DadJokes/DadJokes/View Controllers/PrivateJokesTableViewController.swift b/DadJokes/DadJokes/View Controllers/PrivateJokesTableViewController.swift index 446c06e..2d603c7 100644 --- a/DadJokes/DadJokes/View Controllers/PrivateJokesTableViewController.swift +++ b/DadJokes/DadJokes/View Controllers/PrivateJokesTableViewController.swift @@ -8,6 +8,7 @@ import UIKit import CoreData +import Firebase class PrivateJokesTableViewController: UITableViewController { @@ -39,8 +40,15 @@ class PrivateJokesTableViewController: UITableViewController { tableView.reloadData() } + // Sign out firebase @IBAction func signOutTapped(_ sender: Any) { - self.navigationController?.popToRootViewController(animated: true) + let firebaseAuth = Auth.auth() + do { + try firebaseAuth.signOut() + self.navigationController?.popToRootViewController(animated: true) + } catch let signOutError as NSError { + print ("Error signing out: %@", signOutError) + } } // MARK: - Table view data source diff --git a/DadJokes/DadJokes/View Controllers/PublicJokesTableViewController.swift b/DadJokes/DadJokes/View Controllers/PublicJokesTableViewController.swift index 6ab711d..442e3fa 100644 --- a/DadJokes/DadJokes/View Controllers/PublicJokesTableViewController.swift +++ b/DadJokes/DadJokes/View Controllers/PublicJokesTableViewController.swift @@ -14,12 +14,23 @@ class PublicJokesTableViewController: UITableViewController { super.viewDidLoad() } + // alert override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + + let alert = UIAlertController(title: "Sign up Alert!", message: "To view more or add dad jokes please sign up, under private tab.", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in + NSLog("The \"OK\" alert occured.") + })) + self.present(alert, animated: true, completion: nil) } // MARK: - Table view data source - +// Creating an alert to sign up +// func createAlert(title: String, message: String) { +// let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.alert) +// +// } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 0 } From 010222befe22449014a474021a9d9323a5c71337 Mon Sep 17 00:00:00 2001 From: Enayatullah Naseri Date: Thu, 9 Jan 2020 19:16:11 -0800 Subject: [PATCH 2/2] Added custom alert and updated sign out error --- DadJokes/DadJokes/Base.lproj/Main.storyboard | 5 +--- .../DadJokes/Helpers/DJErrorMessage.swift | 5 ++++ .../PrivateJokesTableViewController.swift | 4 +-- .../PublicJokesTableViewController.swift | 25 +++++++++++-------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/DadJokes/DadJokes/Base.lproj/Main.storyboard b/DadJokes/DadJokes/Base.lproj/Main.storyboard index 1ec411b..4526a45 100644 --- a/DadJokes/DadJokes/Base.lproj/Main.storyboard +++ b/DadJokes/DadJokes/Base.lproj/Main.storyboard @@ -280,9 +280,6 @@ - - - @@ -305,7 +302,7 @@ - +