Advertisement
Guest User

Untitled

a guest
May 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <form>
  3.     <div>
  4.       <h5>Personnal information</h5>
  5.       <input type="text" placeholder="Display name" v-model="displayName">
  6.       <input type="file" name="profilePic"
  7.             ref="profilePic"
  8.             accept=".jpg, .jpeg, .png" />
  9.       <button @click.prevent="uploadPicture" class="btn waves-effect waves-light red">Upload</button>
  10.     </div>
  11.    
  12.     <div>
  13.       <h5>Socials account</h5>
  14.       <input type="text" placeholder="Facebook profile" v-model="socials.facebook_url" />
  15.       <input type="text" placeholder="Linkedin profile" v-model="socials.linkedin_url" />
  16.       <input type="text" placeholder="Twitter profile" v-model="socials.twitter_url" />
  17.     </div>
  18.  
  19.     <button @click.prevent="updateProfile" class="btn waves-effect waves-light red">Update</button>
  20.   </form>
  21. </template>
  22.  
  23. <script>
  24. import { firebaseApp, usersRef } from "../../firebase.config.js";
  25. import axios from "axios";
  26. import { settings } from "../../axios.config.js";
  27.  
  28. const instance = axios.create(settings);
  29.  
  30. export default {
  31.   name: "Profile",
  32.   data() {
  33.     return {
  34.       title: "Profile",
  35.       max_size: 1000000,
  36.       isLoading: false,
  37.       displayName: null,
  38.       profile_pic: null,
  39.       socials: {
  40.         facebook_url: "",
  41.         twitter_url: "",
  42.         linkedin_url: ""
  43.       },
  44.       currentUser: firebaseApp.auth().currentUser
  45.     };
  46.   },
  47.   methods: {
  48.     updateProfile() {
  49.       let userProfileData = {
  50.         socials: {
  51.           facebook_url: this.socials.facebook_url,
  52.           twitter_url: this.socials.twitter_url,
  53.           linkedin_url: this.socials.linkedin_url
  54.         },
  55.         photoURL: this.profile_pic,
  56.         displayName: this.displayName
  57.       };
  58.       const userData = {
  59.         displayName: this.displayName,
  60.         photoURL: this.profile_pic
  61.       };
  62.       console.log(userProfileData);
  63.       firebaseApp
  64.         .auth()
  65.         .currentUser.updateProfile(userData)
  66.         .then(() => {
  67.           usersRef.child(this.currentUser.uid).update(userProfileData);
  68.         });
  69.     },
  70.     uploadPicture() {
  71.       const picture = this.$refs.profilePic.files[0];
  72.       this.isLoading = true;
  73.       if (picture.size > this.max_size) {
  74.         return false;
  75.       }
  76.       let formData = new FormData();
  77.       formData.append("image", picture);
  78.  
  79.       instance("https://api.imgur.com/3/image", {
  80.         method: "POST",
  81.         data: formData
  82.       })
  83.         .then(res => {
  84.           this.profile_pic = res.data.data.link;
  85.           this.isLoading = false;
  86.         })
  87.         .catch(err => {
  88.           console.log(err);
  89.         });
  90.     }
  91.   }
  92. };
  93. </script>
  94.  
  95. <style></style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement