diff --git a/admin/data_management/add_game.php b/admin/data_management/add_game.php index bea9088..3443f97 100644 --- a/admin/data_management/add_game.php +++ b/admin/data_management/add_game.php @@ -17,7 +17,7 @@ try { // Try opening the SQL database connection - $conn = new PDO("mysql:host=$servername; dbname=$dbName", $username, $password); + $conn = new PDO("mysql:host=$servername; dbname=$dbName", $dbUsername, $dbPassword); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "
Connected successfully
"; diff --git a/admin/data_management/add_tourney.php b/admin/data_management/add_tourney.php index 8399606..5a46d42 100644 --- a/admin/data_management/add_tourney.php +++ b/admin/data_management/add_tourney.php @@ -17,7 +17,7 @@ try { // Try opening the SQL database connection - $conn = new PDO("mysql:host=$servername; dbname=$dbName", $username, $password); + $conn = new PDO("mysql:host=$servername; dbname=$dbName", $dbUsername, $dbPassword); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); diff --git a/admin/data_management/game_form.php b/admin/data_management/game_form.php index 8d3862e..537f64d 100644 --- a/admin/data_management/game_form.php +++ b/admin/data_management/game_form.php @@ -4,7 +4,7 @@ session_start(); include("../db_config.php"); // Include database stuff try { // Try opening the SQL database connection - $conn = new PDO("mysql:host=$servername; dbname=$dbName", $username, $password); + $conn = new PDO("mysql:host=$servername; dbname=$dbName", $dbUsername, $dbPassword); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -53,6 +53,7 @@ try { // Try opening the SQL database connection } ?> + diff --git a/admin/data_management/tourney_form.php b/admin/data_management/tourney_form.php index 5c89ebc..5c166e1 100644 --- a/admin/data_management/tourney_form.php +++ b/admin/data_management/tourney_form.php @@ -4,7 +4,7 @@ session_start(); include("../db_config.php"); // Include database stuff try { // Try opening the SQL database connection - $conn = new PDO("mysql:host=$servername; dbname=$dbName", $username, $password); + $conn = new PDO("mysql:host=$servername; dbname=$dbName", $dbUsername, $dbPassword); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -40,7 +40,7 @@ try { // Try opening the SQL database connection $userList[] = $result["winner4"]; } - + // Make sure we only have each name once $userList = array_unique($userList); // Sort the array to alphabetical order sort($userList); diff --git a/admin/db_config.php b/admin/db_config.php index 5422fdf..950955f 100644 --- a/admin/db_config.php +++ b/admin/db_config.php @@ -2,8 +2,8 @@ // DB LOGIN DETAILS HERE $servername = "127.0.0.1"; -$username = "USERNAME"; -$password = "PASSWORD"; +$dbUsername = "USERNAME"; +$dbPassword = "PASSWORD"; $dbName = "DBNAME"; //////////////////////////// DEVELOPER /////////////////////////////// @@ -29,9 +29,6 @@ $gameDataTableName = "games"; // table containing replay data $tournamentDataTableName = "tournaments"; // tournament data table $adminUserTableName = "safeadmins"; -$passwordLength = 8; // default minimum random password length - - //////////////////////////////////////////////////////////////////////////// @@ -53,8 +50,10 @@ isAdmin BOOL, username VARCHAR(30) NOT NULL, password VARCHAR(255), discord VARCHAR(50), +discordLink VARCHAR(150), twitch VARCHAR(50), youtube VARCHAR(50), +youtubeLink VARCHAR(150), userCreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, userUpdated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; @@ -68,8 +67,10 @@ isAdmin BOOL, username VARCHAR(30) NOT NULL, password VARCHAR(255), discord VARCHAR(50), +discordLink VARCHAR(150), twitch VARCHAR(50), youtube VARCHAR(50), +youtubeLink VARCHAR(150), userCreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, userUpdated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; diff --git a/admin/db_management/initialise.php b/admin/db_management/initialise.php index 84c8a34..ee57207 100644 --- a/admin/db_management/initialise.php +++ b/admin/db_management/initialise.php @@ -12,12 +12,13 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully
"; @@ -135,6 +136,7 @@ // Tell the user we're done echo "DONE!
"; +} ?> diff --git a/admin/index.php b/admin/index.php index 3162969..fa197c8 100644 --- a/admin/index.php +++ b/admin/index.php @@ -30,19 +30,19 @@ session_start(); include ("db_config.php"); try { // Try opening the SQL database connection - $conn = new PDO("mysql:host=$servername; dbname=$dbName", $username, $password); + $conn = new PDO("mysql:host=$servername; dbname=$dbName", $dbUsername, $dbPassword); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + // Check if the admin table exists + $sqlCheckAdminTable = $conn->prepare("SHOW TABLES LIKE '" . $adminUserTableName . "'"); + + // Run the query + $sqlCheckAdminTable->execute(); + } catch (PDOException $e) { // failed connection echo "SQL connection failed: " . $e->getMessage(); } - // Check if the admin table exists - $sqlCheckAdminTable = $conn->prepare("SHOW TABLES LIKE '" . $adminUserTableName . "'"); - - // Run the query - $sqlCheckAdminTable->execute(); - //Check if any rows exist $count = $sqlCheckAdminTable->rowCount(); diff --git a/admin/user_management/add_safe_admin.php b/admin/user_management/add_safe_admin.php index b47a773..66a27e8 100644 --- a/admin/user_management/add_safe_admin.php +++ b/admin/user_management/add_safe_admin.php @@ -5,6 +5,7 @@ +Admins table not found! Probably initial setup. Creating...
"; + if ($adminCount == 0) { + echo "Admins table not found! This is probably initial setup.
Creating safe admins table...
"; try { $conn->query($sqlCreateAdminTable); echo "Table '" . $adminUserTableName . "' successfully created (safe admins)
"; - echo "After we finish creating your user, you will need to use the \"Initialize Databases\" option in the admin panel before you can begin to use your server
"; } catch (PDOException $e) { echo $sqlCreateUserTable . "Users table found
"; + + // Now add them to the regular users table as well + // Prepare the query + $insert = $conn->prepare("INSERT INTO " . $userTableName . " (username, password, discord, discordLink, twitch, youtube, youtubeLink, isAdmin) VALUES (:username, :password, :discord, :discordLink, :twitch, :youtube, :youtubeLink, :isAdmin)"); + + // Bind parameters to the query + $insert->bindParam(":username", $username); + $insert->bindParam(":password", $password); + $insert->bindParam(":discord", $discord); + $insert->bindParam(":discordLink", $discordLink); + $insert->bindParam(":twitch", $twitch); + $insert->bindParam(":youtube", $youtube); + $insert->bindParam(":youtubeLink", $youtubeLink); + $insert->bindParam(":isAdmin", $isAdmin); + + // Execute + $insert->execute(); + } else { + echo "Users table not found! This is probably (still) initial setup. Creating...
"; + + initialiseDatabase(); + + + // Next we're going to copy any safe admins into the users table. + // This will make userlists easier to work with + //echo "Copying users from safe admins...
"; + //$copyAdmins = $conn->prepare("INSERT INTO " . $userTableName . " SELECT * FROM " . $adminUserTableName); + + //$copyAdmins->execute(); + //echo "Copied!
"; + } + + + if ($userCount == 0) { + } else { + } + + + + + echo "Safe Admin created successfully!"; } catch (PDOException $e) { // failed connection echo "Connection failed: " . $e->getMessage(); diff --git a/admin/user_management/add_user.php b/admin/user_management/add_user.php index 04f6698..abba567 100644 --- a/admin/user_management/add_user.php +++ b/admin/user_management/add_user.php @@ -5,6 +5,7 @@ +Fatal error
"; + echo "Please go to the home page and try what you were doing again
"; + echo ""; + echo "HOME"; + echo "
Account created! You may sign in now.
"; + echo ""; + echo "HOME"; + echo "SIGN IN"; + echo "
"; + echo "
Account successfully updated
"; + echo "You should have been redirected to your account. Here's a link:
"; + echo ""; + + + } catch (PDOException $e) { // failed connection + echo "Connection failed: " . $e->getMessage(); + } + + $conn = null; + + ?> + + + + \ No newline at end of file diff --git a/admin/user_management/user_form.php b/admin/user_management/user_form.php index c4c576a..0601b54 100644 --- a/admin/user_management/user_form.php +++ b/admin/user_management/user_form.php @@ -4,10 +4,10 @@ + -Get started on your trophy-winning journey with your very own TrojanDestinyRL account!