Impossible de s'authentifier
Bonjour,
je viens solliciter votre aide car j'ai un souci avec mon système de connexion. Après avoir suivi le tutoriel de Rob Allan : http://akrabat.com/zend-auth-tutorial/
J'ai voulu le mettre en place dans mon projet et voila l'erreur qu'il me met :
Citation:
Fatal error: Uncaught exception 'Zend_Auth_Adapter_Exception' with message 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.' in C:\wamp\bin\php\php5.3.8\PEAR\Zend\Auth\Adapter\DbTable.php on line 419
Voila mon code :
Code:
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| <?php
class AuthController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$form = new Form_Login();
$request = $this->getRequest();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
if ($this->_process($form->getValues())) {
// We're authenticated! Redirect to the home page
$this->_helper->redirector('index', 'index');
}
}
}
$this->view->form = $form;
}
protected function _process($values)
{
// Get our authentication adapter and check credentials
$adapter = $this->_getAuthAdapter();
$adapter->setIdentity($values['LOGIN']);
$adapter->setCredential($values['PASSWD']);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if ($result->isValid()) {
$user = $adapter->getResultRowObject();
$auth->getStorage()->write($user);
return true;
}
return false;
}
protected function _getAuthAdapter()
{
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('login')
->setIdentityColumn('LOGIN')
->setCredentialColumn('PASSWD')
->setCredentialTreatment('SHA1(CONCAT(?,salt))');
return $authAdapter;
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->redirector('index'); // back to login page
}
/*
public function loginAction()
{
$form= new Form_Login();
$request = $this->getRequest();
$this->view->message = 'Connexion';
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 = 'Erreur de login';
// 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);
$authAdapter->setTableName('users');
$authAdapter->setIdentityColumn('username');
$authAdapter->setCredentialColumn('password');
// 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);
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);
echo "coucou";
//$this->_redirect('/');
} else {
// failure: clear database row from session
$this->view->message = 'Erreur de connexion.';
}
}
}
$this->view->title = "Administration";
$this->render();
}
*/
}
?> |
Login.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?php
class Form_Login extends Zend_Form
{
public function init()
{
$this->setName("login");
$this->setMethod('post');
$this->addElement('text', 'login',array('required' => true, 'label' => 'Login :',
));
$this->addElement('password', 'passwd', array('required' => true, 'label' => 'Mot de passe :', 'validator'=>'stringlength', 'options'=>array('min'=>3), 'breakChainOnFailure'=>true
));
$this->addElement('submit', 'Envoyer', array('label' => 'Envoyer'));
}
} |
index.phtml :
Code:
1 2 3 4 5
| <?php $this->headTitle('Login'); ?>
<h1>Connexion</h1>
<?php echo $this->form->setAction($this->url()); ?> |
Et mon main.ini :
Code:
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
| [prod]
includepaths[] = APP_PATH "/model"
autoloadernamespaces[] = Table
autoloadernamespaces[] = Form
bootstrap.path = APP_PATH "/Bootstrap.php"
bootstrap.class = FormationBoot
debug = 0
log.logfile = APP_PATH "/logs/main.log"
log.filterlevel = 6
resources.db.adapter = Pdo_Mysql
resources.db.params.username = bd
resources.db.params.dbname = grandprix
resources.db.params.unix_socket = /var/run/mysqld/mysqld.sock
resources.db.params.password = bede
resources.db.params.charset = "utf8"
resources.session.name = appformation
resources.session.save_path = APP_PATH "/tmp/sessions"
resources.cachemanager.moncache1.frontend.name = core
resources.cachemanager.moncache1.frontend.options.automatic_serialization = 1
resources.cachemanager.moncache1.frontend.options.lifetime = 60
resources.cachemanager.moncache1.backend.name = file
resources.cachemanager.moncache1.backend.options.cache_dir = APP_PATH "/tmp/cache"
resources.view.basePath = APP_PATH "/views"
resources.layout.layoutPath = APP_PATH "/layouts"
resources.layout.layout = design
resources.translate.adapter = array
resources.translate.data = APP_PATH "/translate"
resources.translate.scan = Zend_Translate::LOCALE_DIRECTORY
resources.frontcontroller.controllerDirectory = APP_PATH "/controllers"
[dev:prod]
debug = 1
resources.frontcontroller.throwexceptions = 1
resources.view.strictVars = 1 |
Je vous précise je suis en deuxième année de DUT informatique, et il s'agit un projet purement scolaire, un "cas d'école". En tout cas cela fait maintenant 3 jours que j'écume les forums pour essayer de comprendre mon erreur mais je n'ai rien trouvé.
Je vous remercie par avance.