Php Zend Framework 2身份验证不带数据库表检查
我正在尝试进行Zend 2经典身份验证,而不使用DbTable检查 我会解释得更清楚Php Zend Framework 2身份验证不带数据库表检查,php,session,authentication,zend-framework2,Php,Session,Authentication,Zend Framework2,我正在尝试进行Zend 2经典身份验证,而不使用DbTable检查 我会解释得更清楚 我有一个自定义方法authenticate(),它能够对用户进行身份验证(独立于Zend Auth) 我创建了一个扩展Zend\Authentication\Storage\Session的自定义类 现在,我想用如下方式将数据保存到会话中: $authService->getStorage()->write($this); 问题在于在下一页调用时使用该代码: if($authService-
- 我有一个自定义方法authenticate(),它能够对用户进行身份验证(独立于Zend Auth)
- 我创建了一个扩展Zend\Authentication\Storage\Session的自定义类
- 现在,我想用如下方式将数据保存到会话中:
$authService->getStorage()->write($this);
if($authService->hasIdentity())
它的回答是错误的
那么,如何使用自定义身份验证保存身份?我想我可以实现Zend\Authentication\Adapter\AdapterInterface,但我不知道具体如何实现
感谢您的帮助,
非常感谢:)您可以创建如下适配器:
use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Result as AuthResult;
class MyAdapter implements AdapterInterface
{
/**
* @return \Zend\Authentication\Result
*/
public function authenticate()
{
/* Return if can't find user */
return new AuthResult(AuthResult::FAILURE_IDENTITY_NOT_FOUND, null);
/* Return if success, second parameter is the identity, e.g user. */
return new AuthResult(AuthResult::SUCCESS, $identity);
/* Return if user found, but credentials were invalid */
return new AuthResult(AuthResult::FAILURE_CREDENTIAL_INVALID, null);
}
}
您可以将此适配器与ZF2 AuthenticationService一起使用,如下所示:
$auth_service = new \Zend\Authentication\AuthenticationService();
/* Where $myAdapter is a instance of the MyAdapter class above */
$auth_service->setAdapter($myAdapter);