Created
April 14, 2016 07:23
-
-
Save charleshkang/f8e2398c2ce0f004342264e05c82ba76 to your computer and use it in GitHub Desktop.
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
@IBAction func createAccount(sender: AnyObject) { | |
let username = usernameField.text | |
let email = emailField.text | |
let password = passwordField.text | |
if username != "" && email != "" && password != "" { | |
// Set Email and Password for the New User. | |
DataService.dataService.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in | |
if error != nil { | |
// There was a problem. | |
self.signupErrorAlert("Oops!", message: "Having some trouble creating your account. Try again.") | |
} else { | |
// Create and Login the New User with authUser | |
DataService.dataService.BASE_REF.authUser(email, password: password, withCompletionBlock: { | |
err, authData in | |
let user = ["provider": authData.provider!, "email": email!, "username": username!] | |
// Seal the deal in DataService.swift. | |
DataService.dataService.createNewAccount(authData.uid, user: user) | |
}) | |
// Store the uid for future access - handy! | |
NSUserDefaults.standardUserDefaults().setValue(result ["uid"], forKey: "uid") | |
// Enter the app. | |
self.performSegueWithIdentifier("NewUserLoggedIn", sender: nil) | |
} | |
}) | |
} else { | |
signupErrorAlert("Oops!", message: "Don't forget to enter your email, password, and a username.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment