Last active
June 28, 2017 18:53
-
-
Save cryptixcoder/cbbc5a6dc1cc5408034a6acd572daabc to your computer and use it in GitHub Desktop.
Firebase Latitude Check
This file contains hidden or 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
@IBAction func createAccount(_ sender: Any) { | |
let email = self.emailTextField.text! | |
let password = self.passwordTextField.text! | |
if firstName.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter Your First Name.") | |
} | |
if lastName.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter Your Last Name.") | |
} | |
if companyPosition.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter Your Company Position.") | |
} | |
if businessName.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The Business Name.") | |
} | |
if businessStreet.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The Business's Street.") | |
} | |
if businessCity.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The City.") | |
} | |
if businessState.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The State.") | |
} | |
if businessZIP.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The ZIP.") | |
} | |
if businessPhone.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The Business's Phone.") | |
} | |
if businessWebsite.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The Business Website.") | |
} | |
if businessLatitude.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The Business Latitude.") | |
} | |
if businessLongitude.text == "" { | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "Please Enter The Business Longitude.") | |
} | |
print("This is a rest") | |
if email != "" && password != "" && self.firstName.text != "" && self.lastName.text != "" && self.companyPosition.text != "" && self.businessName.text != "" && self.businessStreet.text != "" && self.businessCity.text != "" && self.businessState.text != "" && self.businessZIP.text! != "" && self.businessPhone.text != "" && self.businessWebsite.text != "" && self.businessLatitude.text != "" && self.businessLongitude.text != "" { | |
self.ref.child("Businesses").queryOrdered(byChild: "businessLatitude").queryEqual(toValue: self.businessLatitude.text!).observeSingleEvent(of: .value, with: { (snapshot) in | |
if(snapshot.value! is NSNull){ | |
print("Latitude doesn't exists") | |
CommonUtils.sharedUtils.showProgress(self.view, label: "Registering...") | |
FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error) in | |
if error == nil { | |
FIREmailPasswordAuthProvider.credential(withEmail: email, password: password) | |
self.ref.child("Businesses").child(user!.uid).setValue(["firstName":self.firstName.text!,"lastName":self.lastName.text!, "companyPosition":self.companyPosition.text!,"businessName":self.businessName.text!, "businessStreet":self.businessStreet.text!, "businessCity":self.businessCity.text!, "businessState":self.businessState.text!, "businessZIP":self.businessZIP.text!, "businessPhone":self.businessPhone.text!, "businessWebsite":self.businessWebsite.text!,"businessLatitude":self.businessLatitude.text!, "businessLongitude":self.businessLongitude.text!, "approvalStatus":self.isApproved, "email":email ]) | |
CommonUtils.sharedUtils.hideProgress() | |
let photoViewController = self.storyboard?.instantiateViewController(withIdentifier: "BusinessProfile") | |
self.navigationController?.pushViewController(photoViewController!, animated: true) | |
} else { | |
DispatchQueue.main.async(execute: {() -> Void in | |
CommonUtils.sharedUtils.hideProgress() | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: (error?.localizedDescription)!) | |
}) | |
} | |
}) | |
} | |
else{ | |
print("Latitude exists") | |
CommonUtils.sharedUtils.hideProgress() | |
CommonUtils.sharedUtils.showAlert(self, title: "Error", message: "This Place Is Already Registered") | |
} | |
}) | |
} | |
else { | |
let alert = UIAlertController(title: "Error", message: "Enter email & password!", preferredStyle: .alert) | |
let action = UIAlertAction(title: "OK", style: .default, handler: nil) | |
alert.addAction(action) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment