From b21dd0518daa10d05caf823b570bbf23058dbe39 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 29 May 2019 19:01:38 +0200 Subject: [PATCH] Website refactored Prepared the website structure for the new layout --- config.json | 4 +- functions.php | 18 +-------- index.php | 6 +-- lib/css/dashboard.css | 0 lib/php/dashboard.php | 33 ++++++++++++++++ lib/php/forgot.php | 4 +- lib/php/go.php | 7 ++-- lib/php/insert.php | 88 +++++++++++++++++-------------------------- lib/php/login.php | 14 +++---- lib/php/manage.php | 63 +++++++++++++++++++++++++++++++ 10 files changed, 150 insertions(+), 87 deletions(-) create mode 100644 lib/css/dashboard.css create mode 100644 lib/php/dashboard.php create mode 100644 lib/php/manage.php diff --git a/config.json b/config.json index 0980c91..bac5848 100644 --- a/config.json +++ b/config.json @@ -1,11 +1,11 @@ { "installed": false, + "website_name": "OpenShorte", "db": { "host": "127.0.0.1", "port": 3306, "username": "", "password": "", "name": "" - }, - "installation_path": "" + } } \ No newline at end of file diff --git a/functions.php b/functions.php index c23b72a..2ff1edb 100644 --- a/functions.php +++ b/functions.php @@ -1,24 +1,8 @@ + + + + + + Dashboard Home | <?=$GLOBALS['config']['website_name']?> + + + Open Management Console + + + - BJPHoster URL Shortener | Password Reset + + + Password Reset | <?=$GLOBALS['config']['website_name']?>
diff --git a/lib/php/go.php b/lib/php/go.php index 9caf307..81679b4 100644 --- a/lib/php/go.php +++ b/lib/php/go.php @@ -26,8 +26,9 @@ - Redirect in 5 seconds - + + + Redirect in 5 seconds | <?=$GLOBALS['config']['website_name']?>
@@ -37,7 +38,7 @@ window.onload = function() { var seconds = 5; function update_timeout (interval) { - document.getElementById("title").innerHTML = "Redirect in "+seconds+" seconds"; + document.getElementById("title").innerHTML = "Redirect in " + seconds +" seconds | "; document.getElementById("body-timeout").innerHTML = seconds; if (seconds == 0) { window.location.href = ""; diff --git a/lib/php/insert.php b/lib/php/insert.php index 64d45eb..2515118 100644 --- a/lib/php/insert.php +++ b/lib/php/insert.php @@ -1,63 +1,43 @@ connect ( ); - if ( isset ( $_POST [ 'url' ] ) ) { - $url = $_POST [ 'url' ]; - $database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" ); - $parameters = [ - [ "s" ], - [ &$url ], - ]; - $database->bind ( $parameters ); - $database->execute ( ); - $database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;"); - $database->execute ( ); - $result = $database->get_result ( ); - $row = $result->fetch_assoc ( ); header ( 'Content-Type: application/json' ); + http_response_code ( 401 ); $response = [ - 'status' => 200, - 'message' => 'URL inserted correctly.', - 'last_insert' => $row [ 'last' ], + 'status' => 401, + 'error_message' => 'You either are not logged in or you do not have permissions to insert new URLs.' ]; echo ( json_encode ( $response ) ); exit; } - else { - $database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] ); - $database->execute ( ); - $result = $database->get_result ( ); - $row = $result->fetch_assoc ( ); -?> - - - - BJPHoster URL Shortener | Control Panel - - - - -
-" ); - } - else { - do { - echo ( "\t\t\t" . '
' . $row [ 'ID' ] . " | " . $row [ 'URL' ] . "
\n" ); - } while ( $row = $result->fetch_assoc ( ) ); - } -?> -
- -
-
- - - - - 400, + 'error_message' => 'You either did not provide a URL or you provided an invalid one.' + ]; + echo ( json_encode ( $response ) ); + exit; } + $database = new Database ( $GLOBALS [ 'config' ] [ 'db' ] ); + $database->connect ( ); + $url = $_POST [ 'url' ]; + $database->prepare ( "INSERT INTO `links` ( `URL`, `created_by` ) VALUES ( ?, " . $_SESSION [ 'user_id' ] . " );" ); + $parameters = [ + [ "s" ], + [ &$url ], + ]; + $database->bind ( $parameters ); + $database->execute ( ); + $database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;"); + $database->execute ( ); + $result = $database->get_result ( ); + $row = $result->fetch_assoc ( ); + header ( 'Content-Type: application/json' ); + $response = [ + 'status' => 200, + 'message' => 'URL inserted correctly.', + 'last_insert' => $row [ 'last' ], + ]; + echo ( json_encode ( $response ) ); + exit; diff --git a/lib/php/login.php b/lib/php/login.php index 15ad2ef..984c76f 100644 --- a/lib/php/login.php +++ b/lib/php/login.php @@ -1,6 +1,6 @@ - BJPHoster URL Shortener | Login + Redirect in 5 seconds | <?=$GLOBALS['config']['website_name']?> - - + + - - - + + + connect ( ); + if ( isset ( $_POST [ 'url' ] ) ) { + $url = $_POST [ 'url' ]; + $database->prepare ( "INSERT INTO `links` ( `ID`, `URL`, `created_by` ) VALUES ( NULL, ?, " . $_SESSION [ 'user_id' ] . " );" ); + $parameters = [ + [ "s" ], + [ &$url ], + ]; + $database->bind ( $parameters ); + $database->execute ( ); + $database->prepare ( "SELECT MAX( links.ID ) as `last` FROM links;"); + $database->execute ( ); + $result = $database->get_result ( ); + $row = $result->fetch_assoc ( ); + header ( 'Content-Type: application/json' ); + $response = [ + 'status' => 200, + 'message' => 'URL inserted correctly.', + 'last_insert' => $row [ 'last' ], + ]; + echo ( json_encode ( $response ) ); + exit; + } + else { + $database->prepare ( "SELECT links.ID, links.URL FROM links WHERE links.created_by = " . $_SESSION [ 'user_id' ] ); + $database->execute ( ); + $result = $database->get_result ( ); + $row = $result->fetch_assoc ( ); +?> + + + + BJPHoster URL Shortener | Control Panel + + + + +
+" ); + } + else { + do { + echo ( "\t\t\t" . '
' . $row [ 'ID' ] . " | " . $row [ 'URL' ] . "
\n" ); + } while ( $row = $result->fetch_assoc ( ) ); + } +?> +
+ +
+
+ + + + +