コード例 #1
0
ファイル: UserServiceTest.php プロジェクト: rexmac/zyndax
 public function testFindWithParameter()
 {
     $testEntity = UserTest::createTestUser();
     self::$entityManager->persist($testEntity);
     self::$entityManager->flush();
     $entity = UserService::find($testEntity->getId());
     $this->assertEquals($testEntity->toArray(), $entity->toArray());
 }
コード例 #2
0
ファイル: UsersController.php プロジェクト: rexmac/zyndax
 /**
  * Index action
  *
  * @return void
  */
 public function indexAction()
 {
     $timeZone = new DateTimeZone($this->_user->getProfile()->getTimeZone()->getName());
     $users = UserService::find();
     uasort($users, function ($a, $b) {
         $a = strtolower($a->getUsername());
         $b = strtolower($b->getUsername());
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     });
     $this->view->users = $users;
     $this->view->timeZone = $timeZone;
     if (Zend_Registry::get('acl')->isUserAllowed('mvc:admin:users:create', 'view')) {
         $this->view->contextLinks = '<a class="addUserLink zp-button" href="' . $this->view->url(array(), 'adminUserCreate') . '" title="Create User">+ Add</a>';
     }
     JqueryViewHelper::assignData(array('userMayEdit' => Zend_Registry::get('acl')->isUserAllowed('mvc:admin:users:create', 'view')));
 }
コード例 #3
0
ファイル: Auth.php プロジェクト: rexmac/zyndax
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  * Does nothing if current request matches a whitelisted route, or if
  * request is authenticated. Otherwise, redirects to login page.
  *
  * @param  AbstractRequest $request
  * @throws Zend_Controller_Dispatcher_Exception
  * @throws Zend_Controller_Action_Exception
  * @return void
  */
 public function preDispatch(AbstractRequest $request)
 {
     $route = strtolower(sprintf('%s/%s/%s', $request->getModuleName(), $request->getControllerName(), $request->getActionName()));
     Logger::debug(__METHOD__ . ':: route = ' . $route);
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         Logger::debug(__METHOD__ . ":: Auth has identity...");
         $user = UserService::find($auth->getIdentity());
         $user->setLastConnect(new DateTime());
         UserService::update();
         Zend_Registry::set('user', $user);
         Logger::debug(__METHOD__ . ':: logged in as user: '******' - ' . $user->getUsername());
         if (!Zend_Session::$_unitTestEnabled) {
             // @codeCoverageIgnoreStart
             // If accessing non-admin UI and currently using LoginAs feature, then overwrite 'user' in registry
             $authCookieName = Zend_Registry::get('config')->session->auth->name;
             $ssa = new Zend_Session_Namespace($authCookieName);
             if (isset($ssa->loginAsUser) && 'admin' !== strtolower($request->getModuleName())) {
                 $user = UserService::find($ssa->loginAsUser);
                 #Logger::debug(__METHOD__.':: admin using login-as user: '******' - ' . $user->getUsername());
                 Zend_Registry::set('loginAs', true);
                 Zend_Registry::set('user', $user);
             }
         }
         // @codeCoverageIgnoreEnd
     }
     $this->_isDispatchable($request);
     if (null === $this->_whitelist) {
         $this->_whitelist = Zend_Registry::get('config')->auth->whitelist->toArray();
     }
     foreach ($this->_whitelist as $whitelistedRoute) {
         if (preg_match('|^' . $whitelistedRoute . '$|', $route)) {
             return;
         }
     }
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         Logger::debug(__METHOD__ . ":: Auth has identity...");
         #if(isset($_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; }
         #elseif(isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; }
         #elseif(isset($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; }
         #else { $ip = null; }
         return;
     }
     #$request->setDispatched(false);  // Cancel the current action
     // Handle unauthorized request...
     Logger::debug(__METHOD__ . ":: Unauthorized request. Redirecting...");
     if (!Zend_Session::$_unitTestEnabled) {
         // @codeCoverageIgnoreStart
         $session = new Zend_Session_Namespace('referrer');
         $session->uri = $request->getRequestUri();
     }
     // @codeCoverageIgnoreEnd
     if ($request->isXmlHttpRequest()) {
         return $this->getResponse()->setHttpResponseCode(500)->setBody(json_encode(array('redirect' => '/user/login')))->sendResponse();
     }
     $helper = HelperBroker::getStaticHelper('redirector');
     $helper->gotoUrl('/user/login');
 }