Logica de verificacion terminada

This commit is contained in:
2021-05-20 12:26:42 -03:00
parent 5a25331dc9
commit 9b934b2c95
9 changed files with 144 additions and 11 deletions

View File

@@ -0,0 +1,39 @@
<?php
require 'messages.php';
require 'sanitize.php';
$user = $_POST['user'];
$password = $_POST['password'];
if (isset($_POST['submit'])) {
if(isset($user) && isset($password)) {
if(strlen($user) <= 20) {
if(strlen($password) <= 20){
sanitize('user', $user);
} else {
echo error('The password has more characters than allowed!');
echo backToPreviusPage(3, '../login.html');
}
} else {
echo error('The user has more characters than allowed!');
echo backToPreviusPage(3, '../login.html');
}
} else {
echo error('Some of the fields were not filled. Try again please');
echo backToPreviusPage(3, '../login.html');
}
} else {
echo error('There was an error sending the form');
echo backToPreviusPage(3, '../login.html');
}
?>

23
logic/messages.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
function error($string) {
return '<h2 class=`invalid`>'. $string . '</h2>';
}
function backToPreviusPage($secs, $linkPage) {
return '<h3 class=`backToPreviousPage`>Coming back to the previous page in ' . $secs . ' seconds' .
'<script>
function goBackPage() {
window.location.replace(`' . $linkPage . '`)
console.log(`funka`)
}
setTimeout(goBackPage, ' . $secs * 1000 . ')
</script>';
}
?>

View File

@@ -0,0 +1,47 @@
<?php
require 'messages.php';
require 'sanitize.php';
$user = $_POST['user'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm-password'];
if (isset($_POST['submit'])) {
if (isset($user) && isset($password) && isset($confirm_password)) {
if ($password === $confirm_password) {
if (strlen($user) <= 20) {
if (strlen($password) <= 20) {
sanitize('user', $user);
} else {
echo error('The password has more characters than allowed!');
echo backToPreviusPage(3, '../register.html');
}
} else {
echo error('The user has more characters than allowed!');
echo backToPreviusPage(3, '../register.html');
}
} else {
echo error('The passwords doesn'. `'` . 't match');
echo backToPreviusPage(3, '../register.html');
}
} else {
echo error('Some of the fields were not filled. Try again please');
echo backToPreviusPage(3, '../register.html');
}
} else {
echo error('There was an error sending the form');
echo backToPreviusPage(3, '../register.html');
}
?>

20
logic/sanitize.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
function sanitize($typeOfField, $field) {
switch($typeOfField) {
case ($typeOfField === 'user'):
return filter_var($field, FILTER_SANITIZE_STRING);
break;
case ($typeOfField === 'email'):
return filter_var($field, FILTER_SANITIZE_EMAIL);
break;
default:
return 'The value in the '. $typeOfField . 'field is not valid';
break;
}
}
?>