-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.html
61 lines (52 loc) · 2.12 KB
/
index.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
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>Discord OAUTH</title>
<style>
* {
text-align: center;
margin: 0px auto;
}
#welcome_txt {
font-size: 24px;
}
#login-link {
background-color: whitesmoke;
border-radius: 8px;
color: black;
padding: 15px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
}
#login-link:hover {
cursor: pointer;
}
</style>
</head>
<body>
<br>
<a id='login-link' href='[DISCORD OAUTH LINK HERE]'>Login with Discord</a><br><br>
<p id='welcome_txt'></p>
<script>
window.onload = function () {
if (location.href.indexOf("code") !== -1) { // Detect if you logged in or not
const code = location.href.substring(location.href.indexOf("code") + 5, location.href.length); // Get the code OAUTH gives you
const req = new XMLHttpRequest(); // Create a new XMLHttpRequest
req.open("POST", "http://localhost:80/user"); // Open the XMLHttpRequest; CHANGE THE PORT TO THE PORT YOU HAVE AS YOUR VARIABLE IN OAUTH.js.
req.send(code); // Send the code in the request
req.onload = () => { // Will run when the request is loaded
if (req.status === 500) { // Error
document.getElementById('welcome_txt').innerText = `There was an error with that. Please try logging in again. Error Code: ${req.status}`;
} else if (req.status === 200) { // Successful
document.getElementById("welcome_txt").innerText = `Welcome, ${req.responseText}!`
} else { // Other
document.getElementById('welcome_txt').innerText = `An error occured. Please try logging in again. Error Code: ${req.status}`;
}
}
}
}
</script>
</body>
</html>