This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Firebase | |
import FBSDKCoreKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension LoginViewController: GIDSignInUIDelegate{ | |
func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) { | |
viewController.dismiss(animated: true, completion: nil) | |
NotificationCenter.default.post(name: .closeLoginVC, object: nil) | |
} | |
func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension FirebaseManager: GIDSignInDelegate { | |
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { | |
if let error = error { | |
print(error.localizedDescription) | |
return | |
} | |
if let user = user { | |
let idToken = user.authentication.idToken ?? "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
FIRApp.configure() | |
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID | |
GIDSignIn.sharedInstance().delegate = firebaseManager | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func logout() { | |
do{ | |
try FIRAuth.auth()?.signOut() | |
} catch let signOutError as NSError { | |
print ("Error signing out: %@", signOutError) | |
} | |
NotificationCenter.default.post(name: .closeMainVC, object: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func forgotPasswordTapped(with sender: LoginView) { | |
let alertController = UIAlertController(title: "Forgot My Password", message: "To reset your password, please enter your email address.", preferredStyle: .alert) let sendAction = UIAlertAction(title: "Send", style: .default) { (action) in | |
let emailField = alertController.textFields![0] | |
if let email = emailField.text { | |
FIRAuth.auth()?.sendPasswordReset(withEmail: email, completion: { (error) in | |
if let error = error { | |
let alertController = UIAlertController(title: "Error", message: "\(error.localizedDescription)", preferredStyle: .alert) | |
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) | |
alertController.addAction(okAction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func signUpTapped(with sender: CreateAccountView) { | |
if checkIfAllFieldsValid() { | |
if let email = self.createView.emailTextField.text, let password = self.createView.passwordTextField.text { | |
FirebaseManager.createAccount(with: email, and: password, completion: { (success) in | |
if !success { | |
let alertController = UIAlertController(title: "Error", message: "Creating an account was failed. Please Try Again", preferredStyle: .alert) | |
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) | |
alertController.addAction(okAction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Firebase | |
import FirebaseAuth | |
import UIKit | |
class FirebaseManager { | |
class func createAccount(with email: String, and password: String, completion:@escaping (Bool)->Void) { | |
FIRAuth.auth()!.createUser(withEmail: email, password: password, completion: { (user, error) in |