Repository navigation
Expand file tree
/
Copy pathstatic.js
More file actions
293 lines (283 loc) · 9.93 KB
/
Copy pathstatic.js
File metadata and controls
293 lines (283 loc) · 9.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
158
159
160
161
162
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
$(document).ready(function(){
//electron specific initialisation
let remote = require('electron').remote;
let win = remote.BrowserWindow;
//let mainApp = remote.require('./mian');
const url = require("url");
const path = require("path");
mSession = remote.session;
expTD = expiryDate(1);
var txtLogin = $('.login');
var txtRegister = $('.register');
var txtLoginProgress= $('#progress-login');
var txtLoginError = $('#login-error');
var txtSuccess = $("#success-msg");
var closeBtn = $('.close');
txtRegister.css("display", "none");
//txtLogin.css("display", "none")
txtLoginProgress.css("display", "none");
txtLoginError.css("display", "none");
txtSuccess.css("display", "none");
$("#txtStaffLogin").on('click', function(e){
txtLoginProgress.css("display", "block");
e.preventDefault();
var id = $("#txtStaffId").val();
var password = $("#txtPassword").val();
if (id=="" || password=="") {
//alert('All fields are required');
errorMsg = "All fields are required"
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn)
}else if(id=="math.admin"){
//--/there can only be one admin
//--/should check local storage if there is a mail
var staffId = "admin";
$.ajax({
type: "POST",
timeout: 10000,
url: "https://mathknust.000webhostapp.com/public/php/login_admin.php",
data: "txtStaffId="+staffId+"&txtPassword="+password,
success: function(html){
value = JSON.parse(html);
if (value.error==true) {
//localStorage["session"] = value.user_id;
userId = value.user_id;
expTD = expiryDate(1);
setCookie("sessionIdAdmin", userId, expTD, mSession, "http://localhost");
window.location.replace("admin/index.html");
//check the storage of the cookie
}else{
//error messages goes here
//check the error message to see if an admin already exist? if no, display the regsitration page? else
errorMsg = value.error_msg;
if (errorMsg=="Administrator Not Found!") {
//display the registration page
txtLoginProgress.css('display', 'none');
txtLogin.css('display', 'none');
txtRegister.css('display', 'block');
}else{
//display the normal error message
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
}
}
},
error: function(xmlhttprequest, textstatus, message){
if(textstatus==="timeout") {
errorMsg = "Slow connection detected. Check your internet connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
} else {
errorMsg = "Address Unreacheable! Check connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
}
},
beforeSend: function(){
//error messages
}
});
//}
}else if(id=="math.sec"){
//check thee server for the secretarys mail
//check for password and redirect to go site
//confirm login details
var staffId = "sec";
$.ajax({
type: "POST",
timeout: 10000,
url: "https://mathknust.000webhostapp.com/public/php/login_sec.php",
data: "txtStaffId="+staffId+"&txtPassword="+password,
success: function(html){
value = JSON.parse(html);
if (value.error==true) {
//localStorage["session"] = value.user_id;
userId = value.user_id;
expTD = expiryDate(1);
setCookie("sessionIdSec", userId, expTD, mSession, "http://localhost");
//alert(getCookie("sessionId"));
window.location.replace("go/index.html");
}else{
//error messages goes here
errorMsg = value.error_msg;
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn)
}
},
error: function(xmlhttprequest, textstatus, message){
if(textstatus==="timeout") {
errorMsg = "Slow connection detected. Check your internet connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
} else {
errorMsg = "Address Unreacheable! Check connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
}
},
beforeSend: function(){
//error messages
}
});
}else{
//check for username and password and redirect to lo site
$.ajax({
type: "POST",
timeout: 10000,
url: "https://mathknust.000webhostapp.com/public/php/login_rec.php",
data: "txtStaffId="+id+"&txtPassword="+password,
success: function(html){
value = JSON.parse(html);
if (value.error==true) {
//localStorage["session"] = value.user_id;
userId = value.user_id;
expTD = expiryDate(1);
setCookie("sessionIdRec", userId, expTD, mSession, "http://localhost");
window.location.replace("lo/index.html");
}else{
//error messages goes here
errorMsg = value.error_msg;
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn)
}
},
error: function(xmlhttprequest, textstatus, message){
if(textstatus==="timeout") {
errorMsg = "Slow connection detected. Check your internet connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
} else {
errorMsg = "Address Unreacheable! Check connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
}
},
beforeSend: function(){
//error messages
}
});
}
return false;
});
$('#txtStaffRegister').on('click', function(e){
e.preventDefault();
txtLoginProgress.css("display", "block");
firstName = $("#txtFirstName").val();
lastName = $("#txtLastName").val();
txtPasswordR = $("#txtPasswordR").val();
txtPasswordRC = $("#txtPasswordRC").val();
txtEmail = $("#txtStaffEmail").val();
if (firstName=="" || lastName=="" || txtPasswordR=="" || txtPasswordRC=="" || txtEmail=="") {
//alert('Please all fields are required');
errorMsg = "All fields are required"
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn)
}else if(txtPasswordR!=txtPasswordRC){
//alert('Passwords do not match');
errorMsg = "Passwords do not match"
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn)
}else{
$.ajax({
type: "POST",
timeout: 10000,
url: "https://mathknust.000webhostapp.com/public/php/create_admin.php",
data: "txtAddEmail="+txtEmail+"&txtAddPassword="+txtPasswordR+"&txtAddFirstName="+firstName + "&txtAddLastName="+lastName,
success: function(html){
value = JSON.parse(html);
if (value.error==true) {
successMsg = "Registration successful!";
successDisplay(txtLoginError, txtLoginProgress, txtSuccess, successMsg, closeBtn)
txtLogin.css('display', 'block');
txtRegister.css('display', 'none');
}else{
//error messages goes here
//alert(value.error_msg);
errorMsg = value.error_msg;
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn)
}
},
error: function(xmlhttprequest, textstatus, message){
if(textstatus==="timeout") {
errorMsg = "Slow connection detected. Check your internet connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
} else {
errorMsg = "Address Unreacheable! Check connection and try again!";
errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn);
}
},
beforeSend: function(){
//error messages
}
});
//localStorage['math.admin'] = txtEmail;
//console.log('ok');
}
});
});
function errorDisplay(txtLoginError, txtLoginProgress, txtSuccess, errorMsg, closeBtn){
txtLoginProgress.css("display", "none");
txtSuccess.css("display", "none");
txtLoginError.find("p").text(errorMsg);
txtLoginError.fadeIn(1500, function(){
txtLoginError.css("display", "block");
});
closeBtn.on('click', function(){
txtLoginError.fadeOut(1000, "linear", function(){
txtLoginError.css("display", "none");
});
});
}
function successDisplay(txtLoginError, txtLoginProgress, txtSuccess, successMsg, closeBtn){
txtLoginProgress.css("display", "none");
txtLoginError.css("display", "none");
txtSuccess.find("p").text(successMsg);
txtSuccess.fadeIn(1500, function(){
txtSuccess.css("display", "block");
});
closeBtn.on('click', function(){
txtSuccess.fadeOut(1000, "linear", function(){
txtSuccess.css("display", "none");
});
});
}
/* Close when someone clicks on the "x" symbol inside the overlay */
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
//for id manipulation
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
//set cookie
function setCookie(cname, cvalue, exdays, mSession, hostUrl) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
// document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
mSession.defaultSession.cookies.set({
name: cname,
value: cvalue,
url: hostUrl,
expirationDate: exdays
},
err => {
if (err)console.log(err);
}
);
}
//get cookie
function getCookie(cname, mSession) {
}
function expiryDate(exdays){
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = d.toUTCString();
return d.getTime();
}
function getuserId(mSession){
var cookie = getCookie("sessionId", mSession);
//alert(cookie);
if (cookie!=null) {
id = cookie.substring(5,6);
if (id!="") {
return id;
}else{
return "";
}
}else{
return "";
}
}