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. --- css/style.css | 4 ++ index.html | 65 -------------------------------- index.php | 77 +++++++++++++++++++++++++++++++++++++ js/arrows.js | 37 ------------------ js/validate_hero.js | 58 ---------------------------- login.html | 55 --------------------------- main.js | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ php/configuration.php | 18 ++++++--- php/database.php | 8 +--- php/misc.php | 5 --- php/register.php | 7 ++++ 11 files changed, 203 insertions(+), 233 deletions(-) delete mode 100644 index.html create mode 100644 index.php delete mode 100644 js/arrows.js delete mode 100644 js/validate_hero.js delete mode 100644 login.html create mode 100644 main.js diff --git a/css/style.css b/css/style.css index 31778c4..18d4817 100644 --- a/css/style.css +++ b/css/style.css @@ -195,3 +195,7 @@ input[type=submit]:hover { bottom: 0; z-index: -200; } + +#loginform { + display: none; +} diff --git a/index.html b/index.html deleted file mode 100644 index 6a2018b..0000000 --- a/index.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - shady file upload - - - - -
-
- - -
-
-
- -
- -
-

file upload service

-

that just about works

-

most of the time

-
-
- -
-
-

Get started

-
-

Username

- - - -

Email address

- - - -

Password

- - - -

Repeat Password

- - - -

Don't have an account? Log in -

-
-
- - -
-
- - -
- - - - - - diff --git a/index.php b/index.php new file mode 100644 index 0000000..3e92167 --- /dev/null +++ b/index.php @@ -0,0 +1,77 @@ + + + + + shady file upload + + +
+
+ + +
+
+
+ +
+ +
+

file upload service

+

that just about works

+

most of the time

+
+
+ +
+
+

Get started

+
+

Username

+ + + +

Email address

+ + + +

Password

+ + + +

Repeat Password

+ + + +

Already have an account? Log in +

+
+
+ +
+
+

Login

+
+

Username

+ + +

Password

+ + +

Don't have an account? Sign up +

+
+
+ + +
+
+ + +
+ + + + + diff --git a/js/arrows.js b/js/arrows.js deleted file mode 100644 index 10ad416..0000000 --- a/js/arrows.js +++ /dev/null @@ -1,37 +0,0 @@ - -arrows = []; - -const minSpeed = 3; -const maxSpeed = 8; -const delay = 1500; -const lifetime = 20000; - -function make_arrow() { - const svg = document.getElementById("protoarrow").cloneNode(); - svg.style.left = Math.random() * 100 + '%'; - svg.style.display = 'block'; - document.getElementById('arrows').append(svg); - const ob = { - y: -800, - svg: svg, - speed: Math.random() * (maxSpeed - minSpeed) + minSpeed - }; - arrows.push(ob); - setTimeout(make_arrow, delay); - setTimeout(() => { - svg.remove(); - arrows.shift(); - }, lifetime); -} - -function update() { - for (const arrow of arrows) { - arrow.y += arrow.speed; - arrow.svg.style.bottom = arrow.y + 'px'; - } - - window.requestAnimationFrame(update); -} - -make_arrow(); -update(); diff --git a/js/validate_hero.js b/js/validate_hero.js deleted file mode 100644 index 6d29a53..0000000 --- a/js/validate_hero.js +++ /dev/null @@ -1,58 +0,0 @@ - -function clear_hero_errors() -{ - var errors = document.getElementsByClassName("hero_form_error"); - var i; - for (i = 0; i < errors.length; i++) - { - errors[i].hidden = true; - } -} -function validate_hero_login_form() -{ - var username=document.forms["hero_form"]["username"].value; - var flag=true; - clear_hero_errors(); - - if(username.length==0) - { - document.getElementById("username-length-error").hidden=false; - flag=false; - } - document.activeElement.blur(); - return flag; -} -function validate_hero_form() -{ - var username=document.forms["hero_form"]["username"].value; - var email=document.forms["hero_form"]["email"].value; - var password=document.forms["hero_form"]["password"].value; - var password2=document.forms["hero_form"]["password2"].value; - - var flag=true; - clear_hero_errors(); - - if(username.length==0) - { - document.getElementById("username-length-error").hidden=false; - flag=false; - } - if(!email.match(/\S+@\S+/)) - { - document.getElementById("email-error").hidden=false; - flag=false; - } - if(password.length==0) - { - document.getElementById("password-length-error").hidden=false; - flag=false; - } - if(password !== password2) - { - document.getElementById("password-match-error").hidden=false; - flag=false; - } - document.activeElement.blur(); - return flag; - -} diff --git a/login.html b/login.html deleted file mode 100644 index 525358f..0000000 --- a/login.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - shady file upload - - - - -
-
- - -
-
-
- -
- -
-

