示例#1
0
 public function signup()
 {
     if (!empty($_POST)) {
         if (!empty($_POST["pseudo"]) && !empty($_POST["email"]) && !empty($_POST["password"]) && !empty($_POST["confirmPassword"])) {
             if ($_POST["password"] == $_POST["confirmPassword"]) {
                 $password = password_hash($_POST["password"], PASSWORD_DEFAULT);
                 // bien que pas en bleue, password_hash est une fonction native de PHP
                 $userManager = new UserManager();
                 // instencie une nouvelle class UserManager et ses fonctions définie W/Manager/UserManager.php
                 $reponse = ["res" => 0, "errors" => [], "url" => $this->generateUrl("toeteam")];
                 if ($userManager->emailExists($_POST["email"])) {
                     // si email déjà utilisé
                     $reponse["errors"]["email"] = "cet email existe déja";
                 } elseif ($userManager->usernameExists($_POST["pseudo"])) {
                     $reponse["errors"]["pseudo"] = "ce pseudo existe déja";
                 } else {
                     $userManager->insert(["user_pseudo" => $_POST["pseudo"], "user_mail" => $_POST["email"], "user_password" => $password]);
                     $reponse["res"] = 1;
                     // il n'y a pas d'erreur
                     // login direct
                     $userManager = new UserManager();
                     $user = $userManager->getUserByUsernameOrEmail($_POST["pseudo"]);
                     $auth = new AuthentificationManager();
                     $auth->logUserIn($user);
                 }
                 $this->showJson($reponse);
                 // renvoyer la réponse JSON
             }
         }
     }
 }
 public function register()
 {
     $this->allowTo('admin');
     $userManager = new UserManager();
     $error = "";
     $username = "";
     $email = "";
     //formulaire d'inscription soumis ?
     if (!empty($_POST)) {
         //ninja shit ?
         foreach ($_POST as $key => $value) {
             //créer une variable $username, $email, $password, etc...
             ${$key} = trim(strip_tags($value));
         }
         // //La boucle foreach revient à écrire v
         // $username    	 = trim(strip_tags($_POST['username']));
         // $email 			 = trim(strip_tags($_POST['email']));
         // $password 		 = trim(strip_tags($_POST['password']));
         // $password_confirm = trim(strip_tags($_POST['password_confirm']));
         /*Validadation*/
         //-----------------------------------------------------
         //username assez long ?
         if (strlen($username) < 4) {
             $error = "Votre pseudo est trop court";
         }
         //-----------------------------------------------------
         //pseudo déjà présent dans la bdd ?
         if ($userManager->usernameExists($username)) {
             $error = "Pseudo déjà utilisé !";
         }
         //-----------------------------------------------------
         //email déjà présent dans la bdd ?
         if ($userManager->emailExists($email)) {
             $error = "Email déjà existant !";
         } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error = "Email non valide";
         }
         //-----------------------------------------------------
         //mot de passe correspondent?
         if ($password != $password_confirm) {
             $error = "Les mots de passe ne correspondent pas !";
         }
         //-----------------------------------------------------
         /*Fin de validation*/
         //si valide ..
         if (empty($error)) {
             //hacher le mot de passe
             $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
             $newAdmin = ["username" => $username, "email" => $email, "password" => $hashedPassword, "role" => "admin", "dateCreated" => date("Y-m-d H:i:s"), "dateModified" => date("Y-m-d H:i:s")];
             //insérer en base
             $userManager->insert($newAdmin);
         }
     }
     //afficher bravo ou rediriger ou faire quelque chose de bien
     // si invalide..
     //envoyer les erreurs et les données soumises à la vue
     $dataToPassToTheView = ["username" => $username, "email" => $email, "error" => $error];
     $this->show('user/register_administrator', $dataToPassToTheView);
 }
