本文整理汇总了PHP中Zend\Authentication\AuthenticationService::hasIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationService::hasIdentity方法的具体用法?PHP AuthenticationService::hasIdentity怎么用?PHP AuthenticationService::hasIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Authentication\AuthenticationService
的用法示例。
在下文中一共展示了AuthenticationService::hasIdentity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginAction
public function loginAction()
{
if ($this->authenticationService->hasIdentity()) {
return $this->redirect()->toRoute('dashboard');
}
$storage = $this->authenticationService->getStorage();
$this->authenticationService->setStorage(new NonPersistent());
$redir = $this->params()->fromQuery('redir', $this->params()->fromPost('redir'));
if ($redir !== null) {
$this->authSession->url = $redir;
return $this->redirect()->toRoute('login');
}
if ($this->getRequest()->isPost()) {
$this->authenticateForm->setData($this->getRequest()->getPost());
if ($this->authenticateForm->isValid()) {
/** @var AccountInterface $account */
$account = $this->zourceAccount();
$this->authSession->identity = $this->identity();
$this->authSession->verified = false;
$this->authenticationService->setStorage($storage);
return $this->redirectAfterLogin($account);
}
}
$this->resetTwoFactorAuthentication();
return new ViewModel(['authenticateForm' => $this->authenticateForm]);
}
示例2: __construct
/**
* @var AuthenticationService
*/
public function __construct(AuthenticationService $authService, array $config)
{
$roles = array();
$this->authService = $authService;
$this->config = $config;
$roleKey = $this->config['identity_providers']['ldap_role_key'];
if ($this->authService->hasIdentity()) {
$rawObj = $this->authService->getIdentity()->getRawLdapObj();
$data = @unserialize($rawObj);
if ($data !== false) {
$user = unserialize($rawObj);
if (!is_null($user) || is_array($user)) {
$roles = array('user');
foreach ($user[$roleKey] as $role) {
//if (isset($definedRoles[$role]))
$roles[] = $role;
}
}
}
}
if (!is_array($roles)) {
throw new InvalidArgumentException('ZfcUserLdapRbacIdentityProvider only accepts strings or arrays');
}
$this->roles = $roles;
}
示例3: getIdentityRoles
/**
* {@inheritDoc}
*/
public function getIdentityRoles()
{
$definedRoles = $this->bjyConfig['role_providers']['BjyAuthorize\\Provider\\Role\\Config']['user']['children'];
$roleKey = $this->config['identity_providers']['ldap_role_key'];
if (!$this->authService->hasIdentity()) {
return array($this->getDefaultRole());
}
$rawObj = $this->authService->getIdentity()->getRoles();
// $data = @unserialize($rawObj);
// if ($data === false) {
// return array($this->getDefaultRole());
// }
// $user = unserialize($rawObj);
$user = $rawObj;
if (is_null($user) || !is_array($user)) {
return array($this->getDefaultRole());
}
$roles = array('user');
// foreach ($user[$roleKey] as $role) {
foreach ($user as $role) {
if (isset($definedRoles[$role])) {
$roles[] = $role;
}
}
return $roles;
}
示例4: __invoke
public function __invoke(MvcEvent $event)
{
if ($event->getRequest() instanceof ConsoleRequest) {
return;
}
$match = $event->getRouteMatch();
// No route match, this is a 404
if (!$match instanceof RouteMatch) {
return;
}
/** @var Application $app */
$app = $event->getParam('application');
$config = $app->getConfig();
$disableForAuthorizedCallback = $config['authorized-redirect-to-route'];
$redirectTo = $disableForAuthorizedCallback($match, $this->authService);
if ($this->authService->hasIdentity() && !empty($redirectTo)) {
$response = $this->redirectTo($event, $redirectTo);
return $response;
}
$checkCallback = $config['need-authorization-callback'];
// if true = authorization needed
if (!$checkCallback($match, $this->authService)) {
return;
}
// User is authenticated
if ($this->authService->hasIdentity()) {
return;
}
$response = $this->redirectTo($event, $config['not-authorized-redirect-to-route']);
return $response;
}
示例5: onBootstrap
public function onBootstrap($e)
{
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
/*
* Definições de sessoes
*/
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("Usuario"));
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
$config = $e->getApplication()->getServiceManager()->get('config');
/*
* Permissão de usuário
*/
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
if (!$auth->hasIdentity() && $matchedRoute != "login" && $matchedRoute != "gatewayTesteValidacao") {
return $controller->redirect()->toRoute("login");
} else {
if ($auth->hasIdentity() && $matchedRoute == "login") {
return $controller->redirect()->toRoute("enviarMensagem");
}
}
if ($auth->hasIdentity()) {
$controller->layout()->infoUser = $auth->getIdentity();
}
}, 100);
}
示例6: __invoke
/**
* Retrieve the current admin
*
* @return UserModel|boolean
*/
public function __invoke()
{
if ($this->auth->hasIdentity()) {
return $this->auth->getIdentity();
}
return false;
}
示例7: preDispatch
/**
* preDispatch Event Handler
* Handle authentication process
* Decide where user should be redirected to when logged in or not
*
*
* @access public
* @uses AuthenticationService
* @uses Response
*
* @param \Zend\Mvc\MvcEvent $event
* @throws \Exception
*/
public function preDispatch(MvcEvent $event)
{
// ACL dispatcher is used only in HTTP requests not console requests
if (!$event->getRequest() instanceof HttpRequest) {
return;
}
$userAuth = new AuthenticationService();
$user = array();
$signInController = 'DefaultModule\\Controller\\Sign';
if ($userAuth->hasIdentity()) {
$user = $userAuth->getIdentity();
}
$routeMatch = $event->getRouteMatch();
$controller = $routeMatch->getParam('controller');
$action = $routeMatch->getParam('action');
if ($userAuth->hasIdentity() && isset($user['status']) && $user['status'] == 2) {
$userAuth->clearIdentity();
// redirect to sign/out
$url = $event->getRouter()->assemble(array('action' => 'out'), array('name' => 'defaultSign'));
} else {
if ($userAuth->hasIdentity() && $controller == $signInController && $action == 'in') {
// redirect to index
$url = $event->getRouter()->assemble(array('action' => 'index'), array('name' => 'home'));
}
}
if (isset($url)) {
$event->setResponse(new Response());
$this->redirect()->getController()->setEvent($event);
$response = $this->redirect()->toUrl($url);
return $response;
}
}
示例8: logout
public function logout()
{
if ($this->authService->hasIdentity()) {
$this->authService->clearIdentity();
$this->sessionManager->forgetMe();
}
}
示例9: validAuthAcl
public function validAuthAcl($e)
{
$storage = new SessionStorage();
$auth = new AuthenticationService();
$auth->setStorage($storage);
//pega controller e action
$controller = $e->getTarget();
$em = $controller->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
$matchedController = $controller->getEvent()->getRouteMatch()->getParam('controller');
$matchedAction = $controller->getEvent()->getRouteMatch()->getParam('action', 'index');
//user logado
if ($auth->hasIdentity()) {
$arrayUser = $auth->getIdentity();
$repository = $em->getRepository("Zf2User\\Entity\\User");
$user = $repository->findOneById($arrayUser->getId());
$role = $user->getRole()->getName();
} elseif (!$auth->hasIdentity()) {
$role = 'Visit';
}
//acl
$acl = $controller->getServiceLocator()->get("Zf2Acl\\Permissions\\Acl");
if (!$acl->isAllowed($role, $matchedController, $matchedAction)) {
$e->getResponse()->setStatusCode(Response::STATUS_CODE_404);
$e->stopPropagation();
}
}
示例10: testFailAuthenticationOnNoToken
public function testFailAuthenticationOnNoToken()
{
$token = new AccessToken();
$owner = $this->getMock(TokenOwnerInterface::class);
$token->setOwner($owner);
$this->resourceServer->expects($this->atLeastOnce())->method('getAccessToken')->with($this->isInstanceOf(PsrServerRequestInterface::class))->will($this->returnValue(null));
$this->assertFalse($this->authenticationService->hasIdentity());
$this->assertNull($this->authenticationService->getIdentity());
}
示例11: validaAuth
public function validaAuth(MvcEvent $e)
{
$auth = new AuthenticationService();
$auth->setStorage(new SessionStorage("SessaoUsuario"));
$controller = $e->getTarget();
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
if ((!$auth->hasIdentity() and $matchedRoute == "language" || $matchedRoute == "language/default") || (!$auth->hasIdentity() and $matchedRoute == "user" || $matchedRoute == "user/default") || (!$auth->hasIdentity() and $matchedRoute == "application" || $matchedRoute == "application/default") || (!$auth->hasIdentity() and $matchedRoute == "home")) {
return $controller->redirect()->toRoute("login");
}
}
示例12: __invoke
/**
* Retrieve the current identity, if any.
*
* If none available, returns null.
*
* @throws Exception\RuntimeException
* @return mixed|null
*/
public function __invoke()
{
if (!$this->authenticationService instanceof AuthenticationService) {
throw new Exception\RuntimeException('No AuthenticationService instance provided');
}
if (!$this->authenticationService->hasIdentity()) {
return null;
}
return $this->authenticationService->getIdentity();
}
示例13: onError
/**
* If user is logged in, it calls UnauthorizedStrategy otherwise it calls RedirectStrategy
*
* @param MvcEvent $event
* @return void
*/
public function onError(MvcEvent $event)
{
$app = $event->getApplication();
$serviceManager = $app->getServiceManager();
if ($this->authenticationService->hasIdentity()) {
$serviceManager->get('ZfcRbac\\View\\Strategy\\UnauthorizedStrategy')->onError($event);
} else {
$serviceManager->get('ZfcRbac\\View\\Strategy\\RedirectStrategy')->onError($event);
}
}
示例14: isAllowed
/**
* @param RequestInterface $request
*
* @return bool
*/
public function isAllowed(RequestInterface $request)
{
if (!$request instanceof Http\Request) {
return false;
}
if ($this->authService->hasIdentity()) {
return true;
}
$path = $request->getUri()->getPath();
return in_array($path, ['', '/']);
}
示例15: getIdentityRoles
/**
* {@inheritDoc}
*/
public function getIdentityRoles()
{
//if user was manually deleted from storage we should clear identity
if ($this->authService->hasIdentity() && !$this->authService->getIdentity()) {
$this->authService->clearIdentity();
}
if (!$this->authService->hasIdentity()) {
return array($this->getDefaultRole());
}
return $this->authService->getIdentity()->getUser()->getRole();
}