public function action_valide() { /** --- Test la conformitude de tous les champs du formulaires coté serveur --- **/ // --- Champs nom --- // if ($this->req->nom == "") { $errors[] = "Le nom n'est pas rempli"; } else { if (!preg_match(self::EMPTY_REG, $this->req->nom)) { $errors[] = "Le nom est mal renseigné"; } } if (strlen($this->req->nom) >= self::NAME_LENGTH) { $errors[] = "La taille du nom doit être inférieur à " . self::NAME_LENGTH . " caractères"; } if (preg_match(self::NUM_REG, $this->req->nom)) { $errors[] = "Le nom ne doit pas contenir de chiffre"; } // --- Champs prénom --- // if ($this->req->prenom == "") { $errors[] = "Le prenom n'est pas rempli"; } else { if (!preg_match(self::EMPTY_REG, $this->req->prenom)) { $errors[] = "Le prénom est mal renseigné"; } } if (strlen($this->req->prenom) >= self::NAME_LENGTH) { $errors[] = "La taille du prénom doit être inférieur à " . self::NAME_LENGTH . " caractères"; } if (preg_match(self::NUM_REG, $this->req->prenom)) { $errors[] = "Le prénom ne doit pas contenir de chiffre"; } // --- Champs rue --- // if (strlen($this->req->rue) >= self::STREET_LENGTH) { $errors[] = "La taille de la rue doit être inférieur à " . self::STREET_LENGTH . " caractères"; } if (!preg_match(self::STREET_REG, $this->req->rue)) { $errors[] = "Le format du champs rue est: Numéro de rue(nombres) nom de la rue(caractères)"; } // --- Champs Code postal --- // if (!preg_match(self::CP_REG1, $this->req->cp) or preg_match(self::CP_REG2, $this->req->cp)) { $errors[] = "Format du code postal incorrect. Contien 5 chiffres de 01000 à 99999"; } // --- Test si mail déja existant --- (mail => login) // $cm = new ClientManager(DB::get_instance()); if ($cm->chercherParMail($this->req->mail)) { $errors[] = "Mail existant"; } if (!filter_var($this->req->mail, FILTER_VALIDATE_EMAIL)) { $errors[] = "Le mail n'est pas conforme"; } // --- Champs mdp ---// if (strlen($this->req->mdp) < self::MIN_MDP) { $errors[] = "Le mot de passe est trop petit"; } else { if (strlen($this->req->mdp) > self::MAX_MDP) { $errors[] = "Le mot de passe est trop grand"; } } // --- Champs confirmation --- // if ($this->req->mdp != $this->req->mdp2) { $errors[] = "La confirmation ne correspond pas au mot de passe"; } // --- Vérification CAPTCHA --- // if ($this->req->hide && $this->req->cap) { $cap = $this->req->hide; $cap = substr($cap, 2, 3); echo var_dump($cap); if ($cap != $this->req->cap) { $errors[] = "Le captcha n'est pas bon"; } } // -- Si on trouve des erreurs on les affiche en haut du formulaire -- // if (isset($errors[0])) { $f = $this->session->formIns; $f->populate(); $this->session->formIns = $f; foreach ($errors as $err) { $this->site->ajouter_message("-" . $err); } Site::redirect("inscription"); } else { $clt['nom'] = $this->req->nom; $clt['prenom'] = $this->req->prenom; $clt['rue'] = $this->req->rue; $clt['codePostal'] = $this->req->cp; $clt['ville'] = $this->req->ville; $clt['vip'] = 0; $clt['dateInscription'] = date('Y-m-d', time() + 7200); //+7200 Pour mettre en GMT+2 $clt['mail'] = $this->req->mail; $clt['mdp'] = $this->req->mdp; $clt['validate'] = 0; $client = new Client($clt); $cm->add($client); $client2 = $cm->connexion($clt['mail'], $clt['mdp']); // On supprime maintenant la variable contenant les entrées de l'utilisateur sur le form inscription. unset($this->session->formIns); // --On envoie le mail avec la vérif-- if ($client2) { $subject = "Loca-Rent : Bienvenue chère client."; $to = $clt['mail']; $code = md5($clt['prenom'] . $clt['nom'] . time()); $vm = new VerifManager(DB::get_instance()); $ver['codeVerif'] = $code; $ver['idClient'] = $client2->getIdClient(); //echo var_dump($client->getIdClient()); $verif = new Verif($ver); $vm->add($verif); $securelink = 'http://localhost/projet_BD-WEB/github_bd_web/?module=inscription&action=verif&id=' . urlencode($client2->getIdClient()) . '&code=' . urlencode($code); $msg = "<h2>LOCA-RENT</h2><br /><p>Bienvenue chez Loca-Rent,</p> pour continuer votre inscription merci de cliquez sur le lien ci-dessus<br /><a href=" . $securelink . ">" . $securelink . "</a>"; // Dans le cas où nos lignes comportent plus de 70 caractères, nous les coupons en utilisant wordwrap() //$msg = wordwrap($msg, 70, "\r\n"); // Pour envoyer un mail HTML, l'en-tête Content-type doit être défini $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; // En-têtes additionnels $headers .= 'To: ' . $clt['prenom'] . ' ' . $clt['nom'] . ' <' . $clt['mail'] . '>' . "\r\n"; $headers .= 'From: Loca-Rent <*****@*****.**>' . "\r\n"; mail($to, $subject, $msg, $headers); $this->site->ajouter_message("inscription reussie!{$code}"); Site::redirect("index"); } $this->site->ajouter_message("inscription pas reussie!\$"); Site::redirect("index"); } }
if (!empty($_POST['idClient'])) { $idClient = htmlentities($_POST['idClient']); $client = $clientManager->getClientById($idClient); $codeClient = $client->code(); } else { if (empty($_POST['idClient'])) { if (!empty($_POST['nom'])) { $nom = htmlentities($_POST['nom']); if ($clientManager->exists($nom)) { $_SESSION['client-add-error'] = "<strong>Erreur Création Client : </strong>Un client existe déjà avec ce nom : " . $nom . " ."; header('Location:../clients-add.php?idProjet=' . $idProjet); exit; } else { $cin = htmlentities($_POST['cin']); $adresse = htmlentities($_POST['adresse']); $telephone1 = htmlentities($_POST['telephone1']); $telephone2 = htmlentities($_POST['telephone2']); $email = htmlentities($_POST['email']); $codeClient = uniqid() . date('YmdHis'); $created = date('Y-m-d'); $client = new Client(array('nom' => $nom, 'cin' => $cin, 'adresse' => $adresse, 'telephone1' => $telephone1, 'telephone2' => $telephone2, 'email' => $email, 'code' => $codeClient, 'created' => $created)); $clientManager->add($client); } } else { $_SESSION['client-add-error'] = "<strong>Erreur Création Client : </strong>Vous devez remplir au moins le champ 'Nom'."; header('Location:../clients-add.php?idProjet=' . $idProjet); exit; } } } header('Location:../contrats-add.php?idProjet=' . $idProjet . '&codeClient=' . $codeClient);
<?php if (!isset($_POST['nom'])) { ?> <div class="container"> <div class="row"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <h1>Ajouter un client</h1> <form action="#" method="post"> <input type="text" name="nom" placeholder="Nom" required> <input type="text" name="prenom" placeholder="prenom" required> <input type="text" name="mail" placeholder="em@il" required> <input type="text" name="date" placeholder="DD/MM/YYYY" pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4}" required> <input type="text" name="idCompte" placeholder="ID compte" > <input type="text" name="login" placeholder="Login" required> <input type="password" name="pwd" value="Mot de passe" required> <input type="submit" value="Valider"> </form> </div> </div> </div> <?php } else { $clientData = array('nom' => $_POST['nom'], 'prenom' => $_POST['prenom'], 'mail' => $_POST['mail'], 'idCompte' => isset($_POST['idCompte']) ? $_POST['idCompte'] : null, 'date_naissance' => $_POST['date'], 'login' => $_POST['login'], 'pwd' => $_POST['pwd']); $client = new Client($clientData); $pdo = new Mypdo(); $manager = new ClientManager($pdo); $retour = $manager->add($client); var_dump($retour); }