-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.html
66 lines (63 loc) · 2.05 KB
/
redirect.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Redirect</title>
</head>
<body>
</body>
<script type="text/javascript">
/*
Hit Trimm api to check if the auth code is legitimate. If not, redirect
to login, else redirect to index.html.
*/
//get init.json data
var fs = require("fs");
var path = require('path');
var initPath = path.join('./', "init.json");
var firstWindow = '';
var data;
let $ = require('jquery');
try {
data = JSON.parse(fs.readFileSync(initPath, 'utf8'));
}
catch(e) {
console.log('failed');
}
if (data.hasOwnProperty('authCode')) {
//if the init.json has the data
var form_data = new FormData();
form_data.append('email', data['email']);
form_data.append('code', data['authCode']);
//ajax request
$.ajax({
url: 'http://localhost/trimm/public/api/check-authCode',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
async: false,
success: function(php_script_response){
//get success/failure
code = JSON.parse(php_script_response)['success'];
console.log(code);
},
error: function(xhr, status, error) {
code = false;
}
});
if (code) {
//if success == true, redirect to index
window.location.replace('index.html');
} else {
//success != true
window.location.replace('login.html');
}
} else {
//if the information doesnt exist in init.json at all
window.location.replace('login.html');
}
</script>
</html>