Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- guard emailAddress.text != "" , password.text != "" , fullName.text != ""
- else {
- errorOutlet.isHidden = false
- errorOutlet.text = "one or more fields are empty."
- UIApplication.shared.endIgnoringInteractionEvents()
- return SVProgressHUD.dismiss()
- }
- if password.text != "" , emailAddress.text != "" , fullName.text != "" {
- Auth.auth().createUser(withEmail: emailAddress.text! , password: password.text!, completion: { (user, error) in
- if let error = error {
- print(error.localizedDescription)
- SVProgressHUD.dismiss()
- UIApplication.shared.endIgnoringInteractionEvents()
- if let errCode = AuthErrorCode(rawValue: error._code) {
- switch errCode {
- case .emailAlreadyInUse:
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "The email you entered is already in use"
- case .invalidEmail:
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "The Email you entered is invalid"
- case .internalError:
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "An internal error occured! Try again."
- case .networkError:
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "Check your internet connection."
- case .weakPassword :
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "Your password should contain more than 7 characters"
- default : break
- }
- }
- }
- // the auth returns a user
- if let user = user {
- let changeRequest = Auth.auth().currentUser!.createProfileChangeRequest()
- changeRequest.displayName = self.fullName.text!
- changeRequest.commitChanges(completion: nil)
- let imageRef = self.userStorage.child("(user.uid).jpg")
- let data = UIImageJPEGRepresentation(self.profileImage.image!, 0.5)
- let uploadTask = imageRef.putData(data! , metadata: nil, completion: { (metadata, err) in
- if err != nil {
- print(err!.localizedDescription)
- //error
- Auth.auth().currentUser?.delete(completion: nil)
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "An error occured. Try again!"
- UIApplication.shared.endIgnoringInteractionEvents()
- SVProgressHUD.dismiss()
- }
- imageRef.downloadURL(completion: { (url , er) in
- // in case of error
- if er != nil{
- print(er!.localizedDescription)
- SVProgressHUD.dismiss()
- Auth.auth().currentUser?.delete(completion: nil)
- self.errorOutlet.isHidden = false
- self.errorOutlet.text = "An error occured. Try again!"
- UIApplication.shared.endIgnoringInteractionEvents()
- }
Add Comment
Please, Sign In to add comment