示例#3
0
 public function register()
 {
     $userManager = new UserManager();
     $error = "";
     $username = "";
     $email = "";
     //formulaire d'inscription soumis ?
     if (!empty($_POST)) {
         $username = trim(strip_tags($_POST['username']));
         $email = trim(strip_tags($_POST['email']));
         $password = trim(strip_tags($_POST['password']));
         $password_confirm = trim(strip_tags($_POST['password_confirm']));
         /* validation */
         //username assez long
         if (strlen($username) < 4) {
             $error = "Pseudo trop court";
         }
         //username déjà présent ?
         if ($userManager->usernameExists($username)) {
             $error = "Pseudo déjà utilisé !";
         }
         //email valide
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error = "Email non valide !";
         }
         //email déjà présent ?
         if ($userManager->emailExists($email)) {
             $error = "Email déjà utilisé !";
         }
         //mots de passe correspondent ?
         if ($password != $password_confirm) {
             $error = "Les mots de passe ne correspondent pas !";
         }
         /* fin validation */
         //si valide...
         if (empty($error)) {
             //hacher le mot de passe
             $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
             $newAdmin = ["username" => $username, "email" => $email, "password" => $hashedPassword, "role" => "admin", "dateCreated" => date("Y-m-d H:i:s"), "dateModified" => date("Y-m-d H:i:s")];
             //insérer en base
             $userManager->insert($newAdmin);
             //afficher bravo ou rediriger ou faire quelque chose de bien
         }
         //si invalide...
         //envoyer les erreurs et les données soumises à la vue
     }
     $dataToPassToTheView = ["error" => $error, "username" => $username, "email" => $email];
     $this->show('user/register_administrator', $dataToPassToTheView);
 }
示例#4
0
 public function register()
 {
     $this->allowTo('admin');
     $userManager = new UserManager();
     $error = "";
     $username = "";
     $email = "";
     if (!empty($_POST)) {
         foreach ($_POST as $k => $v) {
             ${$k} = trim(strip_tags($v));
         }
         // $username = trim(strip_tags($_POST['username']));
         // $email = trim(strip_tags($_POST['email']));
         // $password = trim(strip_tags($_POST['password']));
         // $confirmPassword = trim(strip_tags($_POST['confirmPassword']));
         if (strlen($username) < 4) {
             $error = 'Identifiant trop court !';
         }
         if ($userManager->usernameExists($username)) {
             $error = "Pseudo déjà utilisé !";
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error = "Email non valide !";
         }
         if ($userManager->emailExists($email)) {
             $error = "Email déjà utilisé !";
         }
         //mots de passe correspondent
         if ($password != $confirmPassword) {
             $error = "les mots de passe ne corresponds pas!";
         }
         //si valide
         if (empty($error)) {
             $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
             $newAdmin = ["username" => $username, "email" => $email, "password" => $hashedPassword, "role" => "admin", "dateCreated" => date("Y-m-d H:i:s"), "dateModified" => date("Y-m-d H:i:s")];
             //inserer en base
             $userManager->insert($newAdmin);
         }
     }
     $dataToPassToTheView = ["error" => $error, "username" => $username, "email" => $email];
     $this->show('users/register_administrator', $dataToPassToTheView);
 }
示例#5
0
 public function forgotPassword()
 {
     $userManager = new UserManager();
     $email = "";
     $errorEmail = "";
     if (!empty($_POST)) {
         $string = new StringUtils();
         $token = $string->randomString();
         $hashedToken = password_hash($token, PASSWORD_DEFAULT);
         $email = trim(strip_tags($_POST['email']));
         if ($userManager->emailExists($email)) {
             $user = $userManager->getUserByUsernameOrEmail($email);
             $username = $user['username'];
             $userManager->update(array("token" => $hashedToken), $user['id']);
             $mail = new \PHPMailer();
             $mail->isSMTP();
             $mail->setLanguage('fr');
             $mail->CharSet = 'UTF-8';
             $mail->SMTPDebug = 2;
             //0 pour désactiver les infos de débug
             $mail->Debugoutput = 'html';
             $mail->Host = 'smtp.gmail.com';
             $mail->Port = 587;
             $mail->SMTPSecure = 'tls';
             $mail->SMTPAuth = true;
             $mail->Username = "******";
             $mail->Password = "******";
             $mail->setFrom('*****@*****.**', 'Service de Messagerie BDloc');
             $mail->addAddress($user['email']);
             $mail->isHTML(true);
             $mail->Subject = 'Changement de mot de passe';
             $mail->Body = '<a href="www.bdloc.dev/change_password/?token=' . $token . '&username='******'">Cliquer ici pour créer un nouveau mot de passe</a>';
             if (!$mail->send()) {
                 echo "Mailer Error: " . $mail->ErrorInfo;
             } else {
                 echo "Message sent!";
             }
             $this->redirectToRoute('login');
         } else {
             $errorEmail = "Email non valide !";
         }
     }
     $data['errorEmail'] = $errorEmail;
     $this->show('user/forgot_Password', $data);
 }
