Witam, mam pewien skrypt, w którym potrzebuję dostać się do panelu admina, w aplication.ini mam:
resources.router.routes.administracja.route = "/administracja"
resources.router.routes.administracja.defaults.controller = "/autoryzacja"
resources.router.routes.administracja.defaults.action = "/index"
w AutoryzacjaController.php:
<?php
class AutoryzacjaController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->form = new Application_Form_Login();
}
public function loginAction()
{
$this->_helper->viewRenderer('index');
$form = new Application_Form_Login();
if ($form->isValid($this->getRequest()->getPost())){
$adapter = new Zend_Auth_Adapter_DbTable(
null,
'user',
'uzytkownik',
'haslo',
'MD5(CONCAT(?))'
);
$adapter->setIdentity($form->getValue('uzytkownik'));
$adapter->setCredential($form->getValue('haslo'));
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
if ($result->isValid()){
return $this->_helper->redirector(
'index',
'index',
'default'
);
}
$form->haslo->addError('Błędna próba logowania');
}
$this->view->form = $form;
}
public function logoutAction()
{
$auth = Zend_Auth::getInstance();
$auth->clearIdentity();
return $this->_helper->redirector(
'index',
'index',
'default'
);
}
}
i w widoku autoryzacja mam:
<?php
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity())
else
echo "Jesteś już zalogowany"; ?>
Dane w bazie są następujące:
uzytkownik: admin
haslo: 21232f297a57a5a743894a0e4a801fc3 -> to w md5 to jest admin czyli hasło i login powinno być admin, jednak jak tak wpisuję to nie działa, nie wyskakuje również komunikat o niepoprawnych danych, a powinien
jeszcze plik forms/Login.php
<?php
class Application_Form_Login extends Zend_Form {
public function init() {
$this->setMethod('post');
$view = Zend_Layout::getMvcInstance()->getView();
$url = $view->url(array('controller' => 'autoryzacja', 'action' => 'login')); $this->setAction($url);
$this->addElement(
'text', 'uzytkownik', array('label' => 'Uzytkownik:', 'required' => true,
'filters' => array('StringTrim'), )
);
$this->addElement(
'password', 'haslo', array('label' => 'Hasło:', 'required' => true,
)
);
$this->addElement(
'submit', 'submit', array('ignore' => true, 'label' => 'Zaloguj',
)
);
}
}
Ten post edytował miras 24.05.2014, 11:01:16