This repository was archived by the owner on Nov 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +76
-1
lines changed Expand file tree Collapse file tree 4 files changed +76
-1
lines changed Original file line number Diff line number Diff line change 41
41
// Save the updated messages data
42
42
file_put_contents ('../db/messages.json ' , json_encode ($ messages ));
43
43
44
- header ("Location: admin_panel .php " );
44
+ header ("Location: index .php " );
45
45
exit ;
46
46
}
47
47
?>
Original file line number Diff line number Diff line change 22
22
$ configs = include ('config.php ' );
23
23
session_start ();
24
24
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
+ }
25
32
// Check if the user is already logged in
26
33
if (isset ($ _SESSION ['username ' ])) {
27
34
// Redirect to the user's dashboard
Original file line number Diff line number Diff line change
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>
Original file line number Diff line number Diff line change
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>
You can’t perform that action at this time.
0 commit comments