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

Commit a2c2b4f

Browse files
committed
Added setup
1 parent 033a7b5 commit a2c2b4f

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

admin/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// Save the updated messages data
4242
file_put_contents('../db/messages.json', json_encode($messages));
4343

44-
header("Location: admin_panel.php");
44+
header("Location: index.php");
4545
exit;
4646
}
4747
?>

index.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
$configs = include('config.php');
2323
session_start();
2424

25+
// Check if setup needs to be run
26+
$userFile = json_decode(file_get_contents('db/login.json'), true);
27+
28+
$userFile[] = $userFile;
29+
if ($userFile[0] == ""){
30+
header("Location: setup/index.php");
31+
}
2532
// Check if the user is already logged in
2633
if (isset($_SESSION['username'])) {
2734
// Redirect to the user's dashboard

setup/index.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Setup</title>
7+
</head>
8+
<?php
9+
// Check if setup has already run
10+
$userFile = json_decode(file_get_contents('db/login.json'), true);
11+
12+
$userFile[] = $userFile;
13+
if ($userFile[0] == ""){
14+
header("Location: ../index.php");
15+
}
16+
?>
17+
<body>
18+
<h1>Welcome to PHPSocial setup!</h1>
19+
<p>This setup guide will guide you through setting up PHPSocial.</p>
20+
<h3>First, enter a username and password</h3>
21+
<p>This will be used for the admin account, so pick something secure</p>
22+
<form method="POST" action="page2.php">
23+
<input type="text" placeholder="Username" name="username"></input>
24+
<input type="password" placeholder="Password" name="password"></input><br><br>
25+
<input type="submit" value="Next"></input>
26+
</form>
27+
</body>
28+
</html>

setup/page2.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Setup</title>
7+
</head>
8+
<?php
9+
if ($_SERVER["REQUEST_METHOD"] == "POST"){
10+
$username = $_POST['username'];
11+
$password = $_POST['password'];
12+
13+
// Hash the password
14+
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
15+
16+
// Load existing user data
17+
$users = json_decode(file_get_contents('../db/login.json'), true);
18+
19+
// Check if username already exists
20+
if (isset($users[$username])) {
21+
echo "Username already exists. Please choose a different username.";
22+
exit;
23+
}
24+
25+
// Add new user to the user data
26+
$users[$username] = [
27+
'password' => $hashedPassword,
28+
'admin' => true
29+
];
30+
31+
// Save the updated user data
32+
file_put_contents('../db/login.json', json_encode($users));
33+
}
34+
?>
35+
<body>
36+
<h1>Finished!</h1>
37+
<p>Thanks for installing PHPSocial!</p>
38+
<a href="/">Login</a>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)