Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.24 KB | None | 0 0
  1. <template>
  2.   <form @submit.prevent="validateBeforeSubmit">
  3.     <title-page :propsTitle="'Réinitialisation du mot de passe'"></title-page>
  4.  
  5.     <div v-if="afficher" class="columns is-mobile is-centered">
  6.       <div class="column is-half tailleFormInscription">
  7.         <label class="label">Nouveau mot de passe</label>
  8.         <div class="field">
  9.           <div class="control is-expanded has-icons-left has-icons-right">
  10.             <input
  11.              name="password"
  12.              class="input"
  13.              v-model="nouveauMDP"
  14.              v-validate="'required'"
  15.              :class="{'input': true, 'is-danger': errors.has('password') }"
  16.              type="password"
  17.              placeholder="**********"
  18.              ref="password"
  19.            >
  20.             <span class="icon is-small is-left">
  21.               <i class="fas fa-lock"></i>
  22.             </span>
  23.             <span class="icon is-small is-right is-hidden">
  24.               <i v-show="errors.has('password')" class="fa fa-warning"></i>
  25.             </span>
  26.           </div>
  27.           <span
  28.            v-show="errors.has('password')"
  29.            class="help is-danger"
  30.          >{{ errors.first('password') }}</span>
  31.         </div>
  32.  
  33.         <div class="field">
  34.           <label class="label">Confirmation du mot de passe</label>
  35.           <div class="control is-expanded has-icons-left has-icons-right">
  36.             <input
  37.              name="password_confirmation"
  38.              v-validate="'required|confirmed:password'"
  39.              type="password"
  40.              :class="{'input': true, 'is-danger': errors.has('password_confirmation')}"
  41.              placeholder="**********"
  42.              data-vv-as="password"
  43.            >
  44.             <span class="icon is-small is-left">
  45.               <i class="fas fa-lock"></i>
  46.             </span>
  47.             <span class="icon is-small is-right is-hidden">
  48.               <i v-show="errors.has('password_confirmation')" class="fa fa-warning"></i>
  49.             </span>
  50.           </div>
  51.           <span
  52.            v-show="errors.has('password_confirmation')"
  53.            class="help is-danger"
  54.          >{{ errors.first('password_confirmation') }}</span>
  55.         </div>
  56.  
  57.         <div class="field">
  58.           <div class="field is-grouped is-narrow">
  59.             <div class="control">
  60.               <button class="button is-link" type="submit">Soumettre</button>
  61.             </div>
  62.             <div class="control">
  63.               <router-link to="/" class="button is-text">Annuler</router-link>
  64.             </div>
  65.           </div>
  66.         </div>
  67.       </div>
  68.     </div>
  69.  
  70.     <popup
  71.      :propsPopupHide="popupHide"
  72.      :propsMessageClass="popupMessageClass"
  73.      :propsMessageSuccessError="popupMessageContent"
  74.    ></popup>
  75.   </form>
  76. </template>
  77.  
  78. <script>
  79. import TitlePage from "@/components/static_rendering/TitrePage";
  80. import axios from "axios";
  81. import PopUpSavedCornerRightDown from "@/components/reactivity/PopUpSavedCornerRightDown.vue";
  82.  
  83. export default {
  84.   name: "ChangePassword",
  85.   components: {
  86.     TitlePage,
  87.     popup: PopUpSavedCornerRightDown
  88.   },
  89.  
  90.   data() {
  91.     return {
  92.       user: localStorage.getItem("user"),
  93.       key: "",
  94.       userId: "",
  95.       nouveauMDP: "",
  96.       confirmPassword: "",
  97.       afficher: false,
  98.       popupHide: true,
  99.       popupMessageClass: "",
  100.       popupMessageContent: {}
  101.     };
  102.   },
  103.  
  104.   methods: {
  105.     reinitliaserPassword() {
  106.       console.log("is clicked");
  107.       axios({
  108.         method: "PUT",
  109.         url: "api/Users/ReinitialiserMotDePasse/",
  110.         contentType: "application/json; charset=utf-8",
  111.         dataType: "json",
  112.         data: {
  113.           Id: this.userId,
  114.           NouveauMDP: this.nouveauMDP,
  115.           keyReinilisationMDP: this.key
  116.         }
  117.       })
  118.         .then(response => {
  119.           console.log(response);
  120.           this.updateDBPopup("is-success", null);
  121.           setTimeout(this.redirect, 2500);
  122.         })
  123.         .catch(error => {
  124.           console.log(error);
  125.           this.updateDBPopup("is-danger", {
  126.             warning: "Échec de la réinitialisation du mot de passe"
  127.           });
  128.           setTimeout(this.closePopup, 2500);
  129.         });
  130.     },
  131.  
  132.     validateBeforeSubmit() {
  133.       this.$validator.validateAll().then(result => {
  134.         if (result) {
  135.           console.log("is clicked");
  136.           axios({
  137.             method: "PUT",
  138.             url: "api/Users/ReinitialiserMotDePasse/",
  139.             contentType: "application/json; charset=utf-8",
  140.             dataType: "json",
  141.             data: {
  142.               Id: this.userId,
  143.               NouveauMDP: this.nouveauMDP,
  144.               keyReinilisationMDP: this.key
  145.             }
  146.           })
  147.             .then(response => {
  148.               console.log(response);
  149.               this.updateDBPopup("is-success", null);
  150.               setTimeout(this.redirect, 2500);
  151.             })
  152.             .catch(error => {
  153.               console.log(error);
  154.               this.updateDBPopup("is-danger", {
  155.                 warning: "Échec de la réinitialisation du mot de passe"
  156.               });
  157.               setTimeout(this.closePopup, 2500);
  158.             });
  159.  
  160.           // eslint-disable-next-line
  161.           return;
  162.         }
  163.         alert("Corrigez les erreurs!");
  164.       });
  165.     },
  166.  
  167.     updateDBPopup(stringClass, objectMessage) {
  168.       this.popupHide = false;
  169.       this.popupMessageClass = stringClass;
  170.       this.popupMessageContent = objectMessage;
  171.     },
  172.     redirect() {
  173.       this.$router.push("/");
  174.     },
  175.     closePopup() {
  176.       this.popupHide = true;
  177.     },
  178.     VerifyKey() {
  179.       var url_string = window.location.href;
  180.       let url = new URL(url_string);
  181.       this.userId = url.searchParams.get("userid");
  182.       this.key = url.searchParams.get("key");
  183.       console.log(this.userId);
  184.       console.log(this.key);
  185.  
  186.       axios
  187.         .get(`apiv2/users/VerifyKey/${this.key}/${this.userId}`)
  188.         .then(responseUser => {
  189.           console.log("marche");
  190.         })
  191.         .then(() => {
  192.           this.afficher = true;
  193.         })
  194.         .catch(() => {
  195.           console.log("erreur");
  196.         });
  197.     }
  198.   },
  199.   created() {
  200.     console.log("created called.");
  201.     this.VerifyKey();
  202.   }
  203. };
  204. </script>
  205.  
  206. <style scoped>
  207. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement