Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Added setup
Browse files Browse the repository at this point in the history
  • Loading branch information
breadtf committed Jun 27, 2023
1 parent 033a7b5 commit a2c2b4f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// Save the updated messages data
file_put_contents('../db/messages.json', json_encode($messages));

header("Location: admin_panel.php");
header("Location: index.php");
exit;
}
?>
Expand Down
7 changes: 7 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
$configs = include('config.php');
session_start();

// Check if setup needs to be run
$userFile = json_decode(file_get_contents('db/login.json'), true);

$userFile[] = $userFile;
if ($userFile[0] == ""){
header("Location: setup/index.php");
}
// Check if the user is already logged in
if (isset($_SESSION['username'])) {
// Redirect to the user's dashboard
Expand Down
28 changes: 28 additions & 0 deletions setup/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup</title>
</head>
<?php
// Check if setup has already run
$userFile = json_decode(file_get_contents('db/login.json'), true);

$userFile[] = $userFile;
if ($userFile[0] == ""){
header("Location: ../index.php");
}
?>
<body>
<h1>Welcome to PHPSocial setup!</h1>
<p>This setup guide will guide you through setting up PHPSocial.</p>
<h3>First, enter a username and password</h3>
<p>This will be used for the admin account, so pick something secure</p>
<form method="POST" action="page2.php">
<input type="text" placeholder="Username" name="username"></input>
<input type="password" placeholder="Password" name="password"></input><br><br>
<input type="submit" value="Next"></input>
</form>
</body>
</html>
40 changes: 40 additions & 0 deletions setup/page2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup</title>
</head>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$username = $_POST['username'];
$password = $_POST['password'];

// Hash the password
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Load existing user data
$users = json_decode(file_get_contents('../db/login.json'), true);

// Check if username already exists
if (isset($users[$username])) {
echo "Username already exists. Please choose a different username.";
exit;
}

// Add new user to the user data
$users[$username] = [
'password' => $hashedPassword,
'admin' => true
];

// Save the updated user data
file_put_contents('../db/login.json', json_encode($users));
}
?>
<body>
<h1>Finished!</h1>
<p>Thanks for installing PHPSocial!</p>
<a href="/">Login</a>
</body>
</html>

0 comments on commit a2c2b4f

Please sign in to comment.