forked from oxguy3/coebot-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitchconnect.php
65 lines (49 loc) · 1.24 KB
/
twitchconnect.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
<?php
require_once("common.php");
// if (!isset($_GET['code'])) {
// throw404();
// }
if (isset($_GET["logout"])) {
header('Location: /');
$_SESSION['showLoggedOut'] = true;
logUserOut();
die('logged out');
}
if (!isset($_GET['code'])) {
throw400();
}
$code = $_GET['code'];
$loginResult = twitchGetAccessToken($code);
if (!$loginResult) {
die("Twitch is down, or authentication failed for some other reason.");
}
$twitchAccessToken = $loginResult->access_token;
$userData = twitchGetUser($twitchAccessToken);
if (!$userData) {
die("Twitch is down, or user retrieval failed for some other reason.");
}
$uid = dbSetUser($userData->name, true, $twitchAccessToken);
if ($uid === false) {
throw500("Database error, contact site administrator");
}
logUserIn($userData->name, $uid);
header('Location: ' . getUrlToChannel($_SESSION['channel']));
$_SESSION['showLoggedIn'] = true;
die('logged in');
/*
printHead("Logged in");
printNav();
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Welcome <?php echo $_SESSION['channel']; ?>!</h2>
<p class="lead">This is still super buggy and new and doesn't do much yet. I'm working on it!!</p>
</div>
</div>
</div>
<?php
printFooter();
printFoot();
*/
?>