Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- guard let image = profilePicture.image else { return }
- guard let password = passwordField.text else { return }
- guard let email = emailField.text else { return }
- // guard let username = usernameField.text else { return }
- SVProgressHUD.show()
- Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
- if error != nil{
- SVProgressHUD.dismiss()
- let alert = UIAlertController(title: "Error", message: "Please insert a valid email address and a password of at least 6 characters", preferredStyle: UIAlertController.Style.alert)
- alert.addAction(UIAlertAction(title: "Try again", style: UIAlertAction.Style.default, handler: nil))
- self.present(alert, animated: true, completion: nil)
- self.emailField.text = ""
- self.passwordField.text = ""
- }
- if let user = Auth.auth().currentUser{
- let imageName = NSUUID().uuidString
- let storageRef = Storage.storage().reference().child("(user.uid)/(imageName).jpeg")
- if let uploadData = image.jpegData(compressionQuality: 0.75){
- storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
- if error != nil{
- print(error!)
- return
- }
- print(metadata ?? "success")
- storageRef.downloadURL(completion: { (url, error) in
- guard let downloadURL = url else {
- print("an error occured after uploading and then getting the URL")
- return
- }
- let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
- changeRequest?.photoURL = downloadURL
- changeRequest?.commitChanges { (error) in
- //handle error
- }
- })
- SVProgressHUD.dismiss()
- })
- }
- }
- // print("Registration succesful")
- // SVProgressHUD.dismiss()
- }
- }
- guard let uid = Auth.auth().currentUser?.uid else { return }
- let databaseRef = Database.database().reference().child("users/profile/(uid)")
- let userObject = [
- "photoURL": profileImageURL.absoluteString
- ] as [String:Any]
- databaseRef.setValue(userObject) { error, ref in
- completion(error == nil)
- }
- }
Add Comment
Please, Sign In to add comment