Blame view

src/pages/Administrator/resetPassword.vue 7.15 KB
006544386   Neeraj Sharma   implement task
1
2
3
4
5
  <template>
    <v-app id="login">
      <v-container fluid fill-height>
        <v-layout>
          <v-flex xs12 sm8 md8 lg5 offset-sm2 offset-lg3 class="mt-5">
68d742034   Neeraj Sharma   implement new des...
6
            <v-toolbar class="card-styles mt-5" dark>
006544386   Neeraj Sharma   implement task
7
              <v-spacer></v-spacer>
7858a465f   Shikha Mishra   change api of cha...
8
              <v-toolbar-title>Change Password</v-toolbar-title>
006544386   Neeraj Sharma   implement task
9
10
11
12
13
              <v-spacer></v-spacer>
            </v-toolbar>
            <v-card class="elevation-1 pa-3" id="form">
              <v-card-text>
                <v-flex xs12 sm8 md8 lg8 offset-sm2>
79583580d   Neeraj Sharma   implement task ma...
14
                  <v-form class="mt-3" ref="form" v-model="valid" lazy-validation>
7858a465f   Shikha Mishra   change api of cha...
15
                    <!-- <v-select
79583580d   Neeraj Sharma   implement task ma...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
                      :rules="userRule"
                      label="Select User"
                      :items="getRoles"
                      item-text="name"
                      item-value="name"
                      v-model="resetPassword.name"
                      @change="getUsers(resetPassword.name)"
                    ></v-select>
                    <v-select
                      :rules="userNameRule"
                      label="Select User Name"
                      :items="getUsersName"
                      item-text="email"
                      item-value="email"
                      v-model="resetPassword.email"
7014df603   Shikha Mishra   Improve placehold...
31
                    ></v-select>-->
7858a465f   Shikha Mishra   change api of cha...
32
33
34
35
36
37
38
39
40
41
42
                    <v-text-field
                      :append-icon="e1 ? 'visibility_off' : 'visibility'"
                      :append-icon-cb="() => (e1 = !e1)"
                      :type="e1 ? 'password' : 'text'"
                      :rules="oldPasswordRule"
                      v-model="resetPassword.oldPassword"
                      :error-messages="errors.collect('resetPassword.oldPassword')"
                      v-validate="'required'"
                      data-vv-name="resetPassword.oldPassword"
                      label="Old Password"
                    ></v-text-field>
006544386   Neeraj Sharma   implement task
43
                    <v-text-field
7858a465f   Shikha Mishra   change api of cha...
44
45
46
                      :append-icon="e1 ? 'visibility_off' : 'visibility'"
                      :append-icon-cb="() => (e1 = !e1)"
                      :type="e1 ? 'password' : 'text'"
79583580d   Neeraj Sharma   implement task ma...
47
48
49
50
51
                      :rules="newPasswordRule"
                      v-model="resetPassword.newPassword"
                      :error-messages="errors.collect('resetPassword.newPassword')"
                      v-validate="'required'"
                      data-vv-name="resetPassword.newPassword"
006544386   Neeraj Sharma   implement task
52
53
54
                      label="New Password"
                    ></v-text-field>
                    <v-text-field
7858a465f   Shikha Mishra   change api of cha...
55
56
57
                      :append-icon="e1 ? 'visibility_off' : 'visibility'"
                      :append-icon-cb="() => (e1 = !e1)"
                      :type="e1 ? 'password' : 'text'"
79583580d   Neeraj Sharma   implement task ma...
58
59
60
                      v-model="resetPassword.confirmPassword"
                      :rules="rePasswordRule"
                      :error-messages="errors.collect('password2')"
d2c0f0a3f   Neeraj Sharma   fixed validation in
61
                      v-validate="{ required: false, is: resetPassword.newPassword }"
79583580d   Neeraj Sharma   implement task ma...
62
63
                      data-vv-name="password2"
                      data-vv-as="password"
7014df603   Shikha Mishra   Improve placehold...
64
                      label="Re-enter New Password"
006544386   Neeraj Sharma   implement task
65
66
67
68
69
70
71
                    ></v-text-field>
                  </v-form>
                </v-flex>
              </v-card-text>
              <v-card-actions>
                <v-flex text-xs-center>
                  <v-btn
7858a465f   Shikha Mishra   change api of cha...
72
                    style="background-color: #71d9ea; color: #0c0754;"
006544386   Neeraj Sharma   implement task
73
                    dark
7858a465f   Shikha Mishra   change api of cha...
74
                    flat
006544386   Neeraj Sharma   implement task
75
76
77
                    large
                    :loading="loading"
                    @click="reset"
7858a465f   Shikha Mishra   change api of cha...
78
                  >Change Password</v-btn>
