Guest User

Untitled

a guest
Nov 28th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. @IBAction func createAccount(sender: AnyObject) {
  2.  
  3. var username = usernameField.text
  4. var email = emailField.text
  5. var password = passwordField.text
  6. if username != "" && email != "" && password != "" {
  7. FIRAuth.auth()?.createUserWithEmail(email!, password: password!, completion: { (user, error) in
  8. databaseRef.child("users/(user.uid)/username").setValue(username)
  9. databaseRef.child("users/(user.uid)/password").setValue(password)
  10. databaseRef.child("users/(user.uid)/uid").setValue(user?.uid)
  11. })
  12. } else {
  13. print("please complete all fields")
  14. }
  15. }
  16.  
  17. @IBAction func createAccount(sender: AnyObject) {
  18.  
  19. var username = usernameField.text
  20. var email = emailField.text
  21. var password = passwordField.text
  22.  
  23. if username != "" && email != "" && password != "" {
  24.  
  25. FIRAuth.auth()?.createUserWithEmail(email!, password: password!, completion: { (user, error) in
  26.  
  27. if let user = FIRAuth.auth()?.currentUser {
  28.  
  29. databaseRef.child("users/(user.uid)/username").setValue(username)
  30. databaseRef.child("users/(user.uid)/password").setValue(password)
  31. databaseRef.child("users/(user.uid)/email").setValue(email)
  32.  
  33. print(user.uid)
  34.  
  35. } else {
  36.  
  37. print("no user")
  38.  
  39. }
  40.  
  41. })
  42.  
  43.  
  44. } else {
  45.  
  46. print("please complete all fields")
  47.  
  48. }
  49.  
  50. Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
  51. // guard against errors and optionals
  52. guard error == nil else { return }
  53. guard let user = user else { return }
  54. let userObject = [
  55. "uid": user.uid,
  56. "username": username,
  57. "password": password, // I don't recommend storing passwords like this by the way
  58. "email": email
  59. ] as [String:Any]
  60. databaseRef.setValue(userObject)
  61. }
Add Comment
Please, Sign In to add comment