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()
 {
     $userManager = new UserManager();
     $authentificationManager = new AuthentificationManager();
     $last_name = "";
     $first_name = "";
     $username = "";
     $email = "";
     $password = "";
     $confirmPassword = "";
     $zip_code = "";
     for ($i = 75001; $i < 75021; $i++) {
         $zip[] = $i;
     }
     $address = "";
     $phone_number = "";
     $usernameError = "";
     $emailError = "";
     $zip_codeError = "";
     $passwordError = "";
     if (!empty($_POST)) {
         foreach ($_POST as $k => $v) {
             ${$k} = trim(strip_tags($v));
         }
         if (strlen($username) < 4) {
             $usernameError = "Pseudo trop court !";
         }
         if ($userManager->usernameExists($username)) {
             $usernameError = "Pseudo déjà utilisé !";
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $emailError = "Email non valide";
         }
         if ($userManager->emailExists($email)) {
             $emailError = "Email déjà utilisé !";
         }
         if (!in_array($zip_code, $zip)) {
             $zip_codeError = "Vous devez indiquer un code postal parisien !";
         }
         if ($password != $confirmPassword) {
             $passwordError = "le mot de passe ne correspond pas !";
         }
         if (empty($usernameError) && empty($emailError) && empty($zip_codeError) && empty($passwordError)) {
             $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
             $newUser = ['last_name' => $last_name, 'first_name' => $first_name, 'username' => $username, 'email' => $email, 'password' => $hashedPassword, 'zip_code' => $zip_code, 'address' => $address, 'phone_number' => $phone_number, 'role' => 'client', 'date_created' => date('Y-m-d H:i:s'), 'date_modified' => date('Y-m-d H:i:s')];
             $userManager->insert($newUser);
             $authentificationManager->logUserIn($user);
             if ($userManager) {
                 $this->redirectToRoute('catalog');
             }
         }
     }
     $data = ['last_name' => $last_name, 'first_name' => $first_name, 'username' => $username, 'email' => $email, 'zip_code' => $zip_code, 'address' => $address, 'phone_number' => $phone_number, 'usernameError' => $usernameError, 'emailError' => $emailError, 'passwordError' => $passwordError, 'zip_codeError' => $zip_codeError];
     $this->show('user/register', $data);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #5
0
 public function register()
 {
     $userManager = new UserManager();
     $authentificationManager = new AuthentificationManager();
     $last_name = "";
     $first_name = "";
     $username = "";
     $email = "";
     $password = "";
     $confirmPassword = "";
     $zip_code = "";
     for ($i = 75001; $i < 75021; $i++) {
         $zip[] = $i;
     }
     for ($i = 1; $i < 10; $i++) {
         $zip[] = '75 00' . $i;
     }
     for ($i = 10; $i < 21; $i++) {
         $zip[] = '75 0' . $i;
     }
     $address = "";
     $phone_number = "";
     $usernameError = "";
     $emailError = "";
     $zip_codeError = "";
     $passwordError = "";
     if (!empty($_POST)) {
         foreach ($_POST as $k => $v) {
             ${$k} = trim(strip_tags($v));
         }
         if (strlen($username) < 4) {
             $usernameError = "Pseudo trop court !";
         }
         if ($userManager->usernameExists($username)) {
             $usernameError = "Pseudo déjà utilisé !";
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $emailError = "Email non valide";
         }
         if ($userManager->emailExists($email)) {
             $emailError = "Email déjà utilisé !";
         }
         if (!in_array($zip_code, $zip)) {
             $zip_codeError = "Vous devez indiquer un code postal parisien !";
         }
         if ($password != $confirmPassword) {
             $passwordError = "le mot de passe ne correspond pas !";
         } else {
             if (strlen($password) < 6) {
                 $passwordError = "Veuillez saisir un mot de passe d'au moins 7 caractere !";
             } else {
                 $containsLetter = preg_match('/[a-zA-Z]/', $password);
                 $containsDigit = preg_match('/\\d/', $password);
                 $containsSpecial = preg_match('/[^a-zA-Z\\d]/', $password);
                 if (!$containsLetter || !$containsDigit || !$containsSpecial) {
                     $passwordError = "Veuillez choisir un mot de passe avec au moins une lettre, un chiffre, un caractere special !";
                 }
             }
         }
         if (empty($usernameError) && empty($emailError) && empty($zip_codeError) && empty($passwordError)) {
             $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
             // Recherche des coordonnées de l'utilisateur
             $googleAddress = urlencode($address . ", " . $zip_code . " Paris");
             $response = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=" . $googleAddress);
             $arrayResponse = json_decode($response, true);
             $lat = NULL;
             $lng = NULL;
             if (!empty($arrayResponse['results'][0])) {
                 $lat = $arrayResponse['results'][0]['geometry']['location']['lat'];
                 $lng = $arrayResponse['results'][0]['geometry']['location']['lng'];
             }
             $newUser = ['last_name' => $last_name, 'first_name' => $first_name, 'username' => $username, 'email' => $email, 'password' => $hashedPassword, 'zip_code' => $zip_code, 'address' => $address, 'lat' => $lat, 'lng' => $lng, 'phone_number' => $phone_number, 'role' => 'client', 'date_created' => date('Y-m-d H:i:s'), 'date_modified' => date('Y-m-d H:i:s')];
             $id = $userManager->insert($newUser);
             if (!empty($id)) {
                 $newUser['id'] = $id;
                 $authentificationManager->logUserIn($newUser);
                 $this->redirectToRoute('catalog');
             }
         }
     }
     $data = ['last_name' => $last_name, 'first_name' => $first_name, 'username' => $username, 'email' => $email, 'zip_code' => $zip_code, 'address' => $address, 'phone_number' => $phone_number, 'usernameError' => $usernameError, 'emailError' => $emailError, 'passwordError' => $passwordError, 'zip_codeError' => $zip_codeError];
     $this->show('user/register', $data);
 }
 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);
 }
 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');
 }
Beispiel #8
0
 public function register()
 {
     // $this->allowTo('admin');
     $user = $this->getUser();
     $UserManager = new UserManager();
     $error = [];
     $username = "";
     $email = "";
     $password = "";
     $password_confirm = "";
     $hashedPassword = "";
     $nom = "";
     $prenom = "";
     $code_postal = "";
     $adress = "";
     $tel = "";
     $code_postalRegexp = "/^[0-9]{5}\$/";
     $telRegexp = "/^[0-9]{10}\$/";
     // formulaire d'inscription -------------------------------------
     // if(!empty($_POST)){
     // 	foreach ($$_POST as $k => $v) {
     // 		// crée une variable $username, $email, $password, etc...
     // 		$$k = trim(strip_tags($v));
     // } ------------------------------------------------------------
     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']));
         $nom = trim(strip_tags($_POST['nom']));
         $prenom = trim(strip_tags($_POST['prenom']));
         $adress = trim(strip_tags($_POST['adress']));
         $code_postal = trim(strip_tags($_POST['code_postal']));
         $tel = trim(strip_tags($_POST['tel']));
         /* validation */
         if (empty($username)) {
             $error['username'] = "******";
         }
         // username assez long
         if (strlen($username) < 4) {
             $error['username'] = "******";
         }
         /*else{
         			$sql = "SELECT username FROM users WHERE username = :username";
         			$sth = $dbh->prepare($sql);
         			$sth -> execute(array(":username"=> $username));
         			$foundUsername = $sth->fetchColumn();
         			if ($foundUsername){
         				$error= "ce username existe déjà";
         			}
         		}*/
         // email
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error['email'] = "email non valide !";
         } elseif (strlen($email) > 250) {
             $error['email'] = "email trop long non valide !";
         }
         // mot de passe correspondent
         if ($password != $password_confirm) {
             $error['password'] = "******";
         } elseif (strlen($password) < 6) {
             $error['password'] = "******";
         }
         if (empty($nom)) {
             $error['nom'] = "Veuillez saisir votre nom !";
         }
         if (empty($prenom)) {
             $error['prenom'] = "Veuillez saisir votre prenom !";
         }
         if (empty($adress)) {
             $error['adress'] = "Veuillez saisir votre adress !";
         }
         if (empty($code_postal)) {
             $error['code_postal'] = "Veuillez saisir votre code postal!";
         } elseif (!preg_match($code_postalRegexp, $code_postal)) {
             $error['code_postal'] = "votre code postal doit correspondre à 5 chiffres";
         }
         if (empty($tel)) {
             $error['tel'] = "Veuillez saisir votre tel!";
         } elseif (!preg_match($telRegexp, $tel)) {
             $error['tel'] = "votre numero de tel doit correspondre à 10 chiffres";
         }
         /* fin de la validation */
         // si valide...
         if (empty($error)) {
             //}
             // hacher le mot de passe
             $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
             $newUser = ["username" => $username, "email" => $email, "password" => $hashedPassword, "nom" => $nom, "prenom" => $prenom, "code_postal" => $code_postal, "adress" => $adress, "tel" => $tel, "date_created" => date("Y-m-d H:i:s"), "date_modified" => date("Y-m-d H:i:s")];
             // debug($_POST);
             // die();
             //inseérrer en base
             $UserManager->insert($newUser);
         }
         //afficher bravo ou rediriger ou faire quelque
         //si invalide..
         //envoyer les erreurs et les données soumises à la vue
     }
     $dataToPassToTheView = ["username" => $username, "email" => $email, "password" => $password, "nom" => $nom, "prenom" => $prenom, "code_postal" => $code_postal, "adress" => $adress, "tel" => $tel, "errors" => $error];
     $this->show('temps/abonnement', $dataToPassToTheView);
     // $this->RedirectToRoute('abonnement');
 }
Beispiel #9
0
 public function Fakedata()
 {
     $userManager = new UserManager();
     $users = 1000;
     //paamayim nekutotayim
     $faker = \Faker\Factory::create("fr_FR");
     for ($i = 0; $i < $users; $i++) {
         $username = $faker->userName;
         $email = $faker->email;
         $lastname = $faker->firstname;
         $firstname = $faker->lastname;
         $phone_number = $faker->phoneNumber;
         $user_data = array($username, $email, $firstname, $lastname, $phone_number);
         $newData = ["username" => $username, "email" => $email, "firstname" => $firstname, "lastname" => $lastname, "phone_number" => $phone_number];
         $userManager->insert($newData);
         //print_r($user_data);
     }
     $time_end = microtime(true);
     //dividing with 60 will give the execution time in minutes other wise seconds
     $execution_time = $time_end - $time_start;
     //execution time of the script
     echo '<b>Total Execution Time:</b> ' . $execution_time . ' seconds';
     $this->show('user/fake_data');
 }