Improve setup script
This commit is contained in:
		
							parent
							
								
									c6831ff032
								
							
						
					
					
						commit
						b7c15dc15b
					
				
							
								
								
									
										26
									
								
								setup.php
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								setup.php
									
									
									
									
									
								
							| @ -1,5 +1,4 @@ | ||||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * This script will create a local administrator account. | ||||
|  */ | ||||
| @ -13,11 +12,7 @@ if ($database->has('accounts', ["[>]assigned_permissions" => ["uid" => "uid"]], | ||||
| if (is_empty($_POST['username']) || is_empty($_POST['password']) || is_empty($_POST['realname'])) { | ||||
|     ?>
 | ||||
|     <!DOCTYPE html> | ||||
|     <html> | ||||
|         <head> | ||||
|     <title>Admin Account Creation</title> | ||||
|         </head> | ||||
|         <body> | ||||
|     <h1>Admin Account Creation tool</h1> | ||||
|     <form action="setup.php" method="POST"> | ||||
|         Username: <input type="text" name="username" placeholder="Username" required="required" /><br /> | ||||
| @ -28,18 +23,17 @@ if (is_empty($_POST['username']) || is_empty($_POST['password']) || is_empty($_P | ||||
|             Create account | ||||
|         </button> | ||||
|     </form> | ||||
|         </body> | ||||
|     </html> | ||||
| <?php | ||||
|     <?php | ||||
| } else { | ||||
|     require_once __DIR__ . "/lib/login.php"; | ||||
|     $userid = adduser($_POST['username'], | ||||
|             $_POST['password'], | ||||
|             $_POST['realname'], | ||||
|             (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : null), | ||||
|             "", | ||||
|             "", | ||||
|             1); | ||||
|     header("Content-Type: text/plain"); | ||||
|     if (user_exists($_POST['username'])) { | ||||
|         $userid = $database->get('accounts', 'uid', ['username' => $_POST['username']]); | ||||
|         echo "User already exists, skipping creation.\n"; | ||||
|     } else { | ||||
|         $userid = adduser($_POST['username'], $_POST['password'], $_POST['realname'], (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : null), "", "", 1); | ||||
|         echo "User account #$userid created.\n"; | ||||
|     } | ||||
|     $database->insert('assigned_permissions', ['uid' => $userid, 'permid' => 1]); | ||||
|     die("Account created."); | ||||
|     die("ADMIN permission assigned."); | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user