From 9cab0d0ed64f4e5289a0c979cae10a92508c391b Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 28 Jan 2021 18:16:41 +0200 Subject: initial registering stuff --- file_type_recogniser.php | 84 -------------------------------- index.html | 4 +- php/configuration.php | 17 +++++++ php/database.php | 111 +++++++++++++++++++++++++++++++++++++++++++ php/file_type_recogniser.php | 84 ++++++++++++++++++++++++++++++++ php/misc.php | 18 +++++++ php/upload.php | 23 +++++++++ php/user.php | 10 ++++ register.php | 26 ++++++++++ sql/fileshare.sql | 50 +++++++------------ upload.php | 23 --------- 11 files changed, 308 insertions(+), 142 deletions(-) delete mode 100644 file_type_recogniser.php create mode 100644 php/configuration.php create mode 100644 php/database.php create mode 100644 php/file_type_recogniser.php create mode 100644 php/misc.php create mode 100644 php/upload.php create mode 100644 php/user.php create mode 100644 register.php delete mode 100644 upload.php diff --git a/file_type_recogniser.php b/file_type_recogniser.php deleted file mode 100644 index f160fb7..0000000 --- a/file_type_recogniser.php +++ /dev/null @@ -1,84 +0,0 @@ -file($path_to_file); -} - - -function file_extension($path_to_file) { - #FILEINFO_EXTENSION introduced in php7.2.0 https://www.php.net/manual/en/fileinfo.constants.php - if(defined("FILEINFO_EXTENSION")) - { - $file_type_database = new finfo(FILEINFO_EXTENSION); - return "." . $file_type_database->file($path_to_file); - }else - { - $result=file_type($path_to_file); - - $optimus_prime = array( - 'text/plain'=>'.txt', - 'text/html'=>'.html', - 'text/php'=>'.php', - 'text/css'=>'.css', - 'application/javascript'=>'.js', - 'application/json'=>'.json', - 'application/xml'=>'.xml', - 'application/x-shockwave-flash'=>'.swf', - 'video/x-flv'=>'.flv', - 'image/png'=>'.png', - 'image/jpeg'=>'.jpe', - 'image/jpeg'=>'.jpeg', - 'image/jpeg'=>'.jpg', - 'image/gif'=>'.gif', - 'image/bmp'=>'.bmp', - 'image/vnd.microsoft.icon'=>'.ico', - 'image/tiff'=>'.tiff', - 'image/tiff'=>'.tif', - 'image/svg+xml'=>'.svg', - 'image/svg+xml'=>'.svgz', - 'application/zip'=>'.zip', - 'application/x-rar-compressed'=>'.rar', - 'application/x-msdownload'=>'.exe', - 'application/x-msdownload'=>'.msi', - 'application/vnd.ms-cab-compressed'=>'.cab', - 'audio/mpeg'=>'.mp3', - 'video/quicktime'=>'.qt', - 'video/quicktime'=>'.mov', - 'application/pdf'=>'.pdf', - 'image/vnd.adobe.photoshop'=>'.psd', - 'application/postscript'=>'.ai', - 'application/postscript'=>'.eps', - 'application/postscript'=>'.ps', - 'application/msword'=>'.doc', - 'application/rtf'=>'.rtf', - 'application/vnd.ms-excel'=>'.xls', - 'application/vnd.ms-powerpoint'=>'.ppt', - 'application/vnd.oasis.opendocument.text'=>'.odt', - 'application/vnd.oasis.opendocument.spreadsheet'=>'.ods' - ); - - if(!array_key_exists($result,$optimus_prime)) - { - return ".dat"; - }else - { - return $optimus_prime[$result]; - } - - } -} - -function get_icon($path_to_file) -{ - $file_ext="svg/icons/".file_extension($path_to_file).".svg"; - if(!file_exists($file_ext)) - { - return "svg/icons/.dat.svg"; - }else - { - return $file_ext; - } -} - -?> diff --git a/index.html b/index.html index 5a60526..ba6733f 100644 --- a/index.html +++ b/index.html @@ -27,11 +27,13 @@
-
+

Get started

Username

+

Email address

+

Password

Repeat Password

diff --git a/php/configuration.php b/php/configuration.php new file mode 100644 index 0000000..6b87508 --- /dev/null +++ b/php/configuration.php @@ -0,0 +1,17 @@ + diff --git a/php/database.php b/php/database.php new file mode 100644 index 0000000..934aafa --- /dev/null +++ b/php/database.php @@ -0,0 +1,111 @@ +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 userid*/ + function get_user(string $user) + { + $ret=new User; + + $prep=$this->pdo->prepare("select user_id,username,email from users where username=:username"); + $prep->bindParam(':username',$user); + + $prep->execute(); + + $hold=$prep->fetch(PDO::FETCH_ASSOC); + + if($hold) + { + $ret->user_id=$hold["user_id"]; + $ret->username=$hold["username"]; + $ret->email_address=$hold["email"]; + return $ret; + }else + { + return false; + } + } + /*returns false if this isn't a user or the password is incorrect, otherwise returns the userid*/ + function authenticate(string $user, string $password) + { + $ret=new User; + global $password_hash_algo; + + + + $hashed_pass=password_hash($password,$password_hash_algo); + $prep=$this->pdo->prepare("select user_id,username,email from users where username=:username and password=:password"); + $prep->bindParam(':username',$user); + $prep->bindParam(':password',$hashed_pass); + + $prep->execute(); + + $hold=$prep->fetch(PDO::FETCH_ASSOC); + if($hold) + { + $ret->user_id=hold["user_id"]; + $ret->username=hold["username"]; + $ret->email_address["email"]; + return $ret; + }else + { + return false; + } + } + /*returns false if username is taken, email is not checked here*/ + function register_user(string $user,string $password,string $email) : bool + { + $hold=$this->get_user($user); + global $domain_name; + global $has_email_verification; + global $password_hash_algo; + + + if($hold) + { + return false; + }else + { + if($has_email_verification) + { + generate_email_verification_link(); + }else + { + $hashed_pass=password_hash($password,$password_hash_algo); + $prep=$this->pdo->prepare("insert into users(username,password,email) values(:username,:password,:email)"); + $prep->bindParam(':username',$user); + $prep->bindParam(':password',$hashed_pass); + $prep->bindParam(':email',$email); + $prep->execute(); + } + return true; + } + } + } + + +?> diff --git a/php/file_type_recogniser.php b/php/file_type_recogniser.php new file mode 100644 index 0000000..f160fb7 --- /dev/null +++ b/php/file_type_recogniser.php @@ -0,0 +1,84 @@ +file($path_to_file); +} + + +function file_extension($path_to_file) { + #FILEINFO_EXTENSION introduced in php7.2.0 https://www.php.net/manual/en/fileinfo.constants.php + if(defined("FILEINFO_EXTENSION")) + { + $file_type_database = new finfo(FILEINFO_EXTENSION); + return "." . $file_type_database->file($path_to_file); + }else + { + $result=file_type($path_to_file); + + $optimus_prime = array( + 'text/plain'=>'.txt', + 'text/html'=>'.html', + 'text/php'=>'.php', + 'text/css'=>'.css', + 'application/javascript'=>'.js', + 'application/json'=>'.json', + 'application/xml'=>'.xml', + 'application/x-shockwave-flash'=>'.swf', + 'video/x-flv'=>'.flv', + 'image/png'=>'.png', + 'image/jpeg'=>'.jpe', + 'image/jpeg'=>'.jpeg', + 'image/jpeg'=>'.jpg', + 'image/gif'=>'.gif', + 'image/bmp'=>'.bmp', + 'image/vnd.microsoft.icon'=>'.ico', + 'image/tiff'=>'.tiff', + 'image/tiff'=>'.tif', + 'image/svg+xml'=>'.svg', + 'image/svg+xml'=>'.svgz', + 'application/zip'=>'.zip', + 'application/x-rar-compressed'=>'.rar', + 'application/x-msdownload'=>'.exe', + 'application/x-msdownload'=>'.msi', + 'application/vnd.ms-cab-compressed'=>'.cab', + 'audio/mpeg'=>'.mp3', + 'video/quicktime'=>'.qt', + 'video/quicktime'=>'.mov', + 'application/pdf'=>'.pdf', + 'image/vnd.adobe.photoshop'=>'.psd', + 'application/postscript'=>'.ai', + 'application/postscript'=>'.eps', + 'application/postscript'=>'.ps', + 'application/msword'=>'.doc', + 'application/rtf'=>'.rtf', + 'application/vnd.ms-excel'=>'.xls', + 'application/vnd.ms-powerpoint'=>'.ppt', + 'application/vnd.oasis.opendocument.text'=>'.odt', + 'application/vnd.oasis.opendocument.spreadsheet'=>'.ods' + ); + + if(!array_key_exists($result,$optimus_prime)) + { + return ".dat"; + }else + { + return $optimus_prime[$result]; + } + + } +} + +function get_icon($path_to_file) +{ + $file_ext="svg/icons/".file_extension($path_to_file).".svg"; + if(!file_exists($file_ext)) + { + return "svg/icons/.dat.svg"; + }else + { + return $file_ext; + } +} + +?> diff --git a/php/misc.php b/php/misc.php new file mode 100644 index 0000000..3ab0277 --- /dev/null +++ b/php/misc.php @@ -0,0 +1,18 @@ + diff --git a/php/upload.php b/php/upload.php new file mode 100644 index 0000000..93fa778 --- /dev/null +++ b/php/upload.php @@ -0,0 +1,23 @@ + diff --git a/php/user.php b/php/user.php new file mode 100644 index 0000000..1ef3083 --- /dev/null +++ b/php/user.php @@ -0,0 +1,10 @@ + diff --git a/register.php b/register.php new file mode 100644 index 0000000..7d6c03e --- /dev/null +++ b/register.php @@ -0,0 +1,26 @@ +register_user($username,$password,$email)) +{ + echo "registered"; +}else +{ + echo "didn't register"; +} + +?> diff --git a/sql/fileshare.sql b/sql/fileshare.sql index f927ffc..a079a7f 100644 --- a/sql/fileshare.sql +++ b/sql/fileshare.sql @@ -1,49 +1,31 @@ -drop database fileshare; - - - - - -create database fileshare; -use fileshare; - /*base user information*/ create table users ( - id int not null auto_increment, + user_id int not null auto_increment, username varchar(50) not null unique, - password varchar(100) not null unique, - primary key (id) + password varchar(255) not null, + email varchar(50), + primary key (user_id) ); /*table has only one owner and is identifyed by a number*/ create table files ( - id int not null auto_increment, - owner int default null, - absolutepath varchar(500) not null, + file_id int not null auto_increment, + owner_id int default null, + relative_path varchar(500) not null, type varchar(20) not null default 'data', - primary key (id), - foreign key (owner) references users(id) + primary key (file_id), + foreign key (owner_id) references users(user_id) ); /*the user with userid is given some kind of access to the file with fileid*/ /*there is no edit bit because it will be too dificult to implement prehaps a change bit is in order (but not an edit bit)*/ /*might be beneficial to even go full minimalist and remove the remove bit and only have the view bit*/ create table access ( - fileid int not null, - userid int not null, - canview boolean not null default true, - canremove boolean not null default false, - check (canview=true or canremove=true) , - foreign key (fileid) references files(id), - foreign key (userid) references users(id) + file_id int not null, + user_id int not null, + can_view boolean not null default true, + can_remove boolean not null default false, + check (can_view=true or can_remove=true) , + foreign key (file_id) references files(file_id), + foreign key (user_id) references users(user_id) ); - - - -/*basic info for testing purposes*/ -insert into users(username,password) values ("root","asdf"); -insert into users(username,password) values ("tester","tester"); -insert into files(owner,absolutepath,type) values (1,"/root/jiberish.sh","shell script"); -insert into access(fileid,userid,canview,canremove) values(1,2,true,false); -/*I am not sure why this passes ....*/ -insert into access(fileid,userid,canview,canremove) values(1,2,false,false); diff --git a/upload.php b/upload.php deleted file mode 100644 index 93fa778..0000000 --- a/upload.php +++ /dev/null @@ -1,23 +0,0 @@ - -- cgit v1.2.3 From 758afd5feefbf3a76f5c6abe8bff8c08f39dd7cc Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 28 Jan 2021 19:05:24 +0200 Subject: restructuring stuff --- arrow.svg | 62 -------------------- arrows.js | 37 ------------ bottom.svg | 62 -------------------- css/style.css | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 57 ------------------ index.php | 57 ++++++++++++++++++ js/arrows.js | 37 ++++++++++++ register.php | 1 + style.css | 181 --------------------------------------------------------- svg/arrow.svg | 62 ++++++++++++++++++++ svg/bottom.svg | 62 ++++++++++++++++++++ 11 files changed, 400 insertions(+), 399 deletions(-) delete mode 100644 arrow.svg delete mode 100644 arrows.js delete mode 100644 bottom.svg create mode 100644 css/style.css delete mode 100644 index.html create mode 100644 index.php create mode 100644 js/arrows.js delete mode 100644 style.css create mode 100644 svg/arrow.svg create mode 100644 svg/bottom.svg diff --git a/arrow.svg b/arrow.svg deleted file mode 100644 index 040182d..0000000 --- a/arrow.svg +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/arrows.js b/arrows.js deleted file mode 100644 index ec7352c..0000000 --- a/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.remove(ob); - }, 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/bottom.svg b/bottom.svg deleted file mode 100644 index 772081e..0000000 --- a/bottom.svg +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..e6c5e93 --- /dev/null +++ b/css/style.css @@ -0,0 +1,181 @@ +html, body { + margin: 0; + height: 100%; +} + +body { + background: #f0f0f0; + color: black; + font-family: sans-serif; + overflow: hidden; +} + +#page { + display: flex; + flex: 1 0 0; + align-items: stretch; +} + +#page > * { + flex: 1 0 0; +} + +#header { + background: white; + margin: 0; + padding: 1rem; + font-size: 2em; +} + +.logo { + font-family: monospace; + margin: 0; +} + +#hero { + flex: 1.5 0 0; + position: relative; + font-size: 3.5rem; +} + +.vcenter { + display: flex; + flex-direction: column; + justify-content: center; +} + +#hero .bg { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: -5; +} + +#hero > * > p { + color: #676d75; + margin: 0rem; + padding: 0.5rem; + white-space: nowrap; + text-align: center; +} + +#hero .big { + font-size: 1.2em; +} + +.blue { + color: #231179; + font-weight: bold; +} + + +form { + background: white; + margin: 4.5rem; + padding-top: 0; + box-shadow: 0 0.8rem 1.3rem rgba(0,0,0,0.2); + border-radius: 0.5rem; + border-radius: 0.5rem; + border: 1px solid #b9b9b9; +} + +.vert { + justify-content: center; + display: flex; + flex-direction: column; +} + +.vert2 { + display: flex; + flex-direction: column; +} + +.overlay { + display: grid; +} + +.overlay > * { + grid-row: 1; + grid-column: 1; +} + +form > .content { + margin: 2rem; + margin-top: 1rem; + margin-bottom: 1.7rem; + padding: 0; + display: flex; + flex-direction: column; + justify-content: center; +} + +form > h2 { + color: #4d4d4d; + margin: 0; + text-align: center; + padding: 1rem; + background: #f0f0f0; + border-top-left-radius: 0.5rem; + border-top-right-radius: 0.5rem; +} + +form p { + margin: 1rem 0px 0.3rem 0px; +} + +input { + min-width: 300px; + border: 1px solid #bbb; + padding: 0.5rem; + font-size: inherit; + font-family: inherit; + border-radius: 0.3rem; + background: #fdfdfd; + transition: background 0.15s, border-color 0.35s; +} + +input[type=submit] { + cursor: pointer; + margin-top: 2rem; + width: 100%; + display: block; + padding: 0.7rem; + font-size: 1.1em; + box-shadow: 0 0.2rem 0.6rem #eee; + background: #231179; + color: white; +} + +input:focus, +input:hover { + background: white; +} + +input:focus { + border-color: black; +} + +input[type=submit]:hover { + background: #5b4d9d; +} + +.bgbottom { + position: absolute; + bottom: 0; + left: 0; + width: 100%; + z-index: -100; +} + + +#arrows { + position: relative; +} + +#arrows > img { + position: absolute; + bottom: 0; + z-index: -200; +} diff --git a/index.html b/index.html deleted file mode 100644 index ba6733f..0000000 --- a/index.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 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? Sign in -

- -
- - -
-
- - -
- - - - - diff --git a/index.php b/index.php new file mode 100644 index 0000000..2d1ddfb --- /dev/null +++ b/index.php @@ -0,0 +1,57 @@ + + + + + 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? Sign in +

+
+
+ + +
+
+ + +
+ + + + + diff --git a/js/arrows.js b/js/arrows.js new file mode 100644 index 0000000..a23af87 --- /dev/null +++ b/js/arrows.js @@ -0,0 +1,37 @@ + +arrows = []; + +const minSpeed = 3; +const maxSpeed = 8; +const delay = 1500; +const lifetime = 25000; + +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.remove(ob); + }, 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/register.php b/register.php index 7d6c03e..0c00ad4 100644 --- a/register.php +++ b/register.php @@ -1,6 +1,7 @@ * { - flex: 1 0 0; -} - -#header { - background: white; - margin: 0; - padding: 1rem; - font-size: 2em; -} - -.logo { - font-family: monospace; - margin: 0; -} - -#hero { - flex: 1.5 0 0; - position: relative; - font-size: 3.5rem; -} - -.vcenter { - display: flex; - flex-direction: column; - justify-content: center; -} - -#hero .bg { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - z-index: -5; -} - -#hero > * > p { - color: #676d75; - margin: 0rem; - padding: 0.5rem; - white-space: nowrap; - text-align: center; -} - -#hero .big { - font-size: 1.2em; -} - -.blue { - color: #231179; - font-weight: bold; -} - - -form { - background: white; - margin: 4.5rem; - padding-top: 0; - box-shadow: 0 0.8rem 1.3rem rgba(0,0,0,0.2); - border-radius: 0.5rem; - border-radius: 0.5rem; - border: 1px solid #b9b9b9; -} - -.vert { - justify-content: center; - display: flex; - flex-direction: column; -} - -.vert2 { - display: flex; - flex-direction: column; -} - -.overlay { - display: grid; -} - -.overlay > * { - grid-row: 1; - grid-column: 1; -} - -form > .content { - margin: 2rem; - margin-top: 1rem; - margin-bottom: 1.7rem; - padding: 0; - display: flex; - flex-direction: column; - justify-content: center; -} - -form > h2 { - color: #4d4d4d; - margin: 0; - text-align: center; - padding: 1rem; - background: #f0f0f0; - border-top-left-radius: 0.5rem; - border-top-right-radius: 0.5rem; -} - -form p { - margin: 1rem 0px 0.3rem 0px; -} - -input { - min-width: 300px; - border: 1px solid #bbb; - padding: 0.5rem; - font-size: inherit; - font-family: inherit; - border-radius: 0.3rem; - background: #fdfdfd; - transition: background 0.15s, border-color 0.35s; -} - -input[type=submit] { - cursor: pointer; - margin-top: 2rem; - width: 100%; - display: block; - padding: 0.7rem; - font-size: 1.1em; - box-shadow: 0 0.2rem 0.6rem #eee; - background: #231179; - color: white; -} - -input:focus, -input:hover { - background: white; -} - -input:focus { - border-color: black; -} - -input[type=submit]:hover { - background: #5b4d9d; -} - -.bgbottom { - position: absolute; - bottom: 0; - left: 0; - width: 100%; - z-index: -100; -} - - -#arrows { - position: relative; -} - -#arrows > img { - position: absolute; - bottom: 0; - z-index: -200; -} diff --git a/svg/arrow.svg b/svg/arrow.svg new file mode 100644 index 0000000..040182d --- /dev/null +++ b/svg/arrow.svg @@ -0,0 +1,62 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/svg/bottom.svg b/svg/bottom.svg new file mode 100644 index 0000000..772081e --- /dev/null +++ b/svg/bottom.svg @@ -0,0 +1,62 @@ + + + + + + + + image/svg+xml + + + + + + + + + + -- cgit v1.2.3 From 5d3d901d968db7eb3da9c038e6d823f7c75f1e10 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 29 Jan 2021 02:16:01 +0200 Subject: some cosmetic stuff --- css/style.css | 15 +++++++++++++++ index.php | 9 ++++++++- js/arrows.js | 2 +- js/validate_hero.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 js/validate_hero.js diff --git a/css/style.css b/css/style.css index e6c5e93..76eb6e8 100644 --- a/css/style.css +++ b/css/style.css @@ -125,6 +125,21 @@ form p { margin: 1rem 0px 0.3rem 0px; } + +.hero_form_error { + animation: fadein 0.2s; + background-color: #ff4d4d; + color: #ffffff; + padding-left: 0.5rem; + border-bottom-left-radius: 0.5rem; + border-bottom-right-radius: 0.5rem; + margin-top: -0.2rem; + +} +@keyframes fadein { + from { opacity: 0; } + to { opacity: 1; } +} input { min-width: 300px; border: 1px solid #bbb; diff --git a/index.php b/index.php index 2d1ddfb..38eb660 100644 --- a/index.php +++ b/index.php @@ -27,17 +27,23 @@
-
+

