From dcf61354050bfe81d6983f1aec34d7d3d6733a0d Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Fri, 29 Jan 2021 13:43:53 +0200 Subject: index.html + login.html => index.php those files had the entire HTML tree duplicated, which would make it difficult to make any changes to the front end. this commit combines the two files in one, with some front-end JS to switch between the login and register forms. --- php/configuration.php | 18 ++++++++++++------ php/database.php | 8 +------- php/misc.php | 5 ----- php/register.php | 7 +++++++ 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'php') diff --git a/php/configuration.php b/php/configuration.php index 6b87508..89efb2a 100644 --- a/php/configuration.php +++ b/php/configuration.php @@ -3,15 +3,21 @@ $domain_name="localhost"; -$database_name="adam"; -$database_username="adam"; -$database_password="asdfd"; -$database_location="127.0.0.1"; - +if (file_exists("/home/alex")) { + $database_name="alex"; + $database_username="alex"; + $database_password="lol"; + $database_location="127.0.0.1"; +} +else { + $database_name="adam"; + $database_username="adam"; + $database_password="asdfd"; + $database_location="127.0.0.1"; +} $password_hash_algo=PASSWORD_BCRYPT; - $has_email_verification=false; ?> diff --git a/php/database.php b/php/database.php index ef2b825..f472cbf 100644 --- a/php/database.php +++ b/php/database.php @@ -16,14 +16,8 @@ require_once "misc.php"; global $database_username; global $database_password; global $database_location; - try - { + $this->pdo=new PDO("mysql:dbname={$database_name};host={$database_location}",$database_username,$database_password); - }catch(PDOException $e) - { - error_log("Could not get database {$database_name} from {$database_location}, {$e} "); - die("The cow bought the farm"); - } } /*returns false if this isn't a user, otherwise returns the user*/ diff --git a/php/misc.php b/php/misc.php index 3ab0277..69cd654 100644 --- a/php/misc.php +++ b/php/misc.php @@ -1,11 +1,6 @@ Date: Fri, 29 Jan 2021 14:01:41 +0200 Subject: Login is now remembered in $_SESSION['username'] If it is set, user is logged in, if it is unset user is not logged in --- php/login.php | 7 ++++--- php/logout.php | 10 ++++++++++ php/register.php | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 php/logout.php (limited to 'php') diff --git a/php/login.php b/php/login.php index e6d44dc..536a5bf 100644 --- a/php/login.php +++ b/php/login.php @@ -3,6 +3,8 @@ require_once "user.php"; require_once "database.php"; require_once "misc.php"; +session_start(); + $username=$_POST["username"]; $password=$_POST["password"]; /*server side verification*/ @@ -18,8 +20,7 @@ if(!$user) die("Password or username is incorrect"); } -echo "Username: {$user->username}\n"; -echo "Email: {$user->email_address}"; - +$_SESSION['username'] = $user->username; +header('Location: /'); ?> diff --git a/php/logout.php b/php/logout.php new file mode 100644 index 0000000..9a4cdd7 --- /dev/null +++ b/php/logout.php @@ -0,0 +1,10 @@ + diff --git a/php/register.php b/php/register.php index ef1f238..1d31a91 100644 --- a/php/register.php +++ b/php/register.php @@ -31,4 +31,8 @@ if($database->register_user($username,$password,$email)) echo "didn't register"; } + +$_SESSION['username'] = $username; +header('Location: /'); + ?> -- cgit v1.2.3