示例#6
0
 public function register()
 {
     $this->allowTo('admin');
     $userManager = new UserManager();
     $usernameError = "";
     $emailError = "";
     $passwordError = "";
     if (!empty($_POST)) {
         foreach ($_POST as $k => $v) {
             ${$k} = trim(strip_tags($v));
         }
         // validation
         // username assez long
         if (empty($username)) {
             $usernameError = "Veuillez indiquer un pseudo !";
         } else {
             if (strlen($username) < 4) {
                 $usernameError = "Nom d'utilisateur trop court !";
             } else {
                 if ($userManager->usernameExists($username)) {
                     $usernameError = "Ce pseudo est déjà utilisé !";
                 }
             }
         }
         // email valide
         if (empty($email)) {
             $emailError = "Veuillez entrer une adresse email !";
         } else {
             if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                 $emailError = "L'adresse email n'est pas valide";
             } else {
                 if ($userManager->emailExists($email)) {
                     $emailError = "Cet adresse email est déjà utilisée !";
                 }
             }
         }
         // mot de passe valide
         if (empty($password)) {
             $passwordError = "Veuillez entrer un mot de passe !";
         } else {
             if (strlen($password) <= 6) {
                 $passwordError = "Veuillez entrer un mot de passe d'au moins 7 caractères !";
             }
         }
         // mots de passe correspondent ?
         if ($password != $password_again) {
             $passwordError = "Les mots de passe que vous avez indiqué ne correspondent pas !";
         }
         // si valide ...
         if ($usernameError == "" && $emailError == "" && $passwordError == "") {
             // hacher le mot de passe
             $password_hashed = password_hash($password, PASSWORD_DEFAULT);
             $newAdmin = ['username' => $username, 'email' => $email, 'password' => $password_hashed, 'role' => 'admin', 'date_created' => date('Y-m-d H:i:s'), 'date_modified' => date('Y-m-d H:i:s')];
             // insérer en bdd
             $insertSuccess = $userManager->insert($newAdmin);
             // afficher bravo ou rediriger
             if ($insertSuccess) {
                 $this->redirectToRoute('show_all_terms');
             }
         } else {
             // envoyer les erreurs et les données soumises à la vue
             $dataToPassToTheView = ['username' => $username, 'email' => $email, 'usernameError' => $usernameError, 'emailError' => $emailError, 'passwordError' => $passwordError];
             $this->show('user/register_administrator', $dataToPassToTheView);
         }
     }
     $this->show('user/register_administrator');
 }
示例#7
0
 public function editProfile()
 {
     $userManager = new UserManager();
     $authentificationManager = new AuthentificationManager();
     $last_name = "";
     $first_name = "";
     $username = "";
     $email = "";
     $zip_code = "";
     for ($i = 75001; $i < 75021; $i++) {
         $zip[] = $i;
     }
     $address = "";
     $phone_number = "";
     $usernameError = "";
     $emailError = "";
     $zip_codeError = "";
     if (!empty($_POST)) {
         foreach ($_POST as $k => $v) {
             ${$k} = trim(strip_tags($v));
         }
         // Validation des données
         if (strlen($username) < 4) {
             $usernameError = "Pseudo trop court !";
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $emailError = "Email non valide";
         }
         if (!in_array($zip_code, $zip)) {
             $zip_codeError = "Vous devez indiquer un code postal parisien !";
         }
         if (empty($usernameError) && empty($emailError) && empty($zip_codeError)) {
             // Si l'utilisateur décide de changer de username
             if ($username != $_SESSION['user']['username']) {
                 // S'assurer que le nouveau username n'est pas déjà utilisé
                 if ($userManager->usernameExists($username)) {
                     $usernameError = "Pseudo déjà utilisé !";
                 }
             }
             // Si l'utilisateur décide de changer d'email
             if ($email != $_SESSION['user']['email']) {
                 // S'assurer que le nouvel email n'est pas déjà utilisé
                 if ($userManager->emailExists($email)) {
                     $emailError = "Email déjà utilisé !";
                 }
             }
             $newUser = ['last_name' => $last_name, 'first_name' => $first_name, 'username' => $username, 'email' => $email, 'zip_code' => $zip_code, 'address' => $address, 'phone_number' => $phone_number, 'date_modified' => date('Y-m-d H:i:s')];
             if ($userManager->update($newUser, $_SESSION['user']['id'])) {
                 $refreshUser = $userManager->find($_SESSION['user']['id']);
                 $_SESSION['user'] = $refreshUser;
             }
         }
     }
     $data = ['usernameError' => $usernameError, 'emailError' => $emailError, 'zip_codeError' => $zip_codeError];
     $this->show('user/edit_profile', $data);
 }
