Example #1
0
<?php

/*
 * User registration page
 */
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/src/Template.php';
require_once __DIR__ . '/src/API.php';
Template::build_header('Registration');
if (isset($_POST['user']) && isset($_POST['email']) && isset($_POST['password']) && isset($_POST['password_confirm']) && isset($_POST['register'])) {
    $pass1 = trim($_POST['password']);
    $pass2 = trim($_POST['password_confirm']);
    $username = strtolower(trim($_POST['user']));
    $email = strtolower(trim($_POST['email']));
    if ($pass1 !== $pass2) {
        print "Passwords do not match!";
        exit;
    }
    if (API::add_user($username, $email, $pass1)) {
        print "Registration successful.";
    } else {
        print "Registration failed. Username or e-mail already in use!";
    }
    exit;
}
?>
<h1>Registration</h1>
<form action="register.php" method="POST"
  autocomplete="off">
  <table>
    <tr>
Example #2
0
        renderTopTable('top_artists_six_months', 'table_left', 'Top Artists (past 6 months)');
        renderTopTable('top_songs_six_months', 'table_right', 'Top Songs (past 6 months)');
        print '<br/>';
        renderTopTable('top_artists_year', 'table_left', 'Top Artists (past year)');
        renderTopTable('top_songs_year', 'table_right', 'Top Songs (past year)');
        print '<br/>';
        renderTopTable('top_artists_all_time', 'table_left', 'Top Artists (all time)');
        renderTopTable('top_songs_all_time', 'table_right', 'Top Songs (all time)');
        // Invalid user given
    } else {
        Template::build_header("Invalid user");
        print "User not found.";
    }
    // No user set
} else {
    Template::build_header("Welcome");
    print "Welcome to the song tracker.";
    print '<p>';
    print '<a href="register.php">';
    print 'Register here';
    print '</a>';
    print '</p>';
    ?>

<table>
<th>Username</th>
<?php 
    $users = User::get_all();
    foreach ($users as $user) {
        print "<tr>";
        print "<td>";