public function add() { //verifications formulaire inscription $data = array(); if (isset($_POST['cli_pseudo']) && isset($_POST['cli_motpasse']) && isset($_POST['mdp_confirm']) && isset($_POST['cli_mel']) && isset($_POST['mail_confirm']) && isset($_POST['cli_nom']) && isset($_POST['cli_prenom']) && isset($_POST['cli_telfixe']) && isset($_POST['cli_telportable'])) { $pattern = '/[\\[\\]* + ? | { } () ^ ." <> ! $ ; : § , ¨ & ~ \\\\ \\/ @ = ]/'; $patterntelfixe = '/^0[1-58][0-9]{8}$/'; $patterntelport = '/^0[67][0-9]{8}$/'; $pattern_nom = '/[0-9\\[\\]* + ? | { } () ^ ." <> ! $ ; : § , ¨ & ~ \\\\ \\/ @ = ]/'; //verif civilité if (empty($_POST['cli_civilite'])) { $msgerror = "Veuillez choisir une civilité"; $data[] = $msgerror; } //verif pseudos if (empty($_POST['cli_pseudo'])) { $msgerror = "Le champ Pseudo est vide"; $data[] = $msgerror; } elseif (preg_match($pattern, $_POST['cli_pseudo'])) { $msgerror = "Caractères spéciaux interdits dans le champ Pseudo"; $data[] = $msgerror; } $listeclients = T_e_client_cli::findAll(); foreach ($listeclients as $t_e_client_cli) { if (strtolower($_POST['cli_pseudo']) == strtolower($t_e_client_cli->cli_pseudo)) { $msgerror = "Pseudo déjà enregistré"; $data[] = $msgerror; } } //verifs mdp & confirmation if (empty($_POST['cli_motpasse'])) { $msgerror = "Le champ Mot de passe est vide"; $data[] = $msgerror; } if (empty($_POST['mdp_confirm'])) { $msgerror = "Le champ Confirmez votre mot de passe est vide"; $data[] = $msgerror; } if (preg_match($pattern, $_POST['cli_motpasse'])) { $msgerror = "Caractères spéciaux interdits dans le champ Mot de passe"; $data[] = $msgerror; } if (strlen($_POST['cli_motpasse']) < 8 || strlen($_POST['cli_motpasse']) > 15) { $msgerror = "Le mot de passe doit contenir entre 8 et 15 caractères alphanumériques"; $data[] = $msgerror; } if ($_POST['cli_motpasse'] != $_POST['mdp_confirm']) { $msgerror = "Le mot de passe et la confirmation ne correspondent pas"; $data[] = $msgerror; } //verif mail if (empty($_POST['cli_mel'])) { $msgerror = "Le champ Adresse email est vide"; $data[] = $msgerror; } else { if (!filter_var($_POST['cli_mel'], FILTER_VALIDATE_EMAIL)) { $msgerror = "Le format de l'adresse mail est invalide"; $data[] = $msgerror; } } $listeclients = T_e_client_cli::findAll(); foreach ($listeclients as $t_e_client_cli) { if ($_POST['cli_mel'] == $t_e_client_cli->cli_mel) { $msgerror = "Adresse email déjà utilisée"; $data[] = $msgerror; } } if (empty($_POST['mail_confirm'])) { $msgerror = "Le champ Confirmez votre adresse email est vide"; $data[] = $msgerror; } if ($_POST['cli_mel'] != $_POST['mail_confirm']) { $msgerror = "L\\'email et la confirmation ne correspondent pas"; $data[] = $msgerror; } //verif nom et prenom if (empty($_POST['cli_nom'])) { $msgerror = "Le champ Nom est vide"; $data[] = $msgerror; } elseif (preg_match($pattern_nom, $_POST['cli_nom'])) { $msgerror = "Veuillez rentrer un nom valide"; $data[] = $msgerror; } if (empty($_POST['cli_prenom'])) { $msgerror = "Le champ Prénom est vide"; $data[] = $msgerror; } elseif (preg_match($pattern_nom, $_POST['cli_prenom'])) { $msgerror = "Veuillez rentrer un prénom valide"; $data[] = $msgerror; } //verif tel if (empty($_POST['cli_telfixe']) && empty($_POST['cli_telportable'])) { $msgerror = "Au moins un numéro de téléphone doit être renseigné"; $data[] = $msgerror; } if (!empty($_POST['cli_telfixe']) && !preg_match($patterntelfixe, $_POST['cli_telfixe'])) { $msgerror = "Format téléphone fixe invalide"; $data[] = $msgerror; } if (!empty($_POST['cli_telportable']) && !preg_match($patterntelport, $_POST['cli_telportable'])) { $msgerror = "Format téléphone portable invalide"; $data[] = $msgerror; } foreach ($listeclients as $t_e_client_cli) { if ($_POST['cli_telportable'] == $t_e_client_cli->cli_telportable && $_POST['cli_telportable'] != null) { $msgerror = "Numéro de téléphone portable déjà utilisé"; $data[] = $msgerror; break; } } if (!empty($data)) { $this->render("add", $data); } else { $client = new T_e_client_cli(); $client->cli_mel = parameters()["cli_mel"]; $client->cli_motpasse = md5(parameters()["cli_motpasse"]); $client->cli_pseudo = parameters()["cli_pseudo"]; $client->cli_civilite = parameters()["cli_civilite"]; $client->cli_nom = parameters()["cli_nom"]; $client->cli_prenom = parameters()["cli_prenom"]; $client->cli_telfixe = parameters()["cli_telfixe"]; $client->cli_telportable = parameters()["cli_telportable"]; $client2 = new T_e_client_cli($client->cli_id); $_SESSION['client'] = serialize($client2); $c = new SiteController(); $c->index(); } } else { $this->render("add"); } }
if (isset($_GET)) { foreach ($_GET as $k => $v) { $parameters[$k] = $v; } } // Pour accès ultérieur sans "global" function parameters() { global $parameters; return $parameters; } // Gestion des la route : paramètre r = controller/action if (isset(parameters()["r"])) { try { $route = parameters()["r"]; if (strpos($route, "/") === FALSE) { list($controller, $action) = array($route, "index"); } else { list($controller, $action) = explode("/", $route); } $controller = ucfirst($controller) . "Controller"; $c = new $controller(); $c->{$action}(); } catch (Exception $e) { $c = new SiteController(); $c->error404(); } } else { $c = new SiteController(); $c->index(); }
<?php function check_logged_in() { BaseController::check_logged_in(); } //hiekkis $routes->get('/hiekkalaatikko', function () { HelloWorldController::sandbox(); }); //index $routes->get('/', function () { SiteController::index(); }); //user $routes->get('/login', function () { UserController::login(); }); $routes->post('/login', function () { UserController::handle_login(); }); $routes->get('/logout', function () { UserController::handle_logout(); }); $routes->get('/user/:id', function ($id) { UserController::show($id); }); $routes->post('/user/:id', function ($id) { UserController::update($id); }); $routes->post('/user/:id/destroy', function ($id) {
<?php session_start(); /** * Archivo que inicia todo el */ /** * Función que realiza la autocarga de clases y archivos * @param string $className */ function __autoload($className) { $file = dirname(__FILE__) . '/../class/' . $className . '.php'; if (!file_exists($file)) { $file = dirname(__FILE__) . '/controller/' . $className . '.php'; if (!file_exists($file)) { $file = dirname(__FILE__) . '/config/' . $className . '.php'; if (file_exists($file)) { require_once $file; } } else { require_once $file; } } else { require_once $file; } } // index.php?site=maria $controller = new SiteController(); $controller->index();
public function unlog() { if (session_destroy()) { header("Refresh:0; url=../Sprint/"); $c = new SiteController(); $c->index(); } $m = new message(); $m->setFlash("Deconnexion réussie", "success"); }
<?php require_once dirname(__FILE__) . '/mvc/controllers/site_controller.php'; $siteController = new SiteController(); $siteController->index();