function requireLoggedIn() { if (!isLoggedIn()) { throw400("You must be logged in to do that."); } }
<?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']));
$action = $_GET['a']; $httpMethod = "GET"; } else { if (isset($_POST['a'])) { $action = $_POST['a']; $httpMethod = "POST"; } else { throw400("Your request did not specify an action to perform."); } } if ($action == "join") { $channel = getChannelWithAuthOrDie($USER_ACCESS_LEVEL_OWNER); $bot = getParamOrDie('bot'); $channelCoebotData = dbGetChannel($channel); if ($channelCoebotData['isActive'] == true) { throw400("That channel is already joined by " . $channelCoebotData['botChannel'] . "! Only one instance of CoeBot can be in a channel at a time."); } $botSession = BotSession::getBotSessionCurrentUser($bot, $channel); $botSession->doJoin(); $botSession->finalize(); header('refresh: 3;url=' . getUrlToChannel($channel)); printHead("Processing..."); printNav('', true); ?> <div class="container"> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <h3><span class="loading-generic"><i></i> Join request sent to bot...</span></h3> <p class="lead"><a href="<?php echo getUrlToChannel($channel);