I'm trying to implement authentication module in a ZF2 application, i did exactly as i found in official docs, but i'm getting this error:
Fatal error: Call to undefined method DoctrineModule\Authentication\Adapter\ObjectRepository::setIdentityValue() in DOCROOT/module/Login/src/Login/Controller/IndexController.php on line 33
I put this in my module.config.php:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
),
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Login\Entity\User',
'identity_property' => 'email',
'credential_property' => 'password',
),
),
)
in my module.php:
public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
return $serviceManager->get('doctrine.authenticationservice.orm_default');
}
)
);
}
And this is my controller:
namespace Login\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController{
public function indexAction(){
if ($this->getRequest()->isPost()) {
if($this->authenticate()){
return new ViewModel(array(
'error' => 'Your authentication credentials is valid!',
));
}else{
return new ViewModel(array(
'error' => 'Your authentication credentials are not valid',
));
}
}else{
return new ViewModel(array('error' => ''));
}
}
public function authenticate(){
$data = $this->getRequest()->getPost();
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($data['email']);
$adapter->setCredentialValue($data['password']);
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
return true;
}else{
return false;
}
}
}
Any glue?