70 lines
2.1 KiB
Swift
70 lines
2.1 KiB
Swift
//
|
|
// SignUpViewController.swift
|
|
// Firebase test
|
|
//
|
|
// Created by Max Hunt on 06/05/2020.
|
|
// Copyright © 2020 smt. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import FirebaseAuth
|
|
import Firebase
|
|
|
|
class SignUpViewController: UIViewController {
|
|
|
|
@IBOutlet weak var fName: UITextField!
|
|
@IBOutlet weak var lName: UITextField!
|
|
@IBOutlet weak var email: UITextField!
|
|
@IBOutlet weak var pwd: UITextField!
|
|
@IBOutlet weak var signUpBtn: UIButton!
|
|
@IBOutlet weak var errLbl: UILabel!
|
|
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
errLbl.isHidden = true
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
// MARK: - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
// Get the new view controller using segue.destination.
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
|
|
@IBAction func signUpTapped(_ sender: Any) {
|
|
Auth.auth().createUser(withEmail: self.email.text!, password: self.pwd.text!) { (result, err) in
|
|
if let err = err {
|
|
self.errLbl.isHidden = false
|
|
self.errLbl.text = err.localizedDescription
|
|
}
|
|
else {
|
|
let db = Firestore.firestore()
|
|
db.collection("users").addDocument(data: [
|
|
"First Name":self.fName.text!,
|
|
"Last Name":self.lName.text!,
|
|
"email":self.email.text!,
|
|
"uid":result!.user.uid
|
|
]) { (error) in
|
|
if error != nil {
|
|
self.errLbl.isHidden = false
|
|
self.errLbl.text = error!.localizedDescription
|
|
}
|
|
}
|
|
let HomeViewController = self.storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
|
|
self.view.window?.rootViewController = HomeViewController
|
|
self.view.window?.makeKeyAndVisible()
|
|
//goto home
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|