Guest User

Untitled

a guest
Jun 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. guard emailAddress.text != "" , password.text != "" , fullName.text != ""
  2. else {
  3. errorOutlet.isHidden = false
  4. errorOutlet.text = "one or more fields are empty."
  5. UIApplication.shared.endIgnoringInteractionEvents()
  6. return SVProgressHUD.dismiss()
  7. }
  8.  
  9. if password.text != "" , emailAddress.text != "" , fullName.text != "" {
  10. Auth.auth().createUser(withEmail: emailAddress.text! , password: password.text!, completion: { (user, error) in
  11.  
  12. if let error = error {
  13. print(error.localizedDescription)
  14. SVProgressHUD.dismiss()
  15. UIApplication.shared.endIgnoringInteractionEvents()
  16.  
  17. if let errCode = AuthErrorCode(rawValue: error._code) {
  18. switch errCode {
  19.  
  20. case .emailAlreadyInUse:
  21. self.errorOutlet.isHidden = false
  22. self.errorOutlet.text = "The email you entered is already in use"
  23.  
  24. case .invalidEmail:
  25. self.errorOutlet.isHidden = false
  26. self.errorOutlet.text = "The Email you entered is invalid"
  27.  
  28. case .internalError:
  29. self.errorOutlet.isHidden = false
  30. self.errorOutlet.text = "An internal error occured! Try again."
  31.  
  32. case .networkError:
  33. self.errorOutlet.isHidden = false
  34. self.errorOutlet.text = "Check your internet connection."
  35.  
  36. case .weakPassword :
  37. self.errorOutlet.isHidden = false
  38. self.errorOutlet.text = "Your password should contain more than 7 characters"
  39.  
  40. default : break
  41.  
  42. }
  43. }
  44. }
  45.  
  46.  
  47.  
  48. // the auth returns a user
  49. if let user = user {
  50.  
  51. let changeRequest = Auth.auth().currentUser!.createProfileChangeRequest()
  52. changeRequest.displayName = self.fullName.text!
  53. changeRequest.commitChanges(completion: nil)
  54.  
  55. let imageRef = self.userStorage.child("(user.uid).jpg")
  56. let data = UIImageJPEGRepresentation(self.profileImage.image!, 0.5)
  57. let uploadTask = imageRef.putData(data! , metadata: nil, completion: { (metadata, err) in
  58. if err != nil {
  59. print(err!.localizedDescription)
  60.  
  61. //error
  62.  
  63.  
  64. Auth.auth().currentUser?.delete(completion: nil)
  65. self.errorOutlet.isHidden = false
  66. self.errorOutlet.text = "An error occured. Try again!"
  67. UIApplication.shared.endIgnoringInteractionEvents()
  68. SVProgressHUD.dismiss()
  69.  
  70. }
  71.  
  72.  
  73. imageRef.downloadURL(completion: { (url , er) in
  74. // in case of error
  75. if er != nil{
  76. print(er!.localizedDescription)
  77. SVProgressHUD.dismiss()
  78. Auth.auth().currentUser?.delete(completion: nil)
  79. self.errorOutlet.isHidden = false
  80. self.errorOutlet.text = "An error occured. Try again!"
  81. UIApplication.shared.endIgnoringInteractionEvents()
  82. }
Add Comment
Please, Sign In to add comment