file upload service

-

that just about works

-

most of the time

-
-
- -
-
-

Login

-
-

Username

- - -

Password

- - -

Already have an account? Sign up -

-
-
- - -
-
- - -
- - - - - - diff --git a/main.js b/main.js new file mode 100644 index 0000000..a775eb7 --- /dev/null +++ b/main.js @@ -0,0 +1,102 @@ +arrows = []; + +const minSpeed = 3; +const maxSpeed = 8; +const delay = 1500; +const lifetime = 20000; + +function make_arrow() { + const svg = document.getElementById("protoarrow").cloneNode(); + svg.style.left = Math.random() * 100 + '%'; + svg.style.display = 'block'; + document.getElementById('arrows').append(svg); + const ob = { + y: -800, + svg: svg, + speed: Math.random() * (maxSpeed - minSpeed) + minSpeed + }; + arrows.push(ob); + setTimeout(make_arrow, delay); + setTimeout(() => { + svg.remove(); + arrows.shift(); + }, lifetime); +} + +function update() { + for (const arrow of arrows) { + arrow.y += arrow.speed; + arrow.svg.style.bottom = arrow.y + 'px'; + } + + window.requestAnimationFrame(update); +} + +make_arrow(); +update(); + + + + +function clear_hero_errors() +{ + var errors = document.getElementsByClassName("hero_form_error"); + var i; + for (i = 0; i < errors.length; i++) + { + errors[i].hidden = true; + } +} +function validate_hero_login_form() +{ + var username=document.forms["hero_form"]["username"].value; + var flag=true; + clear_hero_errors(); + + if(username.length==0) + { + document.getElementById("username-length-error").hidden=false; + flag=false; + } + document.activeElement.blur(); + return flag; +} +function validate_hero_form() +{ + var username=document.forms["hero_form"]["username"].value; + var email=document.forms["hero_form"]["email"].value; + var password=document.forms["hero_form"]["password"].value; + var password2=document.forms["hero_form"]["password2"].value; + + var flag=true; + clear_hero_errors(); + + if(username.length==0) + { + document.getElementById("username-length-error").hidden=false; + flag=false; + } + if(!email.match(/\S+@\S+/)) + { + document.getElementById("email-error").hidden=false; + flag=false; + } + if(password.length==0) + { + document.getElementById("password-length-error").hidden=false; + flag=false; + } + if(password !== password2) + { + document.getElementById("password-match-error").hidden=false; + flag=false; + } + document.activeElement.blur(); + return flag; + +} + +function showLogin(l) { + document.getElementById("loginform").style.display = l ? "flex" : "none"; + document.getElementById("signupform").style.display = l ? "none" : "flex"; +} 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 13:48:48 +0200 Subject: hero_form => login_form or register_form as they are now in the same file and conflicted --- index.php | 4 ++-- main.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 3e92167..90b3f56 100644 --- a/index.php +++ b/index.php @@ -25,7 +25,7 @@
-
+

Get started

Username

@@ -50,7 +50,7 @@
- +

Login

Username

