Blame view

src/pages/Authentication/Login.vue 11.2 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 {
32fcd6960   Amber Dev   added logout if a...
95
96
97
98
99
100
        // snackbar: false,
        // y: "top",
        // x: "right",
        // mode: "",
        // timeout: 3000,
        // text: "",
080d88547   Shikha Mishra   issues solved
101
        append: "",
93a68cfa1   Jatinder Singh   first commit
102
103
104
105
        e1: true,
        loading: false,
        remember: false,
        valid: false,
b34ed827a   Jatinder Singh   changes
106
        userLogincredentials: {},
32fcd6960   Amber Dev   added logout if a...
107
        nameRules: [(v) => !!v || "Username is required"],
03dcbf0c1   Neeraj Sharma   fix all api and r...
108
        password: "",
a17c68a03   Neeraj Sharma   implement two rou...
109
        email: "",
07095d4d8   Jatinder Singh   regex
110
        rules: {
32fcd6960   Amber Dev   added logout if a...
111
112
113
          required: (value) => !!value || "password is Required.",
        },
        selectedStudent: {},
93a68cfa1   Jatinder Singh   first commit
114
115
116
      };
    },
    methods: {
610e873a0   Amber Dev   solved bug regard...
117
      async login() {
229463bd5   Neeraj Sharma   implement design ...
118
119
120
121
        if (this.$refs.form.validate()) {
          this.loading = true;
          var userdata = {
            email: this.userLogincredentials.email,
32fcd6960   Amber Dev   added logout if a...
122
            password: this.userLogincredentials.password,
229463bd5   Neeraj Sharma   implement design ...
123
          };
3f8187137   Shikha Mishra   Added functionali...
124
125
126
127
          if (/^[0-9]{10}$/.test(this.userLogincredentials.email)) {
            userdata.fatherCellNo = this.userLogincredentials.email;
            delete userdata.email;
          }
229463bd5   Neeraj Sharma   implement design ...
128
129
          http()
            .post("/schoolLogin", userdata)
32fcd6960   Amber Dev   added logout if a...
130
            .then((response) => {
229463bd5   Neeraj Sharma   implement design ...
131
              // console.log("token",response.data.data);
1571e40b5   Neeraj Sharma   gallery and socia...
132
              this.loading = false;
229463bd5   Neeraj Sharma   implement design ...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
              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);
                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
158
159
160
161
              } 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...
162
                localStorage.setItem("parentStudentId", response.data.data.id);
32fcd6960   Amber Dev   added logout if a...
163
164
165
166
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
  
                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...
221
                      this.$store.dispatch("Id", null);
32fcd6960   Amber Dev   added logout if a...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
                    } else {
                      this.selectedStudent =
                        response.data.data.students[counter]._id;
  
                      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 ...
242
243
              }
            })
32fcd6960   Amber Dev   added logout if a...
244
            .catch((error) => {
229463bd5   Neeraj Sharma   implement design ...
245
246
247
248
249
250
251
252
253
254
255
              if (error.response.data.message) {
                this.text = error.response.data.message;
                this.snackbar = true;
                this.loading = false;
              } else {
                this.text = "Server appears to be offline";
                this.snackbar = true;
                this.loading = false;
              }
            });
        }
32fcd6960   Amber Dev   added logout if a...
256
      },
03dcbf0c1   Neeraj Sharma   fix all api and r...
257
    },
a17c68a03   Neeraj Sharma   implement two rou...
258
    mounted() {
ff30cbe86   Neeraj Sharma   remove discount p...
259
260
      if (this.$store.state.isUserLoggedIn == true) {
        this.$router.push("/dashboard");
9b444e5c3   Neeraj Sharma   add logo in login...
261
      } else if (this.$store.state.isSchoolLoggedIn == true) {
ff30cbe86   Neeraj Sharma   remove discount p...
262
263
        this.$router.push("/dashboard");
      }
a17c68a03   Neeraj Sharma   implement two rou...
264
    },
03dcbf0c1   Neeraj Sharma   fix all api and r...
265
266
267
    computed: {
      color() {
        return this.loading ? "success" : "error";
32fcd6960   Amber Dev   added logout if a...
268
269
      },
    },
93a68cfa1   Jatinder Singh   first commit
270
  };
93a68cfa1   Jatinder Singh   first commit
271
272
273
  </script>
  
  <style scoped lang="css">
03dcbf0c1   Neeraj Sharma   fix all api and r...
274
275
276
277
278
279
280
281
  #login {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    content: "";
    z-index: 0;
  }
93a68cfa1   Jatinder Singh   first commit
282
  </style>
04e3fbc56   Jatinder Singh   minor fix
283
  <style scoped>
7d0816758   Shikha Mishra   show dashboard wh...
284
285
286
287
288
  .schoolLogo {
    height: 60%;
    padding-left: 31%;
  }
  /* img {
03dcbf0c1   Neeraj Sharma   fix all api and r...
289
290
    position: absolute;
    top: 13px;
55f72b7d7   Neeraj Sharma   add new page are ...
291
    left: 8px;
7d0816758   Shikha Mishra   show dashboard wh...
292
  } */
04e3fbc56   Jatinder Singh   minor fix
293
  .v-btn--large {
03dcbf0c1   Neeraj Sharma   fix all api and r...
294
    padding: 0px 84px;
93a68cfa1   Jatinder Singh   first commit
295
  }
a17c68a03   Neeraj Sharma   implement two rou...
296
297
  .link {
    text-decoration: none;
04e3fbc56   Jatinder Singh   minor fix
298
  }
03dcbf0c1   Neeraj Sharma   fix all api and r...
299
  a {
7d0816758   Shikha Mishra   show dashboard wh...
300
    color: #fff;
a17c68a03   Neeraj Sharma   implement two rou...
301
  }
03dcbf0c1   Neeraj Sharma   fix all api and r...
302
  .mt-4 {
a17c68a03   Neeraj Sharma   implement two rou...
303
    margin-top: 21px !important;
03dcbf0c1   Neeraj Sharma   fix all api and r...
304
  }
9b444e5c3   Neeraj Sharma   add logo in login...
305
306
307
  .logo {
    display: block;
  }
03dcbf0c1   Neeraj Sharma   fix all api and r...
308
  @media screen and (max-width: 600px) {
a17c68a03   Neeraj Sharma   implement two rou...
309
310
311
312
313
    img {
      left: 10px;
      height: 34px;
      width: 120px;
    }
7d0816758   Shikha Mishra   show dashboard wh...
314
315
316
317
    .logo {
      height: 56px;
      left: 10px;
      width: 120px;
9b444e5c3   Neeraj Sharma   add logo in login...
318
      display: block;
a17c68a03   Neeraj Sharma   implement two rou...
319
    }
7d0816758   Shikha Mishra   show dashboard wh...
320
321
322
323
    .logoSchool {
      height: 87px;
      left: 10px;
      width: 120px;
a17c68a03   Neeraj Sharma   implement two rou...
324
    }
4413a8d93   Jatinder Singh   changes
325
  }
93a68cfa1   Jatinder Singh   first commit
326
  </style>