Création de repositories/StaticRepo@checkParam + ajout de repositories/StaticRepo@delNumeric

This commit is contained in:
xdrm-brackets 2015-12-02 11:44:39 +01:00
parent 5fe57e8c30
commit e96c75d9dd
5 changed files with 307 additions and 4 deletions

128
globalstylesheet.css Executable file
View File

@ -0,0 +1,128 @@
/*******************************/
/*** RECTIFICATIONS GLOBALES ***/
/*******************************/
*{ margin: 0; padding: 0; }
body{
/* position */
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* background */
background-color: #233342;
/* foreground */
font: 16px 'Open Sans';
color: #fff;
}
/*******************/
/*** FORMULAIRES ***/
/*******************/
form{
/* position */
display: block;
position: absolute;
left: calc( 50% - 20em/2 );
width: 20em;
height: auto;
margin: 2em;
padding: 2em;
/* border */
border-radius: 5px;
box-shadow: inset 0 0 10px #0a0f14;
/* background */
background-color: #151f28;
}
/************************/
/*** CHAMPS DE SAISIE ***/
/************************/
input{
/* position */
display: inline-block;
padding: 1em 2em;
margin: 1em;
width: calc( 100% - 2*2em - 5px - 2*1em );
/* border */
border-radius: 3px 0 0 3px;
border: 0;
border-right: 5px solid #aaa;
/* background */
background-color: #ddd;
/* animation */
transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
}
/* @hover */
input:focus { background-color: #fff; }
input:nth-child(4n+0):focus{ border-right-color: #f45b2a; }
input:nth-child(4n+1):focus{ border-right-color: #1b84db; }
input:nth-child(4n+2):focus{ border-right-color: #f4b92a; }
input:nth-child(4n+3):focus{ border-right-color: #b62af4; }
/*****************************/
/*** BOUTONS DE VALIDATION ***/
/*****************************/
input[type=submit],
input[type=button]{
/* position */
width: auto;
float: right;
/* foreground */
font-weight: bold;
}
input[type=submit]:hover,
input[type=button]:hover{
/* border */
border-right-color: #1b84db;
/* background */
background-color: #fff;
/* foreground */
color: #1b84db;
/* extra */
cursor: pointer;
}
/****************/
/*** MESSAGES ***/
/****************/
.error{
font-size: .8em;
padding: 1em 1em;
color: #f14973;
text-shadow: 1px 1px 0 #000;
}
.success{
font-size: .8em;
padding: 1em 1em;
color: #49f16b;
text-shadow: 1px 1px 0 #000;
}

72
login.php Executable file
View File

@ -0,0 +1,72 @@
<!DOCTYPE html>
<?php /* [0] VERIFICATION DE CONNECTION
=============================================*/
$postVariablesAreSet = isset($_POST['username']) && isset($_POST['mail']) && isset($_POST['password']) && isset($_POST['co']); // si les variables POST existent
$postVariablesTypeOk = $postVariablesAreSet && is_string($_POST['username']) && is_string($_POST['mail']) && is_string($_POST['password']) && is_string($_POST['co']); // si ce sont des string
$postVariablesNEmpty = $postVariablesTypeOk && strlen($_POST['username']) > 1 && strlen($_POST['mail']) > 1 && strlen($_POST['password']) > 1 && strlen($_POST['co']) > 1; // si au moins 1 caractère
$usernameCheck = $postVariablesNEmpty && preg_match("/^[\w -]{3,10}$/i", $_POST['username']); // utilisateur -> "alphanum_- " -> 3 à 10 caractères
$mailCheck = $usernameCheck && preg_match("/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i", $_POST['mail']); // mail -> bon format
$passwordCheck = $mailCheck && preg_match("/^[\w -]{8,50}$/i", $_POST['password']); // password -> "alphanum_- " -> 8 à 50 caractères
$coCheck = $passwordCheck && $_POST['co'] == 'Me connecter';
if( $coCheck ){ // si toutes les valeurs sont correctes
$user = array(); // on définit l'utilisateur
$user['name'] = $_POST['username'];
$user['mail'] = $_POST['mail'];
$user['password'] = $_POST['password'];
$user['hash'] = sha1($_POST['password']);
}
// retourne VRAI si l'utilisateur est connecté
function connected($user){ return ($user != null); }
?>
<html>
<head>
<title>Tests php</title>
<meta charset='utf-8'/>
<meta name='description' value='Site de test'/>
<meta name='author' value='{xdrm} & SeekDaSky'/>
<link rel='stylesheet' href='globalstylesheet.css'/>
</head>
<body>
<?php /* [1] AFFICHAGE DIFFÉRÉ SI CONNECTÉ
==============================================*/
echo "<form action='#auth' method='POST'>";
/* AFFICHAGE D'ERREURS */
if( $postVariablesAreSet ){ // si formulaire soumis
if( !$postVariablesNEmpty )
echo '<span class=error>Certains champs requis sont vides.</span>';
elseif( !$usernameCheck )
echo '<span class=error>Nom d\'utilisateur incorrect. (3 car. min)</span>';
elseif( !$mailCheck )
echo '<span class=error>Adresse mail incorrecte.</span>';
elseif( !$passwordCheck )
echo '<span class=error>Mot de passe incorrect. (8 car. min)</span>';
elseif( connected($user) )
echo '<span class=success>Vous êtes connectés.</span>';
}
echo "<input type='text' name='username' placeholder='username' " .( (connected($user)) ? "value='".$user['name']."'" : '' ).">";
echo "<input type='mail' name='mail' placeholder='mail' " .( (connected($user)) ? "value='".$user['mail']."'" : '' ).">";
echo "<input type='password' name='password' placeholder='password' ".( (connected($user)) ? "value='".$user['password']."'" : '' ).">";
echo "<input type='submit' name='co' value='Me connecter'>";
echo "</form>";
?>
</body>
</html>

View File

@ -31,6 +31,109 @@ class StaticRepo{
public static function testConnexion(){
return static::getConnexion() instanceof PDO;
}
/* SUPPRIME LES VALEURS À CLÉS NUMÉRIQUES DANS UN FETCH D'UNE TABLE DE LA BDD
*
* @fetchData<Array> le résultat d'une $requeteSQL->fetchAll() / $requeteSQL->fetch()
*
* @return newFetchData<Array> retourne le tableau donné en paramètre mais sans les valeurs à clés numériques
*
*/
public static function delNumeric($fetchData, $oneDimension=false){
/* [1] 2 dimensions
===============================================*/
if( !$oneDimension ){
// on supprime les doublons des entrées (indice numérique)
for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs
foreach($fetchData[$i] as $col => $val){ // pour toutes les entrées
if( !mb_detect_encoding($val, 'UTF-8') )
$fetchData[$i][$col] = utf8_encode($val);
if( is_int($col) ) // si l'indice est un entier
unset( $fetchData[$i][$col] ); // on le supprime
}
/* [2] 1 dimensions
===============================================*/
}else{
// on supprime les doublons des entrées (indice numérique)
foreach($fetchData as $i=>$val){ // pour toutes les entrées
if( !mb_detect_encoding($val, 'UTF-8') )
$fetchData[$i] = utf8_encode($val);
if( is_int($i) ) // si l'indice est un entier
unset( $fetchData[$i] ); // on le supprime
}
}
return $fetchData;
}
// _ _____ ___ _ _ ___ ____
// / \ | ___|_ _| \ | |_ _| _ \
// / _ \ | |_ | || \| || || |_) |
// / ___ \ | _| | || |\ || || _ <
// /_/ \_\ |_| |___|_| \_|___|_| \_\
/* Vérifie le type d'une variable
*
* @variable<mixed> la variable à vérifier
* @dbtype<String> le type correspondant à la vérification
*
*
* @return correct<Boolean> TRUE si le type est bon / FALSE si le type ne match pas
*
*/
public static function checkParam($variable, $dbtype){
/* [1] on vérifie que $dbtype est un String
=============================================================*/
if( !is_string($dbtype) ) return false;
/* [2] Vérifications
=============================================================*/
$checker = true; // contiendra VRAI si la vérification s'avère correcte
switch($dbtype){
// [1] 'M' / 'F'
case 'Civilité':
$checker = $checker && is_string($variable) && in_array(array('M', 'F'), $variable);
break;
// [2] Nom de patient
case 'Nom':
$checker = $checker && is_string($variable) && in_array(array('M', 'F'), $variable);
break;
// [N] Type inconnu
default: $checker = false; break;
}
/* [3] On retourne le résultat de la vérif
=============================================================*/
return $checker;
}
}
?>

View File

@ -1,6 +1,6 @@
{
"host": "serveurMySql",
"login": "leLogin",
"password": "leMotDePasse",
"database": "nomBaseDeDonnée"
"host": "localhost",
"login": "php",
"password": "Qt358nUdyeTxLDM8",
"database": "projetphp"
}

0
repositories/index.html Executable file → Normal file
View File