-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentlink.php
117 lines (107 loc) · 4.86 KB
/
studentlink.php
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
<?PHP
require_once("import/nogit.php");
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<title>Log in via Google</title>
<?PHP include_once("import/headers.html"); ?>
<meta name="google-signin-client_id" content="893609922416-qfs9mfsck2qabafc8ourg8i19h29lfve.apps.googleusercontent.com">
</head>
<body>
<body onload="document.getElementById('loading').style.display = 'none';">
<header>
<h1 id="pagetitle">Log in via Google - Damstede Device Portaal<span class="extra-info"> voor Leerlingen</span></h1>
<div id="pageoptions">
</div>
</header>
<div id="content" class="extrapadding">
<p><b>Om gebruik te kunnen maken van het Device Portaal en een computer in de mediatheek te reserveren, moet je inloggen met jouw @<?PHP echo $gSuiteDomain; ?> Google-account:</b></p>
<br />
<div id="my-signin2" data-onsuccess="onSignIn"></div>
<script>
function onGSuccess(googleUser) {
document.getElementById('loading').style.display = 'table';
var id_token = googleUser.getAuthResponse().id_token;
console.log(id_token);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://devices.damstede.eu/import/google-cb.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
var response = xhr.responseText;
console.log(response);
if (response.indexOf("error:") == 0) {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
document.getElementById('loading').style.display = 'none';
document.getElementById("loginerror-msg").innerHTML = response.split(":")[1];
showAction('loginerror');
});
}
else if (response.indexOf("success:") == 0) {
window.location.href = "student.php";
}
else {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
document.getElementById('loading').style.display = 'none';
document.getElementById("loginerror-msg").innerHTML = "Onbekende loginstatus. Laat dit weten aan het systeembeheer via ".$contactEmail;
showAction('loginerror');
});
}
};
xhr.send('id_token=' + id_token);
}
function onGFailure(error) {
console.error(error);
var doShowErrorMsg = true;
switch (error["error"]) {
case "popup_closed_by_user":
doShowErrorMsg = false;
break;
case "access_denied":
document.getElementById("loginerror-msg").innerHTML = "Je moet toegang geven tot de gevraagde gegevens om het Device Portaal te kunnen gebruiken.";
break;
default:
document.getElementById("loginerror-msg").innerHTML = error["error"];
break;
}
if (doShowErrorMsg) {
showAction('loginerror');
}
}
function renderButton() {
gapi.signin2.render('my-signin2', {
'scope': 'profile email',
'width': 260,
'height': 50,
'longtitle': true,
'theme': 'dark',
'onsuccess': onGSuccess,
'onfailure': onGFailure
});
}
</script>
<div class="action" id="loginerror" style="display: none;">
<div class="inneraction">
<div class="actioncontent">
<div class="actionheader">Er ging iets fout</div>
<div class="actionclose" data-action="loginerror" onclick="hideAction(this);">✖</div>
<p id="loginerror-msg">Een onbekende fout is opgetreden. Probeer het later opnieuw.</p>
<div class="actionbuttons">
<input class="button" type="button" value="Oké" data-action="loginerror" onclick="hideAction(this);" />
</div>
</div>
</div>
</div>
</div>
<div id="loading" style="display: table; width: 100%; height: 100%; position: fixed; top: 0px; left: 0px; right: 0px; bottom: 0px; background-color: rgba(0,0,0,0.8);">
<div style="display: table-cell; vertical-align: middle;">
<div style="margin-left: auto; margin-right: auto; text-align: center;">
<div id="spinner"></div>
</div>
</div>
</div>
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
</body>
</html>