当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthenticationService::hasIdentity方法代码示例

本文整理汇总了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]);
 }
开发者ID:zource,项目名称:zource,代码行数:26,代码来源:Authenticate.php

示例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;
 }
开发者ID:hlich,项目名称:zfcuser-ldap,代码行数:28,代码来源:ZfcRbacIdentityProvider.php

示例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;
 }
开发者ID:sha1,项目名称:zfcuser-ldap,代码行数:29,代码来源:LdapIdentityProvider.php

示例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;
 }
开发者ID:t4web,项目名称:authentication,代码行数:31,代码来源:Checker.php

示例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);
 }
开发者ID:abazad,项目名称:whatsappMarketing,代码行数:28,代码来源:Module.php

示例6: __invoke

 /**
  * Retrieve the current admin
  *
  * @return UserModel|boolean
  */
 public function __invoke()
 {
     if ($this->auth->hasIdentity()) {
         return $this->auth->getIdentity();
     }
     return false;
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:12,代码来源:Admin.php

示例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;
     }
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:45,代码来源:AuthenticationEvent.php

示例8: logout

 public function logout()
 {
     if ($this->authService->hasIdentity()) {
         $this->authService->clearIdentity();
         $this->sessionManager->forgetMe();
     }
 }
开发者ID:sauron07,项目名称:rest_helper,代码行数:7,代码来源:UserService.php

示例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();
     }
 }
开发者ID:jhonmike,项目名称:zf-user,代码行数:27,代码来源:Module.php

示例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());
 }
开发者ID:basz,项目名称:zfr-oauth2-server-module,代码行数:9,代码来源:AuthenticationFunctionalTest.php

示例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");
     }
 }
开发者ID:MarceloSantosCorrea,项目名称:CodeEducation,代码行数:10,代码来源:Module.php

示例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();
 }
开发者ID:youprofit,项目名称:casebox,代码行数:18,代码来源:Identity.php

示例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);
     }
 }
开发者ID:hale0124,项目名称:zf2-starter-template,代码行数:16,代码来源:SmartRedirectStrategy.php

示例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, ['', '/']);
 }
开发者ID:peteraba,项目名称:dm-maileradmin,代码行数:16,代码来源:SessionGuard.php

示例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();
 }
开发者ID:zfury,项目名称:cmf,代码行数:14,代码来源:DoctrineProvider.php


注:本文中的Zend\Authentication\AuthenticationService::hasIdentity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。