示例#8
0
 public function register()
 {
     $am = new AuthentificationManager();
     $userManager = new UserManager();
     $error = "";
     $username = "";
     $email = "";
     $firstname = "";
     $lastname = "";
     $streetname = "";
     $phonenumber = "";
     $zipcode = "";
     $pic_name = "default.png";
     $user_name_regex = "/^[\\p{L}0-9._-]{2,100}\$/u";
     $adresse_regex = "^([\\d\\/-]*[\\h]?(bis|ter)?)[\\h]*([\\D]{3}.*)\$";
     if (!empty($_POST)) {
         $email = trim(strip_tags($_POST['email']));
         $username = trim(strip_tags($_POST['username']));
         $password = trim(strip_tags($_POST['password']));
         $confirm = trim(strip_tags($_POST['confirm']));
         $firstname = trim(strip_tags($_POST['firstname']));
         $lastname = trim(strip_tags($_POST['lastname']));
         $streetname = trim(strip_tags($_POST['streetname']));
         $zipcode = trim(strip_tags($_POST['zipcode']));
         $phonenumber = trim(strip_tags($_POST['phonenumber']));
         // username valide ?
         if (strlen($username) < 4) {
             $error = "Votre Pseudo doit comporter 4 lettres minimum !";
         }
         if (!preg_match($user_name_regex, $username)) {
             $error = "Votre Pseudo ne doit pas contenir de caractère spéciaux !";
         }
         if ($userManager->usernameExists($username)) {
             $error = "Ce Pseudo est deja utillisé !";
         }
         // Email valide ?
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error = "Email non valide";
         }
         if ($userManager->emailExists($email)) {
             $error = "Cet Email est deja utillisé !";
         }
         // Adresse valide FAIL
         //if (!preg_match($adresse_regex, $streetname)) {
         //	$error = "Votre adresse n'es pas valide !";
         //}
         // ZIPCODE valide
         if ($zipcode <= "75000" || $zipcode >= "75021") {
             $error = "Vous devez habiter Paris pour vous inscrire à notre service !";
         }
         // Téléphone valide
         if (preg_match("/^[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}\$/", $phonenumber)) {
             // $phonenumber is valid
             $error = "Votre numéro de téléphone n'est pas valide !";
         }
         //	2er cihffre du Telephone coresponde a 01,02,03,04,05,06,07,08 ou 09
         if (substr($phonenumber, 0, 2) < "01" || substr($phonenumber, 0, 2) > "09") {
             $error = "Votre numéro de téléphone n'est pas valide !";
         } else {
             $containsLetter = preg_match('/[a-zA-Z]/', $password);
             $containsDigit = preg_match('/\\d/', $password);
             if (!$containsLetter || !$containsDigit) {
                 $error = "Merci de choisir un mot de passe comportant au moins une lettre et un chiffre !";
             }
         }
         // Password identiques ?
         if ($password != $confirm) {
             $error = "Vos mots de passe doivent être identiques !";
         }
         //si valide...
         if (empty($error)) {
             //hasher le mot de passe
             $hash = password_hash($password, PASSWORD_DEFAULT);
             //insérer en base
             $newSubscriber = ["username" => $username, "email" => $email, "password" => $hash, "firstname" => $firstname, "lastname" => $lastname, "zip_code" => $zipcode, "street_name" => $streetname, "phone_number" => $phonenumber, "date_modified" => date("Y-m-d H:i:s"), "date_created" => date("Y-m-d H:i:s"), "pic_name" => $pic_name];
             $userManager = new \Manager\UserManager();
             $userManager->insert($newSubscriber);
             $am->LogUserIn($newSubscriber);
             $user = $this->getUser();
             $this->redirectToRoute('catalogue');
         }
     }
     /* Afficher la page */
     $data = [];
     $data['error'] = $error;
     $data['username'] = $username;
     $data['email'] = $email;
     $data['firstname'] = $firstname;
     $data['lastname'] = $lastname;
     $data['zipcode'] = $zipcode;
     $data['streetname'] = $streetname;
     $data['phonenumber'] = $phonenumber;
     $data['pic_name'] = $pic_name;
     $this->show('user/register', $data);
 }