mirror of
https://github.com/FranP-code/Login-Form.git
synced 2025-10-12 23:52:47 +00:00
Logica de verificacion terminada
This commit is contained in:
@@ -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
23
logic/messages.php
Normal 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>';
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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
20
logic/sanitize.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
12
login.html
12
login.html
@@ -7,7 +7,6 @@
|
||||
<title>Log in</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<link rel="stylesheet" href="normalize.css">
|
||||
<script src="./scripts/login.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="header-login">
|
||||
@@ -18,11 +17,14 @@
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<form action="./logic/login.php" method="POST">
|
||||
<input type="text" placeholder="User" class="input-1">
|
||||
<input type="password" placeholder="Password" class="input-2">
|
||||
<input type="submit" value="Send" class="submit">
|
||||
<form action="./logic/login.php" method="POST" name="form">
|
||||
<input type="text" name="user" placeholder="User" class="input-1" required>
|
||||
<input type="password" name="password" placeholder="Password" class="input-2" required>
|
||||
<input type="submit" name="submit" value="Send" class="submit" required>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="./scripts/login.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -7,7 +7,6 @@
|
||||
<title>Register</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<link rel="stylesheet" href="normalize.css">
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="header-register">
|
||||
@@ -19,12 +18,14 @@
|
||||
|
||||
|
||||
<div>
|
||||
<form action="./logic/register.php" method="POST">
|
||||
<input type="text" placeholder="User" class="input-1" required>
|
||||
<input type="password" placeholder="Password" class="input-2" required>
|
||||
<input type="password" placeholder="Repeat Password" class="input2" required>
|
||||
<input type="submit" value="Send" class="submit">
|
||||
<form action="./logic/register.php" method="POST" name="form">
|
||||
<input type="text" name="user"placeholder="User" class="input-1" required maxlength="20">
|
||||
<input type="password" name="password" placeholder="Password" class="input-2" required maxlength="20">
|
||||
<input type="password" name="confirm-password" placeholder="Repeat Password" class="input2" required maxlength="20">
|
||||
<input type="submit" name="submit" value="Send" class="submit">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="./scripts/register.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -32,6 +32,7 @@ header {
|
||||
width: 80px;
|
||||
height: 50px;
|
||||
clip-path: polygon(40% 0%, 40% 20%, 100% 20%, 100% 80%, 40% 80%, 40% 100%, 0% 50%);
|
||||
/* CREDITS FOR THE CLIP-PATH: https://bennettfeely.com/clippy/ ARROW FIGURE*/
|
||||
position: absolute;
|
||||
top: 37px;
|
||||
left: 20px ;
|
||||
|
||||
Reference in New Issue
Block a user