* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once '../../model/class/User.php'; require_once '../../model/DAL/UserDAL.php'; //Création de l'user à insèrer $user = new User(); //Vérifie ce qui est renvoyer par le POST de /view/phtml/user_create.php //et set de l'objet user u fur et à mesure $validLastName = filter_input(INPUT_POST, 'lastName', FILTER_SANITIZE_STRING); $user->setNom($validLastName); $validFisrtName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_STRING); $user->setPrenom($validFisrtName); $myregex = "~^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}\$~"; $validBirthDate = filter_input(INPUT_POST, 'birthDate', FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => $myregex))); $user->setDateNaissance($validBirthDate); $validAddress = filter_input(INPUT_POST, 'address', FILTER_SANITIZE_STRING); $user->setAdresse($validAddress); $validEmail = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING); $user->setMail($validEmail); $validUserTypeId = filter_input(INPUT_POST, 'userType', FILTER_SANITIZE_NUMBER_INT); $user->setType($validUserTypeId); //Insertion de l'user dans la table $validInsertion = UserDAL::insertOnDuplicate($user); if ($validInsertion != null) { echo "Insertion OK";
function index() { $isValid = False; $this->jsutils->getAndBindTo('.editMdp', 'click', 'cUser/editMdp', '.editionMdp'); $this->jsutils->compile(); $this->load->helper('text'); $this->load->helper('security'); //appel formulaire $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); //Regle de validation //appel de l'object if (isset($_POST['idUser']) && !empty($_POST['idUser'])) { //echo "id user : "******"<br>"; $id = $_POST['idUser']; $object = $this->doctrine->em->find('user', $id); $isValid = True; } else { $object = new User(); $isValid = True; } if (isset($_POST['type']) && !empty($_POST['type']) && $isValid == True) { //echo "type : ".$_POST['type']."<br>"; $idUser = $_POST['type']; $this->form_validation->set_rules('type', 'Type du texte', 'trim'); $type = $this->doctrine->em->find('usertype', $_POST['type']); $object->setIdtype($type); $isValid = True; } if (isset($_POST['nom']) && !empty($_POST['nom']) && $isValid == True) { //echo "titre : ".$_POST['nom']."<br>"; $this->form_validation->set_rules('nom', 'Nom de l\'utlisateur', 'trim|xss_clean'); $object->setNom(utf8_decode($_POST['nom'])); $isValid = True; } if (isset($_POST['prenom']) && !empty($_POST['prenom']) && $isValid == True) { //echo "texte : ".$_POST['prenom']."<br>"; $this->form_validation->set_rules('prenom', 'Prenom de l\'utlisateur', 'trim|xss_clean'); $object->setPrenom(utf8_decode($_POST['prenom'])); $isValid = True; } if (isset($_POST['email']) && !empty($_POST['email']) && $isValid == True) { //echo "texte : ".$_POST['email']."<br>"; $this->form_validation->set_rules('email', 'Email de l\'utlisateur', 'trim|xss_clean'); $object->setMail($_POST['email']); $isValid = True; } if (isset($_POST['mdp1']) && !empty($_POST['mdp1'])) { //echo "texte : ".$_POST['mdp1']."<br>"; $this->form_validation->set_rules('mdp1', 'Email de l\'utlisateur', 'trim|xss_clean'); $isValid = True; } if (isset($_POST['mdp2']) && !empty($_POST['mdp2']) && $isValid == True) { if ($_POST['mdp1'] == $_POST['mdp2']) { //echo "texte : ".$_POST['mdp2']."<br>"; $this->form_validation->set_rules('mdp2', 'Email de l\'utlisateur', 'trim|xss_clean'); $mdps = $this->doctrine->em->getRepository('mdpSalt')->findAll(); foreach ($mdps as $mdp) { $selR = $mdp->getSaltr(); $selL = $mdp->getSaltl(); } $mdpComplet = $selR . sha1($_POST['mdp2']) . $selL; $object->setMdp($mdpComplet); $isValid = True; } else { $isValid = False; $msgMdp = "Les deux Mots de Passe ne sont pas identique"; } } if ($this->form_validation->run() == FALSE) { //echo 'test false'; $titre = "Utilisateur"; $this->layout->set_titre($titre); $this->layout->th_default(); if (isset($id)) { $object = $this->doctrine->em->find('user', $id); $this->load->view('user/vEdit', array('user' => $object)); } else { $this->load->view('user/vAdd'); } } else { if ($isValid == true) { //echo 'test true'; $this->doctrine->em->persist($object); $this->doctrine->em->flush(); redirect('cUser', 'refresh'); } else { $titre = "Utilisateur"; $this->layout->set_titre($titre); $this->layout->th_default(); if (isset($id)) { $object = $this->doctrine->em->find('user', $id); $this->load->view('user/vEdit', array('user' => $object, 'msgMdp' => $msgMdp)); } else { $this->load->view('user/vAdd', array('msgMdp' => $msgMdp)); } } } }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ require_once '../../model/class/User.php'; require_once '../../model/DAL/UserDAL.php'; require_once '../../model/class/Module.php'; require_once '../../model/DAL/ModuleDAL.php'; //Création de l'user à insèrer $student = new User(); //Vérifie ce qui est renvoyer par le POST de /view/phtml/user_create.php //et set de l'objet user u fur et à mesure $validLastName = filter_input(INPUT_POST, 'lastName', FILTER_SANITIZE_STRING); $student->setNom($validLastName); $validFisrtName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_STRING); $student->setPrenom($validFisrtName); $myregex = "~^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}\$~"; $validBirthDate = filter_input(INPUT_POST, 'birthDate', FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => $myregex))); $student->setDateNaissance($validBirthDate); $validAddress = filter_input(INPUT_POST, 'address', FILTER_SANITIZE_STRING); $student->setAdresse($validAddress); $validEmail = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING); $student->setMail($validEmail); $student->setType(4); //place l'user type à 4 (correspond à l'id de student) //Insertion du student dans la table user $validInsertion = UserDAL::insertOnDuplicate($student); if ($validInsertion != null) { echo "Insertion Etudiant OK";
public function setNom($nom) { $this->__load(); return parent::setNom($nom); }