コード例 #1
0
 /**
  * Tests if the information given by the user before creating a new user in the database is correct.
  **/
 public function controlInscription()
 {
     $accountView = new AccountView();
     if (empty($_POST['lastname']) || empty($_POST['firstname'])) {
         $accountView->showMessage("Veuillez renseigner tous les champs.");
         exit;
     }
     if (!empty($_POST['mail'])) {
         $accountModel = new AccountModel();
         $_POST["mail"] = htmlspecialchars($_POST["mail"]);
         $_POST["passe"] = htmlspecialchars($_POST["passe"]);
         $_POST["passe2"] = htmlspecialchars($_POST["passe2"]);
         if ($_POST["passe"] != $_POST["passe2"]) {
             $accountView->showMessage("Mot de passe non identique");
         } else {
             if (empty($_POST["passe"]) && empty($_POST["passe2"])) {
                 $accountView->showMessage("Veuillez renseigner les deux champs mot de passe");
             } else {
                 if ($userR = $accountModel->getUserEmail($_POST['mail'])) {
                     $accountView->showMessage("Adresse email existe déjà.");
                 } else {
                     if (preg_match('#[ÁÂÄàáâä@ÈÉÊËèéêë€ÌÍÎÏìíîïÒÓÔÖòóôöÙÚÛÜùúûüµŒœ]#', $_POST["firstname"]) != 0) {
                         $accountView->showMessage("Les caractères spéciaux sont interdits");
                     } else {
                         if (preg_match('#[ÁÂÄàáâä@ÈÉÊËèéêë€ÌÍÎÏìíîïÒÓÔÖòóôöÙÚÛÜùúûüµŒœ]#', $_POST["lastname"]) != 0) {
                             $accountView->showMessage("Les caractères spéciaux sont interdits");
                         } else {
                             //$_POST["passe"] = sha1($_POST["passe"]);
                             $userId = $accountModel->addUser($_POST["mail"], $_POST["firstname"], $_POST["lastname"], sha1($_POST["passe"]));
                             $_SESSION['infoUser'] = $accountModel->getUserById(intval($userId['user_id']));
                             $studentResult = $accountModel->getDataStudent('*', $_SESSION['infoUser']['user_id']);
                             $_SESSION['infoStudent'] = $studentResult;
                             $trainingResult = $accountModel->getTrainingInformationsForUser('*', $_SESSION['infoUser']['user_id']);
                             $_SESSION['infoTraining'] = $trainingResult;
                             $accountModel->sendEmail($_POST["mail"], $_POST["passe"]);
                         }
                     }
                 }
             }
         }
     } else {
         $accountView->showMessage("Veuillez remplir le champs adresse email.");
     }
 }
コード例 #2
0
/**
 * Connect the user if he's connected on twitter and if his mail adress is in the DB
 * @param $email string contains the user's mail adress
 * @param $picture string contains the picture path
 */
function addDataTwitter($email, $picture)
{
    $co = connect();
    $data = $co->query("SELECT * FROM Student WHERE student_instituteemail = '{$email}' OR student_personalemail = '{$email}'");
    $res = $data->fetch();
    if (count($res) != 0) {
        $accountModel = new AccountModel();
        $_SESSION['infoStudent'] = $res;
        $_SESSION['infoStudent']['student_avatar'] = $picture;
        $id = $res['user_id'];
        $idstu = $res['student_id'];
        $pourlasess = $co->query("SELECT * FROM User WHERE user_id = {$id}");
        $lesdonnees = $pourlasess->fetch();
        $_SESSION['infoUser'] = $lesdonnees;
        $_SESSION['image'] = $picture;
        $trainingResult = $accountModel->getTrainingInformationsForUser('description', $_SESSION['infoUser']['user_id']);
        $_SESSION['infoTraining'] = $trainingResult;
        //$co->query("UPDATE Student SET `student_avatar` = '$picture' WHERE `student_id` = $idstu");
        //print_r($co->errorInfo());
        //header('Location: index.php');
        echo '<script>document.location.href="index.php"</script>';
    } else {
        session_unset();
        header('Location: index.php?incrip=true');
    }
}