From e96c75d9dd662db3dcbd327b084919086e813b35 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 2 Dec 2015 11:44:39 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20repositories/StaticRepo@ch?= =?UTF-8?q?eckParam=20+=20ajout=20de=20repositories/StaticRepo@delNumeric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- globalstylesheet.css | 128 +++++++++++++++++++++++++++++++ login.php | 72 +++++++++++++++++ repositories/StaticRepo.php | 103 +++++++++++++++++++++++++ repositories/exemple_config.json | 8 +- repositories/index.html | 0 5 files changed, 307 insertions(+), 4 deletions(-) create mode 100755 globalstylesheet.css create mode 100755 login.php mode change 100755 => 100644 repositories/index.html diff --git a/globalstylesheet.css b/globalstylesheet.css new file mode 100755 index 0000000..55400fe --- /dev/null +++ b/globalstylesheet.css @@ -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; +} \ No newline at end of file diff --git a/login.php b/login.php new file mode 100755 index 0000000..84e8407 --- /dev/null +++ b/login.php @@ -0,0 +1,72 @@ + + + 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); } + +?> + + + + Tests php + + + + + + + + + + + + "; + + /* AFFICHAGE D'ERREURS */ + if( $postVariablesAreSet ){ // si formulaire soumis + if( !$postVariablesNEmpty ) + echo 'Certains champs requis sont vides.'; + elseif( !$usernameCheck ) + echo 'Nom d\'utilisateur incorrect. (3 car. min)'; + elseif( !$mailCheck ) + echo 'Adresse mail incorrecte.'; + elseif( !$passwordCheck ) + echo 'Mot de passe incorrect. (8 car. min)'; + elseif( connected($user) ) + echo 'Vous êtes connectés.'; + } + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + ?> + + + + \ No newline at end of file diff --git a/repositories/StaticRepo.php b/repositories/StaticRepo.php index 9c9d35f..e42f1fe 100755 --- a/repositories/StaticRepo.php +++ b/repositories/StaticRepo.php @@ -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 le résultat d'une $requeteSQL->fetchAll() / $requeteSQL->fetch() + * + * @return newFetchData 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 la variable à vérifier + * @dbtype le type correspondant à la vérification + * + * + * @return correct 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; + + } + + } ?> diff --git a/repositories/exemple_config.json b/repositories/exemple_config.json index 6469b2f..8f65e65 100644 --- a/repositories/exemple_config.json +++ b/repositories/exemple_config.json @@ -1,6 +1,6 @@ { - "host": "serveurMySql", - "login": "leLogin", - "password": "leMotDePasse", - "database": "nomBaseDeDonnée" + "host": "localhost", + "login": "php", + "password": "Qt358nUdyeTxLDM8", + "database": "projetphp" } diff --git a/repositories/index.html b/repositories/index.html old mode 100755 new mode 100644