Get started

Username

+ +

Email address

+ +

Password

+

Repeat Password

+

Already have an account? Sign in

@@ -52,6 +58,7 @@
+ diff --git a/js/arrows.js b/js/arrows.js index a23af87..ec7352c 100644 --- a/js/arrows.js +++ b/js/arrows.js @@ -4,7 +4,7 @@ arrows = []; const minSpeed = 3; const maxSpeed = 8; const delay = 1500; -const lifetime = 25000; +const lifetime = 20000; function make_arrow() { const svg = document.getElementById("protoarrow").cloneNode(); diff --git a/js/validate_hero.js b/js/validate_hero.js new file mode 100644 index 0000000..118abbf --- /dev/null +++ b/js/validate_hero.js @@ -0,0 +1,43 @@ + +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_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 !== password2) + { + document.getElementById("password-error").hidden=false; + flag=false; + } + + if(flag) + { + document.getElementById("success").hidden=false; + } + return flag; + +} -- cgit v1.2.3 From 472e170f408e3d8d1db2eb066d445153aad55d73 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 29 Jan 2021 03:26:28 +0200 Subject: register and login looks ok --- README | 6 +++++ css/style.css | 1 + index.html | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 64 ---------------------------------------------------- js/arrows.js | 2 +- js/validate_hero.js | 25 ++++++++++++++++----- login.html | 55 +++++++++++++++++++++++++++++++++++++++++++++ php/database.php | 25 +++++++++++---------- php/login.php | 25 +++++++++++++++++++++ php/register.php | 27 ++++++++++++++++++++++ register.php | 27 ---------------------- 11 files changed, 213 insertions(+), 109 deletions(-) create mode 100644 README create mode 100644 index.html delete mode 100644 index.php create mode 100644 login.html create mode 100644 php/login.php create mode 100644 php/register.php delete mode 100644 register.php diff --git a/README b/README new file mode 100644 index 0000000..e9f371a --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +FILEUP + + + +for this to work you need to have mysql. Create a database and a user for this service then +modify php/configure.php as needed. Create tables described in sql/fileshare.sql diff --git a/css/style.css b/css/style.css index 76eb6e8..31778c4 100644 --- a/css/style.css +++ b/css/style.css @@ -161,6 +161,7 @@ input[type=submit] { box-shadow: 0 0.2rem 0.6rem #eee; background: #231179; color: white; + outline: none; } input:focus, diff --git a/index.html b/index.html new file mode 100644 index 0000000..6a2018b --- /dev/null +++ b/index.html @@ -0,0 +1,65 @@ + + + + + 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 deleted file mode 100644 index 38eb660..0000000 --- a/index.php +++ /dev/null @@ -1,64 +0,0 @@ - - - - - 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? Sign in -

-
-
- - -
-
- - -
- - - - - - diff --git a/js/arrows.js b/js/arrows.js index ec7352c..10ad416 100644 --- a/js/arrows.js +++ b/js/arrows.js @@ -20,7 +20,7 @@ function make_arrow() { setTimeout(make_arrow, delay); setTimeout(() => { svg.remove(); - arrows.remove(ob); + arrows.shift(); }, lifetime); } diff --git a/js/validate_hero.js b/js/validate_hero.js index 118abbf..6d29a53 100644 --- a/js/validate_hero.js +++ b/js/validate_hero.js @@ -8,6 +8,20 @@ function clear_hero_errors() 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; @@ -28,16 +42,17 @@ function validate_hero_form() document.getElementById("email-error").hidden=false; flag=false; } - if(password !== password2) + if(password.length==0) { - document.getElementById("password-error").hidden=false; + document.getElementById("password-length-error").hidden=false; flag=false; } - - if(flag) + if(password !== password2) { - document.getElementById("success").hidden=false; + document.getElementById("password-match-error").hidden=false; + flag=false; } + document.activeElement.blur(); return flag; } diff --git a/login.html b/login.html new file mode 100644 index 0000000..525358f --- /dev/null +++ b/login.html @@ -0,0 +1,55 @@ + + + + + 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/php/database.php b/php/database.php index 934aafa..ef2b825 100644 --- a/php/database.php +++ b/php/database.php @@ -26,7 +26,7 @@ require_once "misc.php"; } } - /*returns false if this isn't a user, otherwise returns the userid*/ + /*returns false if this isn't a user, otherwise returns the user*/ function get_user(string $user) { $ret=new User; @@ -53,24 +53,25 @@ require_once "misc.php"; function authenticate(string $user, string $password) { $ret=new User; - global $password_hash_algo; - - - $hashed_pass=password_hash($password,$password_hash_algo); - $prep=$this->pdo->prepare("select user_id,username,email from users where username=:username and password=:password"); + $prep=$this->pdo->prepare("select user_id,username,email,password from users where username=:username"); $prep->bindParam(':username',$user); - $prep->bindParam(':password',$hashed_pass); - $prep->execute(); $hold=$prep->fetch(PDO::FETCH_ASSOC); + if($hold) { - $ret->user_id=hold["user_id"]; - $ret->username=hold["username"]; - $ret->email_address["email"]; - return $ret; + if(password_verify($password,$hold["password"])) + { + $ret->user_id=$hold["user_id"]; + $ret->username=$hold["username"]; + $ret->email_address=$hold["email"]; + return $ret; + }else + { + return false; + } }else { return false; diff --git a/php/login.php b/php/login.php new file mode 100644 index 0000000..e6d44dc --- /dev/null +++ b/php/login.php @@ -0,0 +1,25 @@ +authenticate($username,$password); +if(!$user) +{ + die("Password or username is incorrect"); +} + +echo "Username: {$user->username}\n"; +echo "Email: {$user->email_address}"; + + +?> diff --git a/php/register.php b/php/register.php new file mode 100644 index 0000000..b6b164c --- /dev/null +++ b/php/register.php @@ -0,0 +1,27 @@ +register_user($username,$password,$email)) +{ + echo "registered"; +}else +{ + echo "didn't register"; +} + +?> diff --git a/register.php b/register.php deleted file mode 100644 index 0c00ad4..0000000 --- a/register.php +++ /dev/null @@ -1,27 +0,0 @@ -register_user($username,$password,$email)) -{ - echo "registered"; -}else -{ - echo "didn't register"; -} - -?> -- cgit v1.2.3