Blame view
src/pages/Authentication/Login.vue
11.2 KB
93a68cfa1
|
1 |
<template> |
03dcbf0c1
|
2 |
<v-app id="login"> |
93a68cfa1
|
3 4 |
<v-content> <v-container fluid fill-height> |
32fcd6960
|
5 |
<!-- SNACKBAR --> |
03dcbf0c1
|
6 7 8 9 10 11 |
<v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" |
32fcd6960
|
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
|
18 |
<v-layout align-center justify-center> |
9b444e5c3
|
19 |
<v-flex xs12 sm10 md5 lg4> |
229463bd5
|
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
|
27 |
<v-card class="elevation-1 px-2 py-3 card" style="background-color: #7852cc" dark> |
7d0816758
|
28 29 30 31 |
<img src="/static/intrackIllustration.png" class="mx-auto logoSchool" style="display:block" |
9b444e5c3
|
32 |
width="280" |
7d0816758
|
33 34 |
/> <v-card-text align-center justify-center> |
e8965626f
|
35 |
<v-toolbar-title class="text-xs-center subheadline">SCHOOL LOGIN</v-toolbar-title> |
03dcbf0c1
|
36 37 |
<v-flex xs12 sm12 md12 lg12> <v-form ref="form" v-model="valid" lazy-validation> |
3f8187137
|
38 |
<label class="title">Email / PhoneNo</label> |
03dcbf0c1
|
39 |
<v-text-field |
af414ec9c
|
40 |
style="padding: 0px; margin: 0px;" |
96f88269a
|
41 |
v-model.trim="userLogincredentials.email" |
03dcbf0c1
|
42 |
:rules="nameRules" |
3f8187137
|
43 |
placeholder="Enter your email / phoneNo" |
03dcbf0c1
|
44 45 |
required ></v-text-field> |
7d0816758
|
46 |
<label class="title">Password</label> |
03dcbf0c1
|
47 |
<v-text-field |
af414ec9c
|
48 |
style="padding: 0px; margin: 0px;" |
e3e2a04c6
|
49 |
:rules="[rules.required]" |
96f88269a
|
50 |
v-model.trim="userLogincredentials.password" |
03dcbf0c1
|
51 52 53 54 |
:append-icon="e1 ? 'visibility_off' : 'visibility'" :append-icon-cb="() => (e1 = !e1)" :type="e1 ? 'password' : 'text'" name="input-10-1" |
7d0816758
|
55 |
placeholder="Enter Your password" |
654e1501d
|
56 |
@keyup.enter="login" |
03dcbf0c1
|
57 58 |
></v-text-field> </v-form> |
9b444e5c3
|
59 60 |
<v-layout> <v-flex xs12 class="pa-0 ma-0"> |
a17c68a03
|
61 |
<h5 class="right mt-4"> |
7d0816758
|
62 |
<router-link class="link" to="/forgetpassword">Forgot password</router-link> |
a17c68a03
|
63 64 65 |
</h5> </v-flex> </v-layout> |
93a68cfa1
|
66 |
</v-flex> |
03dcbf0c1
|
67 68 |
</v-card-text> <v-layout> |
9b444e5c3
|
69 |
<v-flex sm12> |
a17c68a03
|
70 |
<v-btn |
7d0816758
|
71 |
style="margin: auto;display: block;background-color: #71d9ea; color: #0c0754;" |
a17c68a03
|
72 |
dark |
7d0816758
|
73 |
flat |
a17c68a03
|
74 75 76 77 |
@click="login" :loading="loading" >Login</v-btn> </v-flex> |
c7a4fe86a
|
78 |
</v-layout> |
a17c68a03
|
79 |
<v-layout></v-layout> |
93a68cfa1
|
80 81 82 83 84 |
</v-card> </v-flex> </v-layout> </v-container> </v-content> |
03dcbf0c1
|
85 |
</v-app> |
93a68cfa1
|
86 87 88 |
</template> <script> |
03dcbf0c1
|
89 |
import http from "@/Services/http.js"; |
32fcd6960
|
90 |
import AllApiCalls from "@/Services/AllApiCalls.js"; |
93a68cfa1
|
91 |
export default { |
32fcd6960
|
92 |
mixins: [AllApiCalls], |
03dcbf0c1
|
93 |
data() { |
93a68cfa1
|
94 |
return { |
32fcd6960
|
95 96 97 98 99 100 |
// snackbar: false, // y: "top", // x: "right", // mode: "", // timeout: 3000, // text: "", |
080d88547
|
101 |
append: "", |
93a68cfa1
|
102 103 104 105 |
e1: true, loading: false, remember: false, valid: false, |
b34ed827a
|
106 |
userLogincredentials: {}, |
32fcd6960
|
107 |
nameRules: [(v) => !!v || "Username is required"], |
03dcbf0c1
|
108 |
password: "", |
a17c68a03
|
109 |
email: "", |
07095d4d8
|
110 |
rules: { |
32fcd6960
|
111 112 113 |
required: (value) => !!value || "password is Required.", }, selectedStudent: {}, |
93a68cfa1
|
114 115 116 |
}; }, methods: { |
610e873a0
|
117 |
async login() { |
229463bd5
|
118 119 120 121 |
if (this.$refs.form.validate()) { this.loading = true; var userdata = { email: this.userLogincredentials.email, |
32fcd6960
|
122 |
password: this.userLogincredentials.password, |
229463bd5
|
123 |
}; |
3f8187137
|
124 125 126 127 |
if (/^[0-9]{10}$/.test(this.userLogincredentials.email)) { userdata.fatherCellNo = this.userLogincredentials.email; delete userdata.email; } |
229463bd5
|
128 129 |
http() .post("/schoolLogin", userdata) |
32fcd6960
|
130 |
.then((response) => { |
229463bd5
|
131 |
// console.log("token",response.data.data); |
1571e40b5
|
132 |
this.loading = false; |
229463bd5
|
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
|
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
|
162 |
localStorage.setItem("parentStudentId", response.data.data.id); |
32fcd6960
|
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
|
221 |
this.$store.dispatch("Id", null); |
32fcd6960
|
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
|
242 243 |
} }) |
32fcd6960
|
244 |
.catch((error) => { |
229463bd5
|
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
|
256 |
}, |
03dcbf0c1
|
257 |
}, |
a17c68a03
|
258 |
mounted() { |
ff30cbe86
|
259 260 |
if (this.$store.state.isUserLoggedIn == true) { this.$router.push("/dashboard"); |
9b444e5c3
|
261 |
} else if (this.$store.state.isSchoolLoggedIn == true) { |
ff30cbe86
|
262 263 |
this.$router.push("/dashboard"); } |
a17c68a03
|
264 |
}, |
03dcbf0c1
|
265 266 267 |
computed: { color() { return this.loading ? "success" : "error"; |
32fcd6960
|
268 269 |
}, }, |
93a68cfa1
|
270 |
}; |
93a68cfa1
|
271 272 273 |
</script> <style scoped lang="css"> |
03dcbf0c1
|
274 275 276 277 278 279 280 281 |
#login { width: 100%; position: absolute; top: 0; left: 0; content: ""; z-index: 0; } |
93a68cfa1
|
282 |
</style> |
04e3fbc56
|
283 |
<style scoped> |
7d0816758
|
284 285 286 287 288 |
.schoolLogo { height: 60%; padding-left: 31%; } /* img { |
03dcbf0c1
|
289 290 |
position: absolute; top: 13px; |
55f72b7d7
|
291 |
left: 8px; |
7d0816758
|
292 |
} */ |
04e3fbc56
|
293 |
.v-btn--large { |
03dcbf0c1
|
294 |
padding: 0px 84px; |
93a68cfa1
|
295 |
} |
a17c68a03
|
296 297 |
.link { text-decoration: none; |
04e3fbc56
|
298 |
} |
03dcbf0c1
|
299 |
a { |
7d0816758
|
300 |
color: #fff; |
a17c68a03
|
301 |
} |
03dcbf0c1
|
302 |
.mt-4 { |
a17c68a03
|
303 |
margin-top: 21px !important; |
03dcbf0c1
|
304 |
} |
9b444e5c3
|
305 306 307 |
.logo { display: block; } |
03dcbf0c1
|
308 |
@media screen and (max-width: 600px) { |
a17c68a03
|
309 310 311 312 313 |
img { left: 10px; height: 34px; width: 120px; } |
7d0816758
|
314 315 316 317 |
.logo { height: 56px; left: 10px; width: 120px; |
9b444e5c3
|
318 |
display: block; |
a17c68a03
|
319 |
} |
7d0816758
|
320 321 322 323 |
.logoSchool { height: 87px; left: 10px; width: 120px; |
a17c68a03
|
324 |
} |
4413a8d93
|
325 |
} |
93a68cfa1
|
326 |
</style> |