Example #1
0
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>
Example #2
0
/**
 * Returns array of reqsongs for a channel, or NULL if an error occurred
 */
function dbListReqsongs($channel, $limit = 10)
{
    global $mysqli;
    initMysqli();
    $sql = 'SELECT id, url, requestedBy, dateAdded FROM ' . DB_PREF . 'reqsongs WHERE channel=? LIMIT ?';
    $stmt = $mysqli->prepare($sql);
    if ($stmt === false) {
        throw500();
        return false;
    }
    $stmt->bind_param('si', $channel, $limit);
    $success = $stmt->execute();
    if ($success === false) {
        throw500();
        return false;
    }
    $stmt->bind_result($id, $url, $requestedBy, $dateAdded);
    $reqsongs = array();
    while ($stmt->fetch()) {
        $rs = (object) array();
        $rs->id = $id;
        $rs->url = $url;
        $rs->requestedBy = $requestedBy;
        $rs->dateAdded = $dateAdded;
        $reqsongs[] = $rs;
    }
    return $reqsongs;
}