diff --git a/main.js b/main.js index a775eb7..f3b6f9a 100644 --- a/main.js +++ b/main.js @@ -49,7 +49,7 @@ function clear_hero_errors() } function validate_hero_login_form() { - var username=document.forms["hero_form"]["username"].value; + var username=document.forms["login_form"]["username"].value; var flag=true; clear_hero_errors(); @@ -63,10 +63,10 @@ function validate_hero_login_form() } function validate_hero_form() { - var username=document.forms["hero_form"]["username"].value; - var email=document.forms["hero_form"]["email"].value; - var password=document.forms["hero_form"]["password"].value; - var password2=document.forms["hero_form"]["password2"].value; + var username=document.forms["register_form"]["username"].value; + var email=document.forms["register_form"]["email"].value; + var password=document.forms["register_form"]["password"].value; + var password2=document.forms["register_form"]["password2"].value; var flag=true; clear_hero_errors(); -- cgit v1.2.3 From f4d5d71da4f94bf9bc87505e745eed913c9858b9 Mon Sep 17 00:00:00 2001 From: Alex Vitkov 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 --- index.php | 68 ++++++++++++------------------------------------------ loginregister.html | 53 ++++++++++++++++++++++++++++++++++++++++++ php/login.php | 7 +++--- php/logout.php | 10 ++++++++ php/register.php | 4 ++++ 5 files changed, 86 insertions(+), 56 deletions(-) create mode 100644 loginregister.html create mode 100644 php/logout.php diff --git a/index.php b/index.php index 90b3f56..b42c5f2 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,8 @@ - shady file upload + shady file upload +
@@ -12,66 +13,27 @@
-
-
- -
-
-

file upload service

-

that just about works

-

most of the time

-
-
-
- -

Get started

-
-

Username

- - + -

Email address

- - - -

Password

- - - -

Repeat Password

- - - -

Already have an account? Log in -

- -
- -
-
-

Login

-
-

Username

- - -

Password

- - -

Don't have an account? Sign up -

-
-
+Log out +
-
- - - + diff --git a/loginregister.html b/loginregister.html new file mode 100644 index 0000000..2d87daf --- /dev/null +++ b/loginregister.html @@ -0,0 +1,53 @@ +
+
+ +
+ +
+

file upload service

+

that just about works

+

most of the time

+
+
+ +
+
+

Get started

+
+

Username

+ + + +

Email address

+ + + +

Password

+ + + +

Repeat Password

+ + + +

Already have an account? Log in +

+
+
+ +
+
+

Login

+
+

Username

+ + +

Password

+ + +

Don't have an account? Sign up +

+
+
+ + 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 From 8ba2c35a306719932307ec5f99701101637e1fd2 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Fri, 29 Jan 2021 14:45:52 +0200 Subject: Menu bar, different .php pages for logged in/not logged in --- css/style.css | 28 ++++++++++++++- index.php | 35 +++++++++++------- loggedin.php | 6 ++++ loginregister.html | 53 ---------------------------- loginregister.js | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ loginregister.php | 53 ++++++++++++++++++++++++++++ main.js | 102 ----------------------------------------------------- 7 files changed, 211 insertions(+), 168 deletions(-) create mode 100644 loggedin.php delete mode 100644 loginregister.html create mode 100644 loginregister.js create mode 100644 loginregister.php delete mode 100644 main.js diff --git a/css/style.css b/css/style.css index 18d4817..9296e87 100644 --- a/css/style.css +++ b/css/style.css @@ -23,13 +23,38 @@ body { #header { background: white; margin: 0; - padding: 1rem; + padding: 0; + height: 3rem; font-size: 2em; + display: flex; + align-items: stretch; + user-select: none; + -webkit-user-select: none; + -ms-user-select: none; +} + +#topmenu { + font-size: 1.3rem; + list-style-type: none; + display: flex; + margin: 0; + padding: 0; +} + +#topmenu > li { + cursor: pointer; + padding: 10px; +} + +#topmenu > li:hover { + background: #eee; } .logo { font-family: monospace; margin: 0; + align-self: center; + padding-left: 2rem; } #hero { @@ -199,3 +224,4 @@ input[type=submit]:hover { #loginform { display: none; } + diff --git a/index.php b/index.php index b42c5f2..21d56f0 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,6 @@ + @@ -10,23 +13,32 @@
-
+
+
    + + +
  • +
  • Sign out
  • - + + +
  • Sign up
  • +
  • Log in
  • + + +
+ +
-Log out +
@@ -34,6 +46,5 @@
- diff --git a/loggedin.php b/loggedin.php new file mode 100644 index 0000000..884f4b9 --- /dev/null +++ b/loggedin.php @@ -0,0 +1,6 @@ +
+ ALALALLALALLAl +
+ + + diff --git a/loginregister.html b/loginregister.html deleted file mode 100644 index 2d87daf..0000000 --- a/loginregister.html +++ /dev/null @@ -1,53 +0,0 @@ -
-
- -
- -
-

file upload service

-

that just about works

-

most of the time

-
-
- -
-
-

Get started

-
-

Username

- - - -

Email address

- - - -

Password

- - - -

Repeat Password

- - - -

Already have an account? Log in -

-
-
- -
-
-

Login

-
-

Username

- - -

Password

- - -

Don't have an account? Sign up -

-
-
- - diff --git a/loginregister.js b/loginregister.js new file mode 100644 index 0000000..f3b6f9a --- /dev/null +++ b/loginregister.js @@ -0,0 +1,102 @@ +arrows = []; + +const minSpeed = 3; +const maxSpeed = 8; +const delay = 1500; +const lifetime = 20000; + +function make_arrow() { + const svg = document.getElementById("protoarrow").cloneNode(); + svg.style.left = Math.random() * 100 + '%'; + svg.style.display = 'block'; + document.getElementById('arrows').append(svg); + const ob = { + y: -800, + svg: svg, + speed: Math.random() * (maxSpeed - minSpeed) + minSpeed + }; + arrows.push(ob); + setTimeout(make_arrow, delay); + setTimeout(() => { + svg.remove(); + arrows.shift(); + }, lifetime); +} + +function update() { + for (const arrow of arrows) { + arrow.y += arrow.speed; + arrow.svg.style.bottom = arrow.y + 'px'; + } + + window.requestAnimationFrame(update); +} + +make_arrow(); +update(); + + + + +function clear_hero_errors() +{ + var errors = document.getElementsByClassName("hero_form_error"); + var i; + for (i = 0; i < errors.length; i++) + { + errors[i].hidden = true; + } +} +function validate_hero_login_form() +{ + var username=document.forms["login_form"]["username"].value; + var flag=true; + clear_hero_errors(); + + if(username.length==0) + { + document.getElementById("username-length-error").hidden=false; + flag=false; + } + document.activeElement.blur(); + return flag; +} +function validate_hero_form() +{ + var username=document.forms["register_form"]["username"].value; + var email=document.forms["register_form"]["email"].value; + var password=document.forms["register_form"]["password"].value; + var password2=document.forms["register_form"]["password2"].value; + + var flag=true; + clear_hero_errors(); + + if(username.length==0) + { + document.getElementById("username-length-error").hidden=false; + flag=false; + } + if(!email.match(/\S+@\S+/)) + { + document.getElementById("email-error").hidden=false; + flag=false; + } + if(password.length==0) + { + document.getElementById("password-length-error").hidden=false; + flag=false; + } + if(password !== password2) + { + document.getElementById("password-match-error").hidden=false; + flag=false; + } + document.activeElement.blur(); + return flag; + +} + +function showLogin(l) { + document.getElementById("loginform").style.display = l ? "flex" : "none"; + document.getElementById("signupform").style.display = l ? "none" : "flex"; +} diff --git a/loginregister.php b/loginregister.php new file mode 100644 index 0000000..8068b35 --- /dev/null +++ b/loginregister.php @@ -0,0 +1,53 @@ +
+
+ +
+ +
+

file upload service

+

that just about works

+

most of the time

+
+
+ +
+
+

Get started

+
+

Username

+ + + +

Email address

+ + + +

Password

+ + + +

Repeat Password

+ + + +

Already have an account? Log in +

+
+
+ +
+
+

Login

+
+

Username

+ + +

Password

+ + +

Don't have an account? Sign up +

+
+
+ + diff --git a/main.js b/main.js deleted file mode 100644 index f3b6f9a..0000000 --- a/main.js +++ /dev/null @@ -1,102 +0,0 @@ -arrows = []; - -const minSpeed = 3; -const maxSpeed = 8; -const delay = 1500; -const lifetime = 20000; - -function make_arrow() { - const svg = document.getElementById("protoarrow").cloneNode(); - svg.style.left = Math.random() * 100 + '%'; - svg.style.display = 'block'; - document.getElementById('arrows').append(svg); - const ob = { - y: -800, - svg: svg, - speed: Math.random() * (maxSpeed - minSpeed) + minSpeed - }; - arrows.push(ob); - setTimeout(make_arrow, delay); - setTimeout(() => { - svg.remove(); - arrows.shift(); - }, lifetime); -} - -function update() { - for (const arrow of arrows) { - arrow.y += arrow.speed; - arrow.svg.style.bottom = arrow.y + 'px'; - } - - window.requestAnimationFrame(update); -} - -make_arrow(); -update(); - - - - -function clear_hero_errors() -{ - var errors = document.getElementsByClassName("hero_form_error"); - var i; - for (i = 0; i < errors.length; i++) - { - errors[i].hidden = true; - } -} -function validate_hero_login_form() -{ - var username=document.forms["login_form"]["username"].value; - var flag=true; - clear_hero_errors(); - - if(username.length==0) - { - document.getElementById("username-length-error").hidden=false; - flag=false; - } - document.activeElement.blur(); - return flag; -} -function validate_hero_form() -{ - var username=document.forms["register_form"]["username"].value; - var email=document.forms["register_form"]["email"].value; - var password=document.forms["register_form"]["password"].value; - var password2=document.forms["register_form"]["password2"].value; - - var flag=true; - clear_hero_errors(); - - if(username.length==0) - { - document.getElementById("username-length-error").hidden=false; - flag=false; - } - if(!email.match(/\S+@\S+/)) - { - document.getElementById("email-error").hidden=false; - flag=false; - } - if(password.length==0) - { - document.getElementById("password-length-error").hidden=false; - flag=false; - } - if(password !== password2) - { - document.getElementById("password-match-error").hidden=false; - flag=false; - } - document.activeElement.blur(); - return flag; - -} - -function showLogin(l) { - document.getElementById("loginform").style.display = l ? "flex" : "none"; - document.getElementById("signupform").style.display = l ? "none" : "flex"; -} -- cgit v1.2.3