Guest User

Untitled

a guest
Dec 11th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. if emailUserPicString == "" {
  2. let alertController = UIAlertController(title: "Profile Picture Error", message: "Don't forget to choose a profile picture!", preferredStyle: UIAlertControllerStyle.alert)
  3.  
  4. let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {(alert :UIAlertAction!) in
  5. })
  6. alertController.addAction(okAction)
  7.  
  8. self.present(alertController, animated: true, completion: nil)
  9.  
  10. return
  11. } else {
  12. self.performSegue(withIdentifier: "emailToSetup", sender: nil)
  13. }
  14.  
  15. @IBAction func emailSignupNextPressed(_ sender: Any) {
  16. // Make sure text fields aren't empty
  17. guard nameField.text != "", emailField.text != "", passwordField.text != "", confirmPasswordField.text != "" else {return}
  18.  
  19. if passwordField.text == confirmPasswordField.text {
  20. Auth.auth().createUser(withEmail: emailField.text!, password: passwordField.text!, completion: { (user, error) in
  21.  
  22. if let error = error {
  23. print(error.localizedDescription)
  24. }
  25.  
  26. if let user = user {
  27.  
  28. guard let uid = Auth.auth().currentUser?.uid else {return}
  29.  
  30. // Use name as Firebase display name for readability
  31. let changeRequest = Auth.auth().currentUser!.createProfileChangeRequest()
  32. changeRequest.displayName = self.nameField.text!
  33. changeRequest.commitChanges(completion: nil)
  34.  
  35. // Create child node from userStorage "users". Profile image set to user's unique ID
  36. let imageRef = self.userStorage.child("(uid).jpg")
  37. let data = UIImageJPEGRepresentation(self.selectProfileImageView.image!, 0.5)
  38.  
  39. // Upload image to Firebase
  40. let uploadTask = imageRef.putData(data!, metadata: nil, completion: { (metadata, err) in
  41. if err != nil {
  42. print(err!.localizedDescription)
  43. }
  44. imageRef.downloadURL(completion: { (url, er) in
  45. if er != nil {
  46. print(er?.localizedDescription as Any)
  47. }
  48. if let url = url {
  49.  
  50. emailUserPicString = url.absoluteString
  51. print("nnnpic:(emailUserPicString)nnn")
  52. if emailUserPicString == "" {
  53. let alertController = UIAlertController(title: "Profile Picture Error", message: "Don't forget to choose a profile picture!", preferredStyle: UIAlertControllerStyle.alert)
  54.  
  55. let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {(alert :UIAlertAction!) in
  56. })
  57. alertController.addAction(okAction)
  58.  
  59. self.present(alertController, animated: true, completion: nil)
  60.  
  61. return
  62. } else {
  63. self.performSegue(withIdentifier: "emailToSetup", sender: nil)
  64. }
  65. }
  66. })
  67. })
  68. uploadTask.resume()
  69. }
  70. })
  71. } else {
  72. print("Passwords don't match")
  73. passwordAlert()
  74. }
  75. }
Add Comment
Please, Sign In to add comment