006544386   Neeraj Sharma   implement task
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
                </v-flex>
              </v-card-actions>
              <v-snackbar
                :timeout="timeout"
                :top="y === 'top'"
                :right="x === 'right'"
                :vertical="mode === 'vertical'"
                v-model="snackbar"
                :color="color"
              >{{ text }}</v-snackbar>
            </v-card>
          </v-flex>
        </v-layout>
      </v-container>
    </v-app>
  </template>
  <script>
  import http from "@/Services/http.js";
  
  export default {
    data() {
      return {
        snackbar: false,
        y: "top",
        x: "right",
        mode: "",
        timeout: 4000,
        text: "",
79583580d   Neeraj Sharma   implement task ma...
107
        color: "",
7858a465f   Shikha Mishra   change api of cha...
108
        e1: true,
79583580d   Neeraj Sharma   implement task ma...
109
110
111
112
113
        password2: "",
        resetPassword: {},
        getUsersName: [],
        getRoles: [],
        valid: true,
006544386   Neeraj Sharma   implement task
114
        loading: false,
006544386   Neeraj Sharma   implement task
115
        text: "Password Changed",
006544386   Neeraj Sharma   implement task
116
        newPassword: "",
7858a465f   Shikha Mishra   change api of cha...
117
        oldPassword: "",
7014df603   Shikha Mishra   Improve placehold...
118
119
120
121
122
        userRule: [(v) => !!v || "User is required"],
        userNameRule: [(v) => !!v || "User Name is required"],
        oldPasswordRule: [(v) => !!v || "Old Password is required"],
        newPasswordRule: [(v) => !!v || "New Password is required"],
        rePasswordRule: [(v) => !!v || "Re-Password is required"],
006544386   Neeraj Sharma   implement task
123
124
      };
    },
79583580d   Neeraj Sharma   implement task ma...
125
126
    mounted() {
      this.token = this.$store.state.token;
7014df603   Shikha Mishra   Improve placehold...
127
      if (this.$store.state.role != "PARENT") {
bdcd68fbc   Amber Dev   change password i...
128
129
        this.getRole();
      }
79583580d   Neeraj Sharma   implement task ma...
130
    },
006544386   Neeraj Sharma   implement task
131
132
    methods: {
      reset() {
d2c0f0a3f   Neeraj Sharma   fixed validation in
133
134
        if (
          this.$refs.form.validate() &&
7858a465f   Shikha Mishra   change api of cha...
135
          this.resetPassword.oldPassword === this.resetPassword.oldPassword
d2c0f0a3f   Neeraj Sharma   fixed validation in
136
        ) {
79583580d   Neeraj Sharma   implement task ma...
137
          this.loading = true;
7858a465f   Shikha Mishra   change api of cha...
138
          this.resetPassword.newPassword = this.resetPassword.newPassword;
79583580d   Neeraj Sharma   implement task ma...
139
          http()
7858a465f   Shikha Mishra   change api of cha...
140
            .put("/change-password", this.resetPassword, {
7014df603   Shikha Mishra   Improve placehold...
141
              headers: { Authorization: "Bearer " + this.token },
79583580d   Neeraj Sharma   implement task ma...
142
            })
7014df603   Shikha Mishra   Improve placehold...
143
            .then((response) => {
79583580d   Neeraj Sharma   implement task ma...
144
145
146
147
148
149
              this.loading = false;
              this.snackbar = true;
              this.text = "Successfully Restet password !!";
              this.color = "green";
              this.clear();
            })
7014df603   Shikha Mishra   Improve placehold...
150
            .catch((error) => {
79583580d   Neeraj Sharma   implement task ma...
151
152
153
154
155
156
157
158
159
160
              // console.log("err====>",err);
              this.snackbar = true;
              this.text = "User Not Found or Incorrect currentPassword";
              this.color = "error";
              this.loading = false;
            });
        }
      },
      getRole() {
        this.showLoader = true;
006544386   Neeraj Sharma   implement task
161
        http()
79583580d   Neeraj Sharma   implement task ma...
162
          .get("/getRolesList", {
7014df603   Shikha Mishra   Improve placehold...
163
            headers: { Authorization: "Bearer " + this.token },
006544386   Neeraj Sharma   implement task
164
          })
7014df603   Shikha Mishra   Improve placehold...
165
          .then((response) => {
79583580d   Neeraj Sharma   implement task ma...
166
167
168
169
170
171
172
173
            for (let i = 0; i < response.data.data.length; i++) {
              if (
                response.data.data[i].name != "SUPERADMIN" &&
                response.data.data[i].name != "ADMIN"
              ) {
                this.getRoles.push(response.data.data[i]);
                this.showLoader = false;
              }
006544386   Neeraj Sharma   implement task
174
            }
006544386   Neeraj Sharma   implement task
175
          })
7014df603   Shikha Mishra   Improve placehold...
176
          .catch((error) => {
79583580d   Neeraj Sharma   implement task ma...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
            this.showLoader = false;
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
          });
      },
      clear() {
        this.$refs.form.reset();
      },
      getUsers(roles) {
        this.showLoader = true;
        http()
          .get("/getUserWithRole", {
            params: {
7014df603   Shikha Mishra   Improve placehold...
193
              name: roles,
79583580d   Neeraj Sharma   implement task ma...
194
            },
7014df603   Shikha Mishra   Improve placehold...
195
            headers: { Authorization: "Bearer " + this.token },
79583580d   Neeraj Sharma   implement task ma...
196
          })
7014df603   Shikha Mishra   Improve placehold...
197
          .then((response) => {
79583580d   Neeraj Sharma   implement task ma...
198
199
            this.getUsersName = response.data.data;
          })
7014df603   Shikha Mishra   Improve placehold...
200
          .catch((error) => {
79583580d   Neeraj Sharma   implement task ma...
201
202
203
204
205
206
            this.showLoader = false;
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
006544386   Neeraj Sharma   implement task
207
          });
7014df603   Shikha Mishra   Improve placehold...
208
209
      },
    },
006544386   Neeraj Sharma   implement task
210
211
212
  };
  </script>
  <style scoped>
68d742034   Neeraj Sharma   implement new des...
213
214
215
  .card-styles {
    background: #7f62f8 !important;
    border-color: #7f62f8 !important;
006544386   Neeraj Sharma   implement task
216
217
  }
  </style>