Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func handleLoginFb(){
- let facebookLogin = FBSDKLoginManager()
- print("LoggedIn")
- facebookLogin.logInWithReadPermissions(["public_profile","email","user_friends"], fromViewController: self, handler: {(facebookResults,facebookError) -> Void in
- if facebookError != nil {
- print("facebook error login")
- return
- }else if facebookResults.isCancelled{
- print("facebook login is canceled")
- }else {
- print("you are i in")
- let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
- FIRAuth.auth()?.signInWithCredential(credential){ (user, error) in
- print("user loged in firebase")
- }
- self.dismissViewControllerAnimated(true, completion: nil)
- }
- } );
- }
- func anonymousLogin(){
- FIRAuth.auth()?.signInAnonymouslyWithCompletion() { (user, error) in
- if (error != nil){
- print(error)
- return
- }
- print("user Loged anonymously with " + user!.uid )
- self.dismissViewControllerAnimated(true, completion: nil)
- }
- }
- func handleLogin(){
- guard let email = emailTextField.text, password = passwordTextField.text
- else {
- print("Form is not valid")
- return
- }
- FIRAuth.auth()?.signInWithEmail(email, password: password, completion: {(user, error ) in
- if (error != nil){
- print(error)
- return
- }
- self.dismissViewControllerAnimated(true, completion: nil)
- })
- }
- func handleRegister(){
- guard let email = emailTextField.text, name = nameTextField.text , password = passwordTextField.text
- else {
- print("Form is not valid")
- return
- }
- FIRAuth.auth()?.createUserWithEmail(email, password:password, completion:{(user: FIRUser?, error) in
- if(error != nil){
- print(error)
- return
- }
- //User successfuly authentified
- print("User successfuly authentified ")
- guard let uid = user?.uid else {
- return
- }
- let ref = FIRDatabase.database().referenceFromURL("https://e-commerce-cpa-57e7d.firebaseio.com/")
- let usersReference = ref.child("users").child(uid)
- let values = ["name": name , "email": email ]
- usersReference.updateChildValues(values,withCompletionBlock: {(err, ref) in
- if (err != nil){
- print("error occured")
- print(err)
- return
- }
- print("User succesfuly registred")
- })
- })
- self.dismissViewControllerAnimated(true, completion: nil)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement