Пример #1
0
 /**
  * Process the login request. @see G_AuthController::loginAction as to
  * why this is separate.
  *
  * @return void
  */
 public function processAction()
 {
     // allow callers to set a targetUrl via the request
     if ($targetUrl = $this->_getSubmittedTargetUrl()) {
         Garp_Auth::getInstance()->getStore()->targetUrl = $targetUrl;
     }
     // never cache the process request
     $this->_helper->cache->setNoCacheHeaders($this->getResponse());
     // This action does not render a view, it only redirects elsewhere.
     $this->_helper->viewRenderer->setNoRender(true);
     $method = $this->getRequest()->getParam('method') ?: 'db';
     $adapter = Garp_Auth_Factory::getAdapter($method);
     $authVars = Garp_Auth::getInstance()->getConfigValues();
     $postData = $this->getRequest()->getPost();
     // Before login hook.
     $this->_beforeLogin($authVars, $adapter, $postData);
     /**
      * Params can come from GET or POST.
      * The implementing adapter should decide which to use,
      * using the current request to fetch params.
      */
     if (!($userData = $adapter->authenticate($this->getRequest(), $this->getResponse()))) {
         $this->_respondToFaultyProcess($adapter);
         return;
     }
     $this->_helper->viewRenderer->setNoRender(true);
     // Check if adapter issued a redirect (as is the case with oAuth for instance)
     if ($this->getResponse()->isRedirect()) {
         return;
     }
     if ($userData instanceof Garp_Db_Table_Row) {
         $userData = $userData->toArray();
     }
     // Save user data in a store.
     Garp_Auth::getInstance()->store($userData, $method);
     // Store User role in a cookie, so that we can use it with Javascript.
     if (!Garp_Auth::getInstance()->getStore() instanceof Garp_Store_Cookie) {
         $this->_storeRoleInCookie();
     }
     // Determine targetUrl.
     // This is the URL the user was trying to access before logging in, or a default URL.
     $router = Zend_Controller_Front::getInstance()->getRouter();
     if (!empty($authVars['login']['successRoute'])) {
         $targetUrl = $router->assemble(array(), $authVars['login']['successRoute']);
     } elseif (!empty($authVars['login']['successUrl'])) {
         $targetUrl = $authVars['login']['successUrl'];
     } else {
         $targetUrl = '/';
     }
     $store = Garp_Auth::getInstance()->getStore();
     if ($store->targetUrl) {
         $targetUrl = $store->targetUrl;
         unset($store->targetUrl);
     }
     // After login hook.
     $this->_afterLogin($userData, $targetUrl);
     // Set a Flash message welcoming the user.
     $flashMessenger = $this->_helper->getHelper('FlashMessenger');
     $fullName = new Garp_Util_FullName($userData);
     $successMsg = __($authVars['login']['successMessage']);
     if (strpos($successMsg, '%s') !== false) {
         $successMsg = sprintf($successMsg, $fullName);
     } elseif (strpos('%USERNAME%', $successMsg) !== false) {
         $successMsg = Garp_Util_String::interpolate($successMsg, array('USERNAME' => $fullName));
     }
     $flashMessenger->addMessage($successMsg);
     $this->_redirect($targetUrl);
 }
Пример #2
0
 public function testFactoryShouldRecognizeLinkedInType()
 {
     $this->assertTrue(Garp_Auth_Factory::getAdapter('LinkedIn') instanceof Garp_Auth_Adapter_LinkedIn);
 }