Blame view

src/pages/Authentication/Login.vue 11.5 KB
93a68cfa1   Jatinder Singh   first commit
1
  <template>
03dcbf0c1   Neeraj Sharma   fix all api and r...
2
    <v-app id="login">
93a68cfa1   Jatinder Singh   first commit
3
4
      <v-content>
        <v-container fluid fill-height>
32fcd6960   Amber Dev   added logout if a...
5
          <!-- SNACKBAR -->
03dcbf0c1   Neeraj Sharma   fix all api and r...
6
7
8
9
10
11
          <v-snackbar
            :timeout="timeout"
            :top="y === 'top'"
            :right="x === 'right'"
            :vertical="mode === 'vertical'"
            v-model="snackbar"
32fcd6960   Amber Dev   added logout if a...
12
13
14
15
16
17
            :color="snackbarColor"
          >
            {{ text }}
            <v-spacer></v-spacer>
            <v-btn flat text @click="snackbar = false">X</v-btn>
          </v-snackbar>
93a68cfa1   Jatinder Singh   first commit
18
          <v-layout align-center justify-center>
9b444e5c3   Neeraj Sharma   add logo in login...
19
            <v-flex xs12 sm10 md5 lg4>
229463bd5   Neeraj Sharma   implement design ...
20
21
22
23
24
25
26
              <img
                src="/static/icon.png"
                height="40"
                width="140"
                alt="logo"
                class="logo mx-auto mb-2"
              />
9b444e5c3   Neeraj Sharma   add logo in login...
27
              <v-card class="elevation-1 px-2 py-3 card" style="background-color: #7852cc" dark>
7d0816758   Shikha Mishra   show dashboard wh...
28
29
30
31
                <img
                  src="/static/intrackIllustration.png"
                  class="mx-auto logoSchool"
                  style="display:block"
9b444e5c3   Neeraj Sharma   add logo in login...
32
                  width="280"
7d0816758   Shikha Mishra   show dashboard wh...
33
34
                />
                <v-card-text align-center justify-center>
e8965626f   Shikha Mishra   set login design ...
35
                  <v-toolbar-title class="text-xs-center subheadline">SCHOOL LOGIN</v-toolbar-title>
03dcbf0c1   Neeraj Sharma   fix all api and r...
36
37
                  <v-flex xs12 sm12 md12 lg12>
                    <v-form ref="form" v-model="valid" lazy-validation>
3f8187137   Shikha Mishra   Added functionali...
38
                      <label class="title">Email / PhoneNo</label>
03dcbf0c1   Neeraj Sharma   fix all api and r...
39
                      <v-text-field
af414ec9c   Shikha Mishra   set style in text...
40
                        style="padding: 0px; margin: 0px;"
96f88269a   Neeraj Sharma   implement Student...
41
                        v-model.trim="userLogincredentials.email"
03dcbf0c1   Neeraj Sharma   fix all api and r...
42
                        :rules="nameRules"
3f8187137   Shikha Mishra   Added functionali...
43
                        placeholder="Enter your email / phoneNo"
03dcbf0c1   Neeraj Sharma   fix all api and r...
44
45
                        required
                      ></v-text-field>
7d0816758   Shikha Mishra   show dashboard wh...
46
                      <label class="title">Password</label>
03dcbf0c1   Neeraj Sharma   fix all api and r...
47
                      <v-text-field
af414ec9c   Shikha Mishra   set style in text...
48
                        style="padding: 0px; margin: 0px;"
e3e2a04c6   Neeraj Sharma   first commit
49
                        :rules="[rules.required]"
96f88269a   Neeraj Sharma   implement Student...
50
                        v-model.trim="userLogincredentials.password"
03dcbf0c1   Neeraj Sharma   fix all api and r...
51
52
53
54
                        :append-icon="e1 ? 'visibility_off' : 'visibility'"
                        :append-icon-cb="() => (e1 = !e1)"
                        :type="e1 ? 'password' : 'text'"
                        name="input-10-1"
7d0816758   Shikha Mishra   show dashboard wh...
55
                        placeholder="Enter Your password"
654e1501d   Neeraj Sharma   remove school-man...
56
                        @keyup.enter="login"
03dcbf0c1   Neeraj Sharma   fix all api and r...
57
58
                      ></v-text-field>
                    </v-form>
9b444e5c3   Neeraj Sharma   add logo in login...
59
60
                    <v-layout>
                      <v-flex xs12 class="pa-0 ma-0">
a17c68a03   Neeraj Sharma   implement two rou...
61
                        <h5 class="right mt-4">
7d0816758   Shikha Mishra   show dashboard wh...
62
                          <router-link class="link" to="/forgetpassword">Forgot password</router-link>
a17c68a03   Neeraj Sharma   implement two rou...
63
64
65
                        </h5>
                      </v-flex>
                    </v-layout>
93a68cfa1   Jatinder Singh   first commit
66
                  </v-flex>
03dcbf0c1   Neeraj Sharma   fix all api and r...
67
68
                </v-card-text>
                <v-layout>
9b444e5c3   Neeraj Sharma   add logo in login...
69
                  <v-flex sm12>
a17c68a03   Neeraj Sharma   implement two rou...
70
                    <v-btn
7d0816758   Shikha Mishra   show dashboard wh...
71
                      style="margin: auto;display: block;background-color: #71d9ea; color: #0c0754;"
a17c68a03   Neeraj Sharma   implement two rou...
72
                      dark
7d0816758   Shikha Mishra   show dashboard wh...
73
                      flat
a17c68a03   Neeraj Sharma   implement two rou...
74
75
76
77
                      @click="login"
                      :loading="loading"
                    >Login</v-btn>
                  </v-flex>
c7a4fe86a   Neeraj Sharma   responsive admin ...
78
                </v-layout>
a17c68a03   Neeraj Sharma   implement two rou...
79
                <v-layout></v-layout>
93a68cfa1   Jatinder Singh   first commit
80
81
82
83
84
              </v-card>
            </v-flex>
          </v-layout>
        </v-container>
      </v-content>
03dcbf0c1   Neeraj Sharma   fix all api and r...
85
    </v-app>
93a68cfa1   Jatinder Singh   first commit
86
87
88
  </template>
  
  <script>
03dcbf0c1   Neeraj Sharma   fix all api and r...
89
  import http from "@/Services/http.js";
32fcd6960   Amber Dev   added logout if a...
90
  import AllApiCalls from "@/Services/AllApiCalls.js";
