public function indexAction()
 {
     if ($this->_request->isPost()) {
         //sign in
         if ($this->_getParam('type') == 'signin') {
             $login = $_POST['login'];
             $mdp = $_POST['password'];
             $user = new Application_Model_User();
             $connection = $user->login($login, $mdp);
             if (!isset($connection['id_user'])) {
                 echo "vous n'exister pas";
             } else {
                 if ($connection['is_blocked'] == '0') {
                     $this->sess = new Zend_Session_Namespace('user');
                     $this->sess->data = $connection;
                     $this->_redirect($this->view->url(array('controller' => 'index', 'action' => 'index', 'message' => 'connecter'), null, true));
                 } else {
                     $this->_redirect($this->view->url(array('controller' => 'index', 'action' => 'acces'), null, true));
                 }
             }
             // sign up
         } elseif ($this->_getParam('type') == 'signup') {
             $login = $_POST['login'];
             $mdp = $_POST['password'];
             $firstname = $_POST['first_name'];
             $lastname = $_POST['last_name'];
             $mail = $_POST['email'];
             $phone = $_POST['phone'];
             $address = $_POST['address'];
             $cp = $_POST['code_postal'];
             $ville = $_POST['ville'];
             $user = new Application_Model_User();
             $verif = $user->loginExist($login);
             if ($verif > 0) {
                 $this->_redirect($this->view->url(array('controller' => 'user', 'action' => 'index', 'login' => false), null, true));
             }
             $stat = $user->inscription($login, $mdp, $firstname, $lastname, $mail, $phone, $address, $cp, $ville);
             if ($stat != -1) {
                 $val = 'enregistrer';
             } else {
                 $val = 'erreur';
             }
             $this->_redirect($this->view->url(array('controller' => 'index', 'action' => 'index', 'message' => $val), null, true));
         }
     }
 }
 /**
  * Request to login a user comes to this method
  */
 public function indexAction()
 {
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('user'));
     //If user is already loged in redirect him to dash board.
     if ($auth->hasIdentity()) {
         $this->_redirect('patient/orders');
     }
     $this->_helper->layout->setLayout('login');
     $forms = Zend_Registry::get('forms');
     $form = new Zend_Form($forms->user->login);
     $userManagement = new Application_Model_User();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $error = array();
         if ($form->isValid($data)) {
             $userName = $form->username->getValue();
             $password = $form->password->getValue();
             $remember = $this->_request->getParam('remember', 0);
             $userTable = new Application_Model_DbTable_User();
             $userExits = $userTable->fetchRow('username = "******" AND password= "******" AND deleted_at IS NULL');
             $magUser = false;
             if (!empty($userExits)) {
                 $userExits = $userExits->toArray();
                 if ($userExits['id'] == 0 || $userExits['id'] == '') {
                     $magUser = true;
                 }
                 $session = new Zend_Session_Namespace('userObj');
                 $session->__set('userObj', $userExits);
             }
             if ($magUser) {
                 $form->username->setErrors(array('Invalid username or password'));
             } else {
                 $response = $userManagement->login($userName, md5($password), $remember);
             }
             if ($response == 'success') {
                 $this->_redirect('patient/orders');
             } else {
                 $form->username->setErrors(array('Invalid username or password'));
             }
         }
     }
     $this->view->form = $form;
 }