belcebur / belcebur-auth
Doctrine2 多重认证
v1.0.1
2017-08-14 06:32 UTC
Requires
Suggests
- belcebur/belcebur-basic: Basic Tools from ZF2 + Doctrine + Gedmo Extension / Utilidades varias para ZF2 + Doctrine + Gedmo
- gedmo/doctrine-extensions: Multiple Doctrine Extensions
This package is auto-updated.
Last update: 2024-09-26 17:43:55 UTC
README
使用 composer 安装 / 使用 Composer 安装
composer require belcebur/belcebur-auth
Packagist: https://packagist.org.cn/packages/belcebur/belcebur-auth
GitHub: https://github.com/Belcebur/BelceburAuth
配置适配器 / 配置适配器
服务管理器
英语
使用服务管理器创建适配器并指明服务名称。
您可以同时使用一种方法或两种方法。
西班牙语
使用服务管理器创建适配器并指明服务名称。
*可以同时使用一种方法或两种方法.*
示例
<?php return array( 'service_manager' => array( 'factories' => array( 'serviceName1' => function (\Zend\ServiceManager\ServiceLocatorInterface $sm) { return new \DoctrineModule\Authentication\Adapter\ObjectRepository(array( 'object_manager' => $sm->get('Doctrine\ORM\EntityManager'), 'identity_class' => 'Application\Entity\User', 'identity_property' => 'email', 'credential_property' => 'password', 'credentialCallable' => function (\Application\Entity\User $entity, $password) { return md5($password); } )); }, 'serviceName2' => function (\Zend\ServiceManager\ServiceLocatorInterface $sm) { return new \DoctrineModule\Authentication\Adapter\ObjectRepository(array( 'object_manager' => $sm->get('Doctrine\ORM\EntityManager'), 'identity_class' => 'Application\Entity\Member', 'identity_property' => 'username', 'credential_property' => 'password', 'credentialCallable' => function (\Application\Entity\Member $entity,$password) { return md5($password); } )); }, ), ), 'belcebur' => array( 'belcebur-auth' => array( 'auth-factories' => array( 'sm-factories' => array('serviceName1',serviceName2,....), 'config-factories' => array() ) ), ), );
自动创建服务 / 自动创建服务
<?php return array( 'belcebur' => array( 'belcebur-auth' => array( 'auth-factories' => array( 'sm-factories' => array(), 'config-factories' => array( 'serviceName1' => array( 'identity_class' => 'Application\Entity\User', 'identity_property' => 'email', 'credential_property' => 'password', 'credentialCallable' => function (\Application\Entity\User $entity,$password) { return md5($password); } ) ), ) ), ), );
启用模块 / 启用模块
英语
在 "application.config.php" 文件中添加模块名称 BelceburAuth。
西班牙语
在 "application.config.php" 文件中添加模块名称 BelceburAuth。
示例
<?php return array( 'modules' => array( 'Application', 'BelceburAuth' ), );
如何使用? / 如何使用?
在控制器中 / 在控制器中
英语
首先调用服务,然后请求 identity_class 并指明适用的适配器。
西班牙语
首先调用服务,然后请求 identity_class 并指明适用的适配器。
示例
/** * @var \BelceburAuth\Service\AuthenticationFactory $authFactory * @var \DoctrineModule\Authentication\Adapter\ObjectRepository $adapter * @var \Zend\Authentication\Result $result */ $authAdapters = $this->getServiceLocator()->get('AuthenticationFactory'); $adapter = $authAdapters->getAuthAdapter('Application\Entity\User'); $adapter->setIdentity($identity); $adapter->setCredential($password); $result = $authAdapters->authenticate($adapter); var_dump($this->identity()); die;