?
<?php
class Admin_LoginController extends Zend_Controller_Action
{
function loginAction()
{
$url = $this->_request->getParam('url');
$this->_helper->viewRenderer->setResponseSegment( 'login' );
$session = Zend_Registry::get('session');
$translate = Zend_Registry::get('translate');
$action = $session->action;
$actionname = $session->actionname;
$this->view->lang=$session->lang;
$this->view->deconnect = '';
$acces = 0;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
$f = new Zend_Filter_StripTags();
$username = $f->filter($this->_request->getPost('login'));
$password = $f->filter($this->_request->getPost('pass'));
$acces = 1;
}
else
{
if(isset($url))
{
$url = base64_decode($url);
exit($url);
$param = explode("-", $url);
$username = $param[0];
$password = $param[1];
$acces = 1;
}
}
if($acces == 1)
{
if (empty($username)) {
$this->view->message = $translate->_("label_error_name");
} else
{
// setup Zend_Auth adapter for a database table
$config = new Zend_Config_Ini('./application/config/config.ini', ENV);
// Zend Objet Base de données
$dbAdapter = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => $config->db->params->host,
'username' => $config->db->params->username,
'password' => $config->db->params->password,
'dbname' => $config->db->params->dbname
));
$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);
$user = $auth->getIdentity();
if($user->real_name == "professionnel")
{
$this->_redirect('pro-photos-'.$session->lang.'.html');
}
if($user->real_name == "presse")
{
$this->_redirect('presse-photos-'.$session->lang.'.html');
}
$this->view->message = "ok";
//exit($user->real_name);
$this->_redirect('pro-photos-'.$session->lang.'.html');
} else {
// failure: clear database row from session
$this->view->message = $translate->_("label_error_login");
}
}
}
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$this->view->afficheform = 'ok';
if (isset($user))
{
$roleUser = $user->role;
}
if (!$auth->hasIdentity()) {
$form = new FormLoginadmin();
$this->view->form = $form;
}
else if(($roleUser == "admin") || ($roleUser == "pro") || ($roleUser == "presse"))
{
//exit("ici");
$fc = Zend_Controller_Front::getInstance();
$url= $fc->getBaseUrl();
$this->view->message = $translate->_("label_connect_ok");
$this->view->deconnect = $translate->_("label_deconnection");
$this->view->afficheform = 'ko';
if($roleUser == "admin")
{
$titresection = $translate->_("label_titre_admin");
}
else if($roleUser == "pro")
{
$titresection = $translate->_("label_titre_pro");
}
else if($roleUser == "presse")
{
$titresection = $translate->_("label_titre_presse");
}
$this->view->titresection = $titresection;
}
else
{
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('/admin');
}
}
}