93a68cfa1   Jatinder Singh   first commit
91
  export default {
32fcd6960   Amber Dev   added logout if a...
92
    mixins: [AllApiCalls],
03dcbf0c1   Neeraj Sharma   fix all api and r...
93
    data() {
93a68cfa1   Jatinder Singh   first commit
94
      return {
b0e0491ab   Shikha Mishra   solve the issue o...
95
96
97
98
99
100
101
102
103
        //SNACKBAR
        y: "top",
        x: "right",
        mode: "",
        timeout: 10000,
        text: "",
        snackbarColor: "",
  
        snackbar: false,
080d88547   Shikha Mishra   issues solved
104
        append: "",
93a68cfa1   Jatinder Singh   first commit
105
106
107
108
        e1: true,
        loading: false,
        remember: false,
        valid: false,
b34ed827a   Jatinder Singh   changes
109
        userLogincredentials: {},
2f9211c74   Shikha Mishra   done one round of...
110
        nameRules: [(v) => !!v || "Field is required"],
03dcbf0c1   Neeraj Sharma   fix all api and r...
111
        password: "",
a17c68a03   Neeraj Sharma   implement two rou...
112
        email: "",
07095d4d8   Jatinder Singh   regex
113
        rules: {
32fcd6960   Amber Dev   added logout if a...
114
115
116
          required: (value) => !!value || "password is Required.",
        },
        selectedStudent: {},
93a68cfa1   Jatinder Singh   first commit
117
118
119
      };
    },
    methods: {
610e873a0   Amber Dev   solved bug regard...
120
      async login() {
229463bd5   Neeraj Sharma   implement design ...
121
122
123
124
        if (this.$refs.form.validate()) {
          this.loading = true;
          var userdata = {
            email: this.userLogincredentials.email,
32fcd6960   Amber Dev   added logout if a...
125
            password: this.userLogincredentials.password,
229463bd5   Neeraj Sharma   implement design ...
126
          };
3f8187137   Shikha Mishra   Added functionali...
127
128
129
130
          if (/^[0-9]{10}$/.test(this.userLogincredentials.email)) {
            userdata.fatherCellNo = this.userLogincredentials.email;
            delete userdata.email;
          }
229463bd5   Neeraj Sharma   implement design ...
131
132
          http()
            .post("/schoolLogin", userdata)
32fcd6960   Amber Dev   added logout if a...
133
            .then((response) => {
229463bd5   Neeraj Sharma   implement design ...
134
              // console.log("token",response.data.data);
1571e40b5   Neeraj Sharma   gallery and socia...
135
              this.loading = false;
229463bd5   Neeraj Sharma   implement design ...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
              if (response.data.data.role === "ADMIN") {
                this.$store.dispatch("setToken", response.data.data.token);
                this.$store.dispatch("Id", response.data.data.id);
                this.$store.dispatch("Role", response.data.data.role);
                this.$router.push("/dashboard");
              } else if (response.data.data.role === "SUPERADMIN") {
                this.$store.dispatch("setSchoolRole", response.data.data.role);
                this.$store.dispatch("setSchoolToken", response.data.data.token);
                this.$router.push("/schooldashboard");
              } else if (response.data.data.role === "TEACHER") {
                // console.log("teacher", response.data.data.role);
                this.$store.dispatch("setToken", response.data.data.token);
                this.$store.dispatch("Id", response.data.data.id);
                this.$store.dispatch("Role", response.data.data.role);
a690a86fb   Neeraj Sharma   implement meet fu...
150
                localStorage.setItem("teacherName", response.data.data.name);
229463bd5   Neeraj Sharma   implement design ...
151
152
153
154
155
156
157
158
159
160
161
                this.$router.push("/dashboard");
              } else if (response.data.data.role === "LIBRARIAN") {
                this.$store.dispatch("setToken", response.data.data.token);
                this.$store.dispatch("Id", response.data.data.id);
                this.$store.dispatch("Role", response.data.data.role);
                this.$router.push("/dashboard");
              } else if (response.data.data.role === "ACCOUNTANT") {
                this.$store.dispatch("setToken", response.data.data.token);
                this.$store.dispatch("Id", response.data.data.id);
                this.$store.dispatch("Role", response.data.data.role);
                this.$router.push("/dashboard");
11d037abe   Neeraj Sharma   commit code
162
163
164
165
              } else if (response.data.data.role === "PARENT") {
                this.$store.dispatch("setToken", response.data.data.token);
                this.$store.dispatch("Id", response.data.data.id);
                this.$store.dispatch("Role", response.data.data.role);
610e873a0   Amber Dev   solved bug regard...
166
                localStorage.setItem("parentStudentId", response.data.data.id);
32fcd6960   Amber Dev   added logout if a...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
  
                http()
                  .get("/parentStudentsList")
                  .then((response) => {
                    /* set disabled students values */
                    console.log("students - ", response.data.data.students);
                    /* prepare an array of false status students */
                    var indexStatusFalse = [];
                    for (var i = 0; i < response.data.data.students.length; i++) {
                      if (response.data.data.students[i].status == false) {
                        indexStatusFalse.push(i);
                      }
                    }
                    /* introduce a property named disabled in response to make false staus students disbled */
                    for (var i = 0; i < indexStatusFalse.length; i++) {
                      response.data.data.students[
                        indexStatusFalse[i]
                      ].disabled = true;
                    }
                    /* make an array of students */
                    this.$store.dispatch(
                      "SET_STUDENTS_DATA",
                      response.data.data.students
                    );
  
                    /* counter to keep a track of number of students that are disabled or false */
                    var counter = 0;
                    /* if zero element of false students list is > 0 then make first student as defalut selected */
                    if (indexStatusFalse[0] > 0) {
                      this.selectedStudent = response.data.data.students[0]._id;
                    }
                    console.log("indexStatusFalse - ", indexStatusFalse);
                    /* if false student is the first one in the list then see if the next is also false */
                    if (indexStatusFalse[0] == 0) {
                      if (indexStatusFalse.length > 1) {
                        for (var i = 1; i < indexStatusFalse.length; i++) {
                          if (indexStatusFalse[i] == i) {
                            if (indexStatusFalse[i - 1] == i - 1) {
                              counter = i + 1;
                              continue;
                            }
                          } else {
                            counter = i;
                            break;
                          }
                        }
                      } else {
                        counter = 1;
                      }
                    }
                    console.log("counter - ", counter);
                    if (counter == response.data.data.students.length) {
                      this.seeSnackbar(
                        "Your wards have been removed ",
                        "warning"
                      );
  
                      this.$store.dispatch("setToken", null);
32fcd6960   Amber Dev   added logout if a...
225
                      this.$store.dispatch("Id", null);
32fcd6960   Amber Dev   added logout if a...
226
227
228
                    } else {
                      this.selectedStudent =
                        response.data.data.students[counter]._id;
a690a86fb   Neeraj Sharma   implement meet fu...
229
230
                      var studentName = response.data.data.students[counter].name;
                      localStorage.setItem("studentName", studentName);
32fcd6960   Amber Dev   added logout if a...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
                      localStorage.setItem(
                        "parentStudentId",
                        this.selectedStudent
                      );
                      localStorage.setItem(
                        "parentClassId",
                        response.data.data.students[counter].classId
                      );
                      this.$router.push("/dashboard");
                    }
                    this.showLoader = false;
                  })
                  .catch((err) => {
                    console.log("err====>", err);
                    this.showLoader = false;
                  });
229463bd5   Neeraj Sharma   implement design ...
247
248
              }
            })
32fcd6960   Amber Dev   added logout if a...
249
            .catch((error) => {
229463bd5   Neeraj Sharma   implement design ...
250
251
252
              if (error.response.data.message) {
                this.text = error.response.data.message;
                this.snackbar = true;
b0e0491ab   Shikha Mishra   solve the issue o...
253
                this.snackbarColor = "error";
229463bd5   Neeraj Sharma   implement design ...
254
255
256
257
                this.loading = false;
              } else {
                this.text = "Server appears to be offline";
                this.snackbar = true;
b0e0491ab   Shikha Mishra   solve the issue o...
258
                this.snackbarColor = "error";
229463bd5   Neeraj Sharma   implement design ...
259
260
261
262
                this.loading = false;
              }
            });
        }
32fcd6960   Amber Dev   added logout if a...
263
      },
03dcbf0c1   Neeraj Sharma   fix all api and r...
264
    },
a17c68a03   Neeraj Sharma   implement two rou...
265
    mounted() {
ff30cbe86   Neeraj Sharma   remove discount p...
266
267
      if (this.$store.state.isUserLoggedIn == true) {
        this.$router.push("/dashboard");
9b444e5c3   Neeraj Sharma   add logo in login...
268
      } else if (this.$store.state.isSchoolLoggedIn == true) {
ff30cbe86   Neeraj Sharma   remove discount p...
269
270
        this.$router.push("/dashboard");
      }
a17c68a03   Neeraj Sharma   implement two rou...
271
    },
03dcbf0c1   Neeraj Sharma   fix all api and r...
272
273
274
    computed: {
      color() {
        return this.loading ? "success" : "error";
32fcd6960   Amber Dev   added logout if a...
275
276
      },
    },
93a68cfa1   Jatinder Singh   first commit
277
  };
93a68cfa1   Jatinder Singh   first commit
278
279
280
  </script>
  
  <style scoped lang="css">
03dcbf0c1   Neeraj Sharma   fix all api and r...
281
282
283
284
285
286
287
288
  #login {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    content: "";
    z-index: 0;
  }
93a68cfa1   Jatinder Singh   first commit
289
  </style>
04e3fbc56   Jatinder Singh   minor fix
290
  <style scoped>
7d0816758   Shikha Mishra   show dashboard wh...
291
292
293
294
295
  .schoolLogo {
    height: 60%;
    padding-left: 31%;
  }
  /* img {
03dcbf0c1   Neeraj Sharma   fix all api and r...
296
297
    position: absolute;
    top: 13px;
55f72b7d7   Neeraj Sharma   add new page are ...
298
    left: 8px;
7d0816758   Shikha Mishra   show dashboard wh...
299
  } */
04e3fbc56   Jatinder Singh   minor fix
300
  .v-btn--large {
03dcbf0c1   Neeraj Sharma   fix all api and r...
301
    padding: 0px 84px;
93a68cfa1   Jatinder Singh   first commit
302
  }
a17c68a03   Neeraj Sharma   implement two rou...
303
304
  .link {
    text-decoration: none;
04e3fbc56   Jatinder Singh   minor fix
305
  }
03dcbf0c1   Neeraj Sharma   fix all api and r...
306
  a {
7d0816758   Shikha Mishra   show dashboard wh...
307
    color: #fff;
a17c68a03   Neeraj Sharma   implement two rou...
308
  }
03dcbf0c1   Neeraj Sharma   fix all api and r...
309
  .mt-4 {
a17c68a03   Neeraj Sharma   implement two rou...
310
    margin-top: 21px !important;
03dcbf0c1   Neeraj Sharma   fix all api and r...
311
  }
9b444e5c3   Neeraj Sharma   add logo in login...
312
313
314
  .logo {
    display: block;
  }
03dcbf0c1   Neeraj Sharma   fix all api and r...
315
  @media screen and (max-width: 600px) {
a17c68a03   Neeraj Sharma   implement two rou...
316
317
318
319
320
    img {
      left: 10px;
      height: 34px;
      width: 120px;
    }
7d0816758   Shikha Mishra   show dashboard wh...
321
322
323
324
    .logo {
      height: 56px;
      left: 10px;
      width: 120px;
9b444e5c3   Neeraj Sharma   add logo in login...
325
      display: block;
a17c68a03   Neeraj Sharma   implement two rou...
326
    }
7d0816758   Shikha Mishra   show dashboard wh...
327
328
329
330
    .logoSchool {
      height: 87px;
      left: 10px;
      width: 120px;
a17c68a03   Neeraj Sharma   implement two rou...
331
    }
4413a8d93   Jatinder Singh   changes
332
  }
93a68cfa1   Jatinder Singh   first commit
333
  </style>