Ejemplo n.º 1
0
 public function orderBy($orderby)
 {
     $manager = new QuestionManager();
     $manager2 = new TagManager();
     $manager3 = new ProfilManager();
     $questions = $manager->getAllQuestions($orderby);
     $tags = array();
     foreach ($questions as $value) {
         $tags[] = $manager2->getTags($value['id']);
     }
     $profils = $manager3->getAllUsers();
     $this->show('default/home', ['questions' => $questions, 'tags' => $tags, 'profils' => $profils, 'orderby' => $orderby]);
 }
Ejemplo n.º 2
0
 public function register()
 {
     $errors = array();
     $flag = 0;
     //debug($_POST);
     if (isset($_POST['registerform'])) {
         //debug($_POST['registerform']);
         // indication du role par défaut de l'utilisateur
         $_POST['myform']['role'] = 'user';
         //nom
         $nom = $_POST['nom'];
         //prénom
         $prenom = $_POST['prenom'];
         // Hashage du mot de passe
         $_POST['myform']['mdp'] = password_hash($_POST['myform']['mdp'], PASSWORD_DEFAULT);
         $manager = new UserManager();
         $manager2 = new ProfilManager();
         $manager3 = new WuserManager();
         $manager4 = new TagManager();
         $manager5 = new Wusers_tagManager();
         // Si le mail et sa confirmation sont différents
         if ($_POST['myform']['mail'] != $_POST['remail']) {
             $errors[] = 'Les adresses mail entrées sont différentes.';
         } else {
             // Si l'adresse mail existe en bdd
             if ($manager->getUserByUsernameOrEmail($_POST['myform']['mail'])) {
                 $errors[] = '<br />Cette adresse mail est déjà utilisée, veuillez en choisir une autre ou vous connecter à ce compte.';
             } else {
                 if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4}\$#", $_POST['myform']['mail'])) {
                     $errors[] = '<br />L\'adresse mail ne respecte pas les critères de validité.';
                 } else {
                     $_POST['myform']['mail'];
                 }
             }
         }
         //mail
         // Si le mot de passe fait moins de 8 caractères
         // A FAIRE
         // Si le mot de passe et sa confirmation sont diférents
         if ($_POST['myform']['mdp'] != password_verify($_POST['remdp'], $_POST['myform']['mdp'])) {
             $errors[] = 'Les mots de passe entrés sont différents.';
         }
         //mdp
         // Création du token pour validation du compte par mail
         $token = md5(uniqid($_POST['myform']['pseudo'], true));
         if (count($errors) === 0) {
             // error = 0 = insertion user
             //$this->redirectToRoute('login');
             try {
                 $manager->insert($_POST['myform']);
                 $manager2->insertUserData($_POST['myform']['mail'], $nom, $prenom, $token);
                 //debug('compte en bdd');
                 $flag = 1;
                 $wuser_id = $manager3->getWuserId($_POST['myform']['mail']);
                 // debug($wuser_id);
                 $tags = $manager4->getAllTags();
                 $manager5->setWusersTags($wuser_id, $tags);
                 $this->show('default/home', ['flag' => $flag]);
             } catch (Exception $e) {
                 $this->show('default/home', ['errors' => $errors->getMessage()]);
             }
         } else {
             $this->show('default/home', ['errors' => $errors], ['flag' => $flag]);
         }
     }
     $this->show('default/home', ['flag' => $flag]);
 }