Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Firebase
- class SignInVC: UIViewController {
- //outlets
- @IBOutlet weak var emailTF: UITextField!
- @IBOutlet weak var passwordTF: UITextField!
- //action
- @IBAction func onSignInTapped(_ sender: Any) {
- guard let email = emailTF.text,
- email != "",
- let password = passwordTF.text,
- password != ""
- else {
- AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all required fields")
- return
- }
- Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
- guard error == nil else{
- AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
- return
- }
- guard let user = user else { return }
- print(user.email ?? "MISSING EMAIL")
- print(user.displayName ?? "MISSING DISPLAY NAME")
- print(user.uid)
- self.performSegue(withIdentifier: "signInSegue", sender: nil)
- })
- }
- }
- import UIKit
- import Firebase
- class SignUpVC: UIViewController {
- //outlets
- @IBOutlet weak var usernameTF: UITextField!
- @IBOutlet weak var emailTF: UITextField!
- @IBOutlet weak var passwordTF: UITextField!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- //actions
- @IBAction func onSignUpTapped(_ sender: Any) {
- guard let username = usernameTF.text,
- username != "",
- let email = emailTF.text,
- email != "",
- let password = passwordTF.text,
- password != ""
- else {
- AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all fields")
- return
- }
- Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
- guard error == nil else {
- AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
- return
- }
- guard let user = user else { return }
- print(user.email ?? "Missing Email")
- print(user.uid)
- let changeRequest = user.createProfileChangeRequest()
- changeRequest.displayName = username
- changeRequest.commitChanges(completion: { (error) in
- guard error == nil else {
- AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
- return
- }
- self.performSegue(withIdentifier: "signUpSegue", sender: nil)
- })
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement