public function httpPostMethod(Http $http, array $formFields)
 {
     /*
      * Méthode appelée en cas de requête HTTP POST
      *
      * L'argument $http est un objet permettant de faire des redirections etc.
      * L'argument $formFields contient l'équivalent de $_POST en PHP natif.
      */
     try {
         $Customer = new CustomerModel();
         $verifEmail = $Customer->sameMail($formFields['Email']);
         if ($verifEmail && ctype_digit($formFields['Year']) && ctype_digit($formFields['Month']) && ctype_digit($formFields['Day']) && ctype_digit($formFields['Phone']) && strlen($formFields['Phone']) === 10 && ctype_digit($formFields['ZipCode']) && strlen($formFields['ZipCode']) === 5 && isset($formFields['password']) && $formFields['password2'] == $formFields['password'] && isset($formFields['Email']) && filter_var($formFields['Email'], FILTER_VALIDATE_EMAIL) != false) {
             $Birthdate = $formFields['Year'] . '-' . $formFields['Month'] . '-' . $formFields['Day'];
             //var_dump($Birthdate);
             $Customer_id = $Customer->registerCustomer($formFields['FirstName'], $formFields['LastName'], $Birthdate, $formFields['Phone'], $formFields['Address'], $formFields['Address2'], $formFields['City'], $formFields['ZipCode'], $formFields['Email'], $formFields['password']);
             //var_dump($Customer_id);
             $user = $Customer->findCustomer($Customer_id);
             $UserSession = new UserSession();
             $UserSession->create($user);
             $http->redirectTo('');
         } else {
             $http->redirectTo('Exception?Error=3');
         }
     } catch (DomainException $event) {
         $form = new RegisterForm();
         $form->bind($formFields);
         $form->setErrorMessage($event->getMessage());
         return ['_form' => $form];
     }
 }
 public function httpPostMethod(Http $http, array $formFields)
 {
     /*
      * Méthode appelée en cas de requête HTTP POST
      *
      * L'argument $http est un objet permettant de faire des redirections etc.
      * L'argument $formFields contient l'équivalent de $_POST en PHP natif.
      */
     $Customer = new CustomerModel();
     $verifEmail = $Customer->sameMail($formFields['Email']);
     //var_dump(strlen($_POST['Phone']));
     //var_dump(strlen($_POST['ZipCode']));
     if ($verifEmail['result'] === '0' && ctype_digit($formFields['Year']) && ctype_digit($formFields['Month']) && ctype_digit($formFields['Day']) && ctype_digit($formFields['Phone']) && strlen($formFields['Phone']) === 10 && ctype_digit($formFields['ZipCode']) && strlen($formFields['ZipCode']) === 5 && isset($formFields['password']) && isset($formFields['Email']) && filter_var($formFields['Email'], FILTER_VALIDATE_EMAIL) != false) {
         $password = password_hash($formFields['password'], PASSWORD_DEFAULT);
         //var_dump($password);
         $Birthdate = $formFields['Year'] . '-' . $formFields['Month'] . '-' . $formFields['Day'];
         //var_dump($Birthdate);
         $Customer_id = $Customer->registerCustomer($formFields['FirstName'], $formFields['LastName'], $Birthdate, $formFields['Phone'], $formFields['Address'], $formFields['Address2'], $formFields['City'], $formFields['ZipCode'], $formFields['Email'], $formFields['password']);
         //var_dump($Customer_id);
         $user = $Customer->findCustomer($Customer_id);
         $UserSession = new UserSession();
         $UserSession->create($user);
         $http->redirectTo('');
     } elseif ($verifEmail != '0') {
         $http->redirectTo('Exception?Error=3');
     }
 }
 public function httpPostMethod(Http $http, array $formFields)
 {
     if (filter_var($formFields['Login'], FILTER_VALIDATE_EMAIL) != false) {
         $CustomerModel = new CustomerModel();
         $user_id = $CustomerModel->findWithCredentials($formFields['Login'], $formFields['Password']);
         //var_dump($user_id);
         if (ctype_digit($user_id)) {
             $user = $CustomerModel->findCustomer($user_id);
             $UserSession = new UserSession();
             $UserSession->create($user);
             $http->redirectTo('/');
         } else {
             $http->redirectTo('Exception?' . $user_id);
         }
     } else {
         $http->redirectTo('Exception?Error=4');
     }
 }
 public function httpPostMethod(Http $http, array $formFields)
 {
     if (filter_var($formFields['Login'], FILTER_VALIDATE_EMAIL) != false) {
         try {
             $userSession = new UserSession();
             $CustomerModel = new CustomerModel();
             $user_id = $CustomerModel->findWithCredentials($formFields['Login'], $formFields['Password'], $_SERVER['REMOTE_ADDR']);
             if (ctype_digit($user_id)) {
                 $user = $CustomerModel->findCustomer($user_id);
                 $userSession->create($user);
                 $http->redirectTo('/');
             }
         } catch (DomainException $event) {
             //var_dump($event);
             $form = new LoginForm();
             $form->bind($formFields);
             $form->setErrorMessage($event->getMessage());
             return ['_form' => $form];
             //AVEC CONTROLEUR EXECPTION --- $http->redirectTo('Exception?'.$user_id);
         }
     } else {
         $http->redirectTo('Exception?Error=4');
     }
 }
Exemple #5
0
 /**
  * @return User
  */
 public static function connect($username, $remember)
 {
     if (User::find_by_username($username)) {
         $sessid = md5(uniqid());
         $expiration = $remember ? Utils::tps() + 365 * 86400 : Utils::tps() + 24 * 3600;
         $user = User::find_by_username($username);
         UserSession::create(array('user_id' => $user->id, 'session_id' => $sessid, 'expiration' => $expiration, 'remember' => $remember));
         setcookie('SESSID', $sessid, $expiration);
         return $user;
     }
 }