Exemplo n.º 1
0
	  /**
	*loginAction
          *
          * @return void
          */
     public function loginAction()
	 {
	 	
	 	$userService = new User_Service_User();
	 	
		if( $userService->hasIdentity() ){
			$this->renderScript( 'index/logedin.phtml' );
		} else {
			$sessionRequest = new Zend_Session_Namespace( 'sessionRequest');
			$form = new User_Form_Login();
			if( $this->getRequest()->isPost() ){
				if( $form->isValid( $this->getRequest()->getPost() ) ){
					$result = $userService->authenticate( $this->getRequest()->getPost());
					switch( $result ){
						case User_Service_User::USER_AUTH_SUCCESS :
							$this->addSystemSuccess('Connecté');
							$form->reset();
							$this->_redirect( $sessionRequest->previous);
							break;
						default :
							$this->addSystemError('Echec de la connexion');
							$this->_redirect($sessionRequest->previous);
							break;
					}
				} else {
					$errors = $form->getErrors();
					$translate = Zend_Registry::get( 'translator');
					$errorMessage = 'Le formulaire contient des erreurs : <br />';
					foreach( $errors as $fieldName => $fieldErrors ){
						foreach( $fieldErrors as $error ){
							$errorMessage .= 'Champ ' . $fieldName . ' : ' . $translate->_($error) . '<br />';
						}
					}
					$this->addSystemError($errorMessage);
					$this->_redirect($sessionRequest->previous);
				}
			}
			$this->view->form = $form;
		}
	 }