-
Notifications
You must be signed in to change notification settings - Fork 0
/
webflow_loader.js
64 lines (56 loc) · 2.13 KB
/
webflow_loader.js
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
// webflow loader custom code by Altme
$altme = jQuery;
$altme(document).ready(function () {
if(!localStorage.getItem('testObject'))
{
$altme('body').css('display','none');
}
setTimeout(function(){
var url = window.location.href;
var token = url.split("?id_token=")[1];
if ( window.location.origin == website)
{
if (token)
{
var check = parseJwt(token);
localStorage.setItem('testObject', JSON.stringify(check));
var getStorageValue = localStorage.getItem('testObject');
var str = JSON.parse(getStorageValue);
var group = str.group;
redirect(group);
}
else if (localStorage.getItem('testObject') == null)
{
window.location.href = callback_url ;
}
}
}, 10);
});
function redirect(group) {
if(group == 'Default')
{
window.location.replace(website);
}
else if (group == 'Test')
{
window.location.replace(website +'/test');
}
else window.location.replace(website);
}
function parseJwt(token) {
var header = token.split('.')[0];
var header_base64 = header.replace(/-/g, '+').replace(/_/g, '/');
var jsonHeader = decodeURIComponent(atob(header_base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
var payload = token.split('.')[1];
var payload_base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(payload_base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
var headerJsonObj = JSON.parse(jsonHeader);
var payloadJsonObj = JSON.parse(jsonPayload);
var userGroup = payloadJsonObj.group;
localStorage.setItem('group', JSON.stringify(userGroup));
return Object.assign({}, headerJsonObj, payloadJsonObj);
};