Doctrine orm 使用Doctrine 2 MongoDBOM模块进行身份验证
我正在尝试使用Zend2和DoctrineODModule设置登录(身份验证),但出现了一个错误。 我按照教程设置了Zend2与DoctoriNeodModule on的身份验证Doctrine orm 使用Doctrine 2 MongoDBOM模块进行身份验证,doctrine-orm,zend-framework2,doctrine-odm,Doctrine Orm,Zend Framework2,Doctrine Odm,我正在尝试使用Zend2和DoctrineODModule设置登录(身份验证),但出现了一个错误。 我按照教程设置了Zend2与DoctoriNeodModule on的身份验证 有什么建议我做错了什么吗?或者我该怎么办?带着你给我的信息 A value for the identity was not provided prior to authentication with ObjectRepository authentication adapter 我想说的是,要么你没有在你的用户文
有什么建议我做错了什么吗?或者我该怎么办?带着你给我的信息
A value for the identity was not provided prior to authentication with ObjectRepository authentication adapter
我想说的是,要么你没有在你的用户文档上提供字段作为身份,要么在身份验证过程中(在你的操作中)你没有填充身份的值(又名登录)
请提供有关您的应用程序的更多信息(odm模块配置、标识类…),以便为您提供更好的帮助
作为配置,您应该有如下stg:
...
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_orm_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_orm_driver'
)
),
__NAMESPACE__ . '_odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
),
'odm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Document' => __NAMESPACE__ . '_odm_driver'
)
)
),
'authentication' => array(
'odm_default' => array(
'objectManager' => 'doctrine.documentmanager.odm_default',
'identityClass' => 'Application\Document\User',
'identityProperty' => 'username',
'credentialProperty' => 'password',
'credentialCallable' => 'Application\Utils::hashPassword' // Not needed if you don't hash passwords
),
),
),
...
这对我的一些项目来说非常有效我用以下方式完成了它。 在mdule.config.php中
'authentication' => array(
'odm_default' => array(
'object_manager' => 'doctrine.documentmanager.odm_default',
'identity_class' => 'Admin\Document\User',
'identity_property' => 'username',
'credential_property' => 'password',
),
),
'odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
),
'odm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Document' => 'odm_driver'
)
)
在Admin/Document/User.php中创建了两个方法getUsername和getPassword
public function getUsername(){
return $this->username;
}
public function getPassword(){
return $this->password;
}
在index controller.php中创建了控制器
public function loginAction(){
$this->layout('layout/login-layout.phtml');
$login_error=false;
$loginForm = new LoginForm();
if ($this->request->isPost())
{
$loginForm->setData($this->request->getPost());
if ($loginForm->isValid())
{
// try {
// throw new \Exception("My exception");
$data = $loginForm->getData();
$authService = $this->getServiceLocator()
->get('doctrine.authenticationservice.odm_default');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($data['username']); // i am using username
$adapter->setCredentialValue(md5($data['password']));
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
$this->redirect()->toRoute('admin_index'); // or last viewed page
}
/*} catch (Exception $e) {
echo "Caught exception $e\n";
echo $e->getPrevious();
$login_error=false;
return new ViewModel(array(
'loginForm' => $loginForm,
'login_error' => $login_error,
));
//exit;
}/
return array(
'loginForm' => $loginForm,
'errors' => 'username or password is not valid',
);
$this->redirect()->toRoute('admin_index');
} else {
//
// LOG Event ( login|password not valide )
//
//Zend\Debug\Debug::dump("not valid data");
//Zend\Debug\Debug::dump($loginForm->getMessages());
$login_error=true;
}//* */
}
}
//
return new ViewModel(array(
'loginForm' => $loginForm,
'login_error' => $login_error,
));
}
它无法解决现在出现的错误“创建“Zend\Authentication\AuthenticationService”时引发异常;未返回任何实例”