Пример #1
0
 public function loginAction()
 {
     $rubriqueModel = new RubriqueModel();
     $listeRubrique = $rubriqueModel->fetchAll();
     $this->layout()->setVariable('listeRubrique', $listeRubrique);
     $this->layout()->setVariable('menu_id', 'admin');
     $langue = $this->getEvent()->getRouteMatch()->getParam('langue');
     $this->layout()->setVariable('langue', $langue);
     $form = new AdminForm();
     //formulaire de connexion
     $adminModel = new AdminModel();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $admin = new Admin();
         $form->setInputFilter($admin->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $admin->exchangeArray($form->getData());
             //filtrage des données récupérées
             $admin->login = filter_var($admin->login, FILTER_SANITIZE_STRING);
             $admin->password = filter_var($admin->password, FILTER_SANITIZE_STRING);
             $token = $adminModel->verifyUser($admin->login, $admin->password);
             //if code 200
             $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue));
             /*return $this->forward()->dispatch('Rubrique\Controller\Admin', array(
                   'action' => 'index',
                   'token'   => $token,
               ));*/
         }
     }
     return new ViewModel(array('form' => $form, 'listeRubrique' => $listeRubrique, 'langue' => $langue));
 }
Пример #2
0
 public function loginAction()
 {
     $langue = $this->getEvent()->getRouteMatch()->getParam('langue');
     $token = VerifUser::tokenAction();
     if ($token != null) {
         $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue));
     }
     $listeRubrique = SendLayout::fetchAllRubriques($this, 'login', $langue, $token);
     $form = new AdminForm();
     //formulaire de connexion
     $adminModel = new AdminModel();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $admin = new Admin();
         $form->setInputFilter($admin->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $admin->exchangeArray($form->getData());
             try {
                 $token = $adminModel->verifyUser($admin->login, $admin->password);
             } catch (\Exception $e) {
                 $token = null;
                 SendLayout::sendGeneral($this, $listeRubrique, 'login', $langue, $token);
                 return new ViewModel(array('form' => $form, 'listeRubrique' => $listeRubrique, 'langue' => $this->getEvent()->getRouteMatch()->getParam('langue'), 'exception' => $e->getMessage()));
             }
             $session = new Container('user');
             $session->token = $token;
             //Redirection vers l'interface d'administration
             $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue));
             //echo $token;
         }
     }
     SendLayout::sendGeneral($this, $listeRubrique, 'login', $langue, $token);
     return new ViewModel(array('form' => $form, 'listeRubrique' => $listeRubrique, 'langue' => $langue));
 }