1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| <?php
/*
* AuthController.php
* Contrôleur de connexion à Mnémosis
*
* Créé le 23 janv. 2010 d'après le tutoriel 'Débutez avec Zend_Auth
*
*
*/
class AuthController extends Zend_Controller_Action
{
function init()
{
$this->initView();
$this->view->baseUrl = $this->_request->getBaseUrl();
}
function indexAction()
{
$this->_redirect('/');
}
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))
{
$this->view->message = 'Veuillez donner votre perso Swing.';
}
else
{
// setup Zend_Auth adapter for a database table
Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('Joueur');
$authAdapter->setIdentityColumn('J_Nom');
$authAdapter->setCredentialColumn('J_MotPasse');
// Set the input credential values to authenticate against
$authAdapter->setIdentity($username);
$authAdapter->setCredential(md5($password));
// do the authentication
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid())
{
// success: store database row to auth's storage
// system. (Not the password though!)
$data = $authAdapter->getResultRowObject(null, 'password');
$auth->getStorage()->write($data);
$this->_redirect('/');
}
else
{
// failure: clear database row from session
$this->view->message = "Perso Swing ou mot de passe incorrect.";
}
}
}
$this->view->title = 'Connexion à Mnémosis';
$this->render();
}
function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('/');
}
}
?> |
Partager