Created
May 7, 2018 05:41
-
-
Save PattyAppier/8da0541b68f39d53dee3ec27884ccb79 to your computer and use it in GitHub Desktop.
PattysCharmDriverApp_LogIn
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
``` | |
// ViewController.swift | |
// PattysCharmDriver | |
// Created by Patty Chen on 5/4 | |
// Copyright © 2018年 Patty Chen. All rights reserved. | |
import UIKit | |
import FirebaseAuth | |
import Firebase | |
class ViewController: UIViewController { | |
//May 4, to add some log-in outlay features in App. | |
@IBOutlet weak var emailTextField: UITextField! | |
@IBOutlet weak var passwordTextField: UITextField! | |
@IBOutlet weak var passengerOrDriverSW: UISwitch! | |
@IBOutlet weak var passengerLabel: UILabel! | |
@IBOutlet weak var driverLabel: UILabel! | |
@IBOutlet weak var topButton: UIButton! | |
@IBOutlet weak var bottomButton: UIButton! | |
@IBOutlet weak var passwordLabel: UILabel! | |
@IBOutlet weak var mailAddressLabel: UILabel! | |
@IBOutlet weak var pattysCharmDriverLabel: UILabel! | |
var signUpStatus = true | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
//override func didReceiveMemoryWarning() { | |
// super.didReceiveMemoryWarning() | |
//} May 4,delete thid func | |
//May 4, to add some log-in action features & dispaly alert from error occuring in App. | |
@IBAction func signUP(_ sender: Any) { | |
if emailTextField.text == "" || passwordTextField.text == "" { | |
displaySignUpAlert(title: "Missing Info", message: "Plz put in enough info !") | |
} else { | |
if let mail = emailTextField.text { | |
if let password = passwordTextField.text { | |
if signUpStatus { | |
//signUP | |
Auth.auth().createUser(withEmail: mail, password: password,completion: { (user, error) in | |
if error != nil { | |
self.displaySignUpAlert(title: "Error", message: error!.localizedDescription) | |
} else { | |
print("Well done, Sign Up go smoothly!") | |
} | |
}) // May 4, https://firebase.google.com/docs/auth/ios/start validate the email address and password provided by the user, then pass them to the createUser method. | |
} else { | |
//logIn | |
// May 7, | |
Auth.auth().signIn(withEmail: mail, password: password,completion: { (user, error) in | |
if error != nil { | |
self.displaySignUpAlert(title: "Error", message: error!.localizedDescription) | |
} else { | |
print("Well done, Sign Up go smoothly!") | |
} | |
}) //Create a form that allows existing users to sign in using their email address and password. When a user completes the form, call the signIn method. | |
} | |
} | |
} | |
} | |
} | |
// May 4, addd alert function | |
func displaySignUpAlert(title: String, message: String) { | |
let alertDisplayer = UIAlertController(title: title, message: message, preferredStyle: .alert) // declare an instant of Class, and initiate by below code sentence. | |
alertDisplayer.addAction(UIAlertAction(title: "Bravo, go ahead!", style: .default, handler: nil))// this is a Enclosure style function in Swift4. | |
self.present(alertDisplayer, animated: true, completion: nil) // self means the View Controller instance by deafault. | |
} | |
@IBAction func logIN(_ sender: Any ) { | |
if signUpStatus { | |
topButton.setTitle("Log In", for: .normal) | |
bottomButton.setTitle("Switch to Sign Up", for: .normal) | |
passengerLabel.isHidden = true | |
driverLabel.isHidden = true | |
passengerOrDriverSW.isHidden = true | |
signUpStatus = false | |
} else { | |
topButton.setTitle("Sign Up", for: .normal) | |
bottomButton.setTitle("Switch to Log In", for: .normal) | |
passengerLabel.isHidden = false | |
driverLabel.isHidden = false | |
passengerOrDriverSW.isHidden = false | |
signUpStatus = true | |
} | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment