public function profilModif()
 {
     $manager = new ProfilManager();
     $manager2 = new WuserManager();
     $manager3 = new UserManager();
     if (isset($_POST)) {
         $id = $_POST['id'];
         $mail = $_POST['mail'];
         $telephone = $_POST['telephone'];
         $facebook = $_POST['facebook'];
         $twitter = $_POST['twitter'];
         $googleplus = $_POST['googleplus'];
         $linkedin = $_POST['linkedin'];
         $github = $_POST['github'];
         $profil = $manager->getUserProfil($id);
         if (empty($mail) || $manager3->getUserByUsernameOrEmail($mail) || !preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4}\$#", $mail)) {
             $mail = $profil['mail'];
         }
         if (empty($telephone)) {
             $telephone = $profil['telephone'];
         }
         if (empty($facebook)) {
             $facebook = $profil['facebook'];
         }
         if (empty($twitter)) {
             $twitter = $profil['twitter'];
         }
         if (empty($googleplus)) {
             $googleplus = $profil['googleplus'];
         }
         if (empty($linkedin)) {
             $linkedin = $profil['linkedin'];
         }
         if (empty($github)) {
             $github = $profil['github'];
         }
         $manager->setProfilModif($id, $telephone, $facebook, $twitter, $googleplus, $linkedin, $github);
         $manager2->setWuserModif($id, $mail);
         $this->redirectToRoute('profil', ['id' => $id]);
     }
 }
 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]);
 }