예제 #1
0
 public function restitution_mdp($tab)
 {
     if ($tab['categ'] == 'infirmier') {
         $statement = 'SELECT * FROM INFIRMIER WHERE EMAIL=:email';
     } elseif ($tab['categ'] == 'admin') {
         $statement = 'SELECT * FROM ADMIN WHERE EMAIL=:email';
     } elseif ($tab['categ'] == 'patient') {
         $statement = 'SELECT * FROM PATIENT WHERE EMAIL=:email';
     } else {
         return false;
         //si le type n'est pas correct on renvoit faux
     }
     $sth = $this->connexion->prepare($statement);
     $sth->bindParam(':email', $tab['email'], PDO::PARAM_STR);
     if ($sth->execute() && $sth->rowCount() > 0) {
         $user = $sth->fetchObject();
         $statement = 'INSERT INTO JETON (LIEN) VALUES("lien_a_inserer")';
         $sth = $this->connexion->prepare($statement);
         if ($sth->execute() && $sth->rowCount() > 0) {
             $idjeton = $this->connexion->lastInsertId();
             $date = new DateTime();
             $date->setTimestamp(time());
             $datetime = $date->format('Y-m-d H:i:s');
             $jeton = 'utype=' . $tab['categ'] . '&user='******'&jeton=' . $idjeton . '&date=' . $datetime;
             $jeton_crypte = Cryptage::mc_encrypt($jeton);
             $lien = 'http://' . $_SERVER['HTTP_HOST'] . '/Liemie/restitution_mdp.php?jeton=' . $jeton_crypte;
             $hash_jeton = md5($user->EMAIL . '' . $idjeton . '' . $tab['categ'] . '' . $datetime);
             $statement = 'UPDATE JETON SET LIEN=:lien, DATE_JETON=:date WHERE ID_JETON=:idjeton';
             $sth = $this->connexion->prepare($statement);
             $sth->bindParam(':idjeton', $idjeton, PDO::PARAM_INT);
             $sth->bindParam(':lien', $hash_jeton, PDO::PARAM_STR);
             $sth->bindParam(':date', $datetime, PDO::PARAM_STR);
             if ($sth->execute() && $sth->rowCount() > 0) {
                 $corps = 'Pour récupérer votre mot de passe, veuillez suivre le lien suivant : <a href="' . $lien . '">Réinitialiser le mot de passe</a> !';
                 $unmail = new MyMailer('*****@*****.**', $user->EMAIL, 'Kaliémie : Récupération de votre mot de passe.', $corps, '*****@*****.**', 'siocarcouet', 'ssl://smtp.gmail.com', 465);
                 if ($unmail->envoyerMail()) {
                     return true;
                 } else {
                     //echo $unmail->getErreur();
                 }
             }
         }
     }
     return false;
 }