Current File : /home/karenpetzb/application/modules/default/controllers/AuthController.php
<?php

class AuthController  extends Modules_Default_Controllers_MainController
{
	public function init()
	{
		$this->view->baseUrl = $this->getBaseUrl();
		$this->checkMaintenance();
	}
	public function indexAction()
	{

	}
	public function logoutAction()
	{
		Zend_Auth::getInstance()->clearIdentity();
		$this->view->user = null;
		$this->_redirect('/');
	}
	public function loginAction()
	{

		$this->view->message = '';
		if ($this->_request->isPost()) {

			// collect the data from the user
			Zend_Loader::loadClass('Zend_Filter_StripTags');
			$f = new Zend_Filter_StripTags();
			$username = $f->filter($this->_request->getPost('username'));
			$password = $f->filter($this->_request->getPost('password'));

			if (empty($username) || empty($password)) {

				$this->view->message = 'Les champs sont obligatoire.';
					
			} else {

				// setup Zend_Auth adapter for a database table
				Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
				$dbAdapter = Zend_Registry::get('dbAdapter');

				$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter,
															'user',
															'LOGIN',
															'MDP',
															'MD5(?) AND ROLE = "0"'); 
					
				// Set the input credential values to authenticate against
				$authAdapter->setIdentity($username);
				$authAdapter->setCredential($password);

				// do the authentication
				$auth = Zend_Auth::getInstance();
				$result = $auth->authenticate($authAdapter);
				//$result = $authAdapter->authenticate();
					
				if ($result->isValid()) {

					// success: store database row to auth's storage
					// system. (Not the password though!) //array('IDUSER', 'LOGIN'));
					$data = $authAdapter->getResultRowObject(null, 'mdp');

					$auth->getStorage()->write($data);

					$this->log("Login : ".$username,'info');
					$this->_redirect('/backoffice/');
				} else {
					// failure: clear database row from session
					$this->view->message = 'Les identifiants sont incorrects.';
				}
			}
		}
		$this->render();
	}
}

?>