redirect() public static method

It may generate redirected request using GET or POST HTTP method. The function never returns.
public static redirect ( string $url, array $params = null, Zend_Controller_Response_Abstract $response = null, string $method = 'GET' )
$url string URL to redirect to
$params array additional variable/value pairs to send
$response Zend_Controller_Response_Abstract
$method string redirection method ('GET' or 'POST')
示例#1
0
 function HandleObjectCategories($objectCategoryIds)
 {
     global $prefs;
     $perspectivelib = TikiLib::lib('perspective');
     $current_object = current_object();
     if (!$current_object) {
         // only used on tiki objects
         return;
     }
     $descendants = $this->get_category_descendants($prefs['areas_root']);
     $objectPerspective = 0;
     if (!empty($objectCategoryIds)) {
         if (!isset($_SESSION['current_perspective'])) {
             unset($_SESSION['current_perspective']);
         }
         foreach ($objectCategoryIds as $categId) {
             // If category is inside $prefs['areas_root']
             if (in_array($categId, $descendants)) {
                 $area = $this->getAreaByCategId($categId);
                 if ($area) {
                     $objectPerspective = $area['perspectives'][0];
                     // use 1st persp
                     break;
                 }
             }
         }
         if ($objectPerspective && $objectPerspective != $_SESSION['current_perspective']) {
             $area = $this->getAreaByPerspId($_SESSION['current_perspective']);
             $objectArea = $this->getAreaByPerspId($objectPerspective);
             if ($area && !$area['share_common'] || $objectArea && $objectArea['exclusive']) {
                 $perspectivelib->set_perspective($objectPerspective, true);
                 Zend_OpenId::redirect(Zend_OpenId::selfUrl());
             }
         }
     }
     if ($objectPerspective < 1 && !empty($_SESSION['current_perspective'])) {
         // uncategorised objects
         $area = $this->getAreaByPerspId($_SESSION['current_perspective']);
         if ($area) {
             if (!$area['share_common']) {
                 $perspectivelib->set_perspective($objectPerspective, true);
                 Zend_OpenId::redirect(Zend_OpenId::selfUrl());
             }
         }
     }
 }
 /**
  * Performs check of OpenID identity.
  *
  * This is the first step of OpenID authentication process.
  * On success the function does not return (it does HTTP redirection to
  * server and exits). On failure it returns false.
  *
  * @param bool $immediate enables or disables interaction with user
  * @param string $id OpenID identity
  * @param string $returnTo HTTP URL to redirect response from server to
  * @param string $root HTTP URL to identify consumer on server
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     $this->_setError('');
     if (!Zend_OpenId::normalize($id)) {
         $this->_setError("Normalisation failed");
         return false;
     }
     $claimedId = $id;
     if (!$this->_discovery($id, $server, $version)) {
         $this->_setError("Discovery failed: " . $this->getError());
         return false;
     }
     if (!$this->_associate($server, $version)) {
         $this->_setError("Association failed: " . $this->getError());
         return false;
     }
     if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) {
         /* Use dumb mode */
         unset($handle);
         unset($macFunc);
         unset($secret);
         unset($expires);
     }
     $params = array();
     if ($version >= 2.0) {
         $params['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup';
     $params['openid.identity'] = $id;
     $params['openid.claimed_id'] = $claimedId;
     if ($version <= 2.0) {
         if ($this->_session !== null) {
             $this->_session->identity = $id;
             $this->_session->claimed_id = $claimedId;
         } else {
             if (defined('SID')) {
                 $_SESSION["zend_openid"] = array("identity" => $id, "claimed_id" => $claimedId);
             } else {
                 require_once "Zend/Session/Namespace.php";
                 $this->_session = new Zend_Session_Namespace("zend_openid");
                 $this->_session->identity = $id;
                 $this->_session->claimed_id = $claimedId;
             }
         }
     }
     if (isset($handle)) {
         $params['openid.assoc_handle'] = $handle;
     }
     $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
     if (empty($root)) {
         $root = Zend_OpenId::selfUrl();
         if ($root[strlen($root) - 1] != '/') {
             $root = dirname($root);
         }
     }
     if ($version >= 2.0) {
         $params['openid.realm'] = $root;
     } else {
         $params['openid.trust_root'] = $root;
     }
     if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
         $this->_setError("Extension::prepareRequest failure");
         return false;
     }
     Zend_OpenId::redirect($server, $params, $response);
     return true;
 }
示例#3
0
 /**
  * Perepares information to send back to consumer's authentication request,
  * signs it using shared secret and send back through HTTP redirection
  *
  * @param array $params GET or POST request variables
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 public function respondToConsumer($params, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     $version = 1.1;
     if (isset($params['openid_ns']) && $params['openid_ns'] == Zend_OpenId::NS_2_0) {
         $version = 2.0;
     }
     $ret = array();
     if ($version >= 2.0) {
         $ret['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $ret = $this->_respond($version, $ret, $params, $extensions);
     if (!empty($params['openid_return_to'])) {
         Zend_OpenId::redirect($params['openid_return_to'], $ret, $response);
     }
     return true;
 }
示例#4
0
$dir = realpath(__DIR__ . "/../../..");
set_include_path("{$dir}/incubator/library" . PATH_SEPARATOR . "{$dir}/library" . PATH_SEPARATOR . get_include_path());
/**
 * @see Zend_Auth
 */
require_once "Zend/Auth.php";
/**
 * @see Zend_Auth_Adapter_OpenId
 */
require_once "Zend/Auth/Adapter/OpenId.php";
$status = "";
$auth = Zend_Auth::getInstance();
if (isset($_POST['openid_action']) && $_POST['openid_action'] == "login" && !empty($_POST['openid_identifier']) || isset($_GET['openid_mode']) || isset($_POST['openid_mode'])) {
    $result = $auth->authenticate(new Zend_Auth_Adapter_OpenId(@$_POST['openid_identifier']));
    if ($result->isValid()) {
        Zend_OpenId::redirect(Zend_OpenId::selfURL());
    } else {
        $auth->clearIdentity();
        foreach ($result->getMessages() as $message) {
            $status .= "{$message}<br>\n";
        }
    }
} else {
    if ($auth->hasIdentity()) {
        if (isset($_POST['openid_action']) && $_POST['openid_action'] == "logout") {
            $auth->clearIdentity();
        } else {
            $status = "You are logged-in as " . $auth->getIdentity() . "<br>\n";
        }
    }
}
 /**
  * handle all kinds of openId requests
  * 
  * @return void
  */
 public function openId()
 {
     Tinebase_Core::startCoreSession();
     $server = new Tinebase_OpenId_Provider(null, null, new Tinebase_OpenId_Provider_User_Tine20(), new Tinebase_OpenId_Provider_Storage());
     $server->setOpEndpoint(dirname(Zend_OpenId::selfUrl()) . '/index.php?method=Tinebase.openId');
     // handle openId login form
     if (isset($_POST['openid_action']) && $_POST['openid_action'] === 'login') {
         $server->login($_POST['openid_identifier'], $_POST['password'], $_POST['username']);
         unset($_GET['openid_action']);
         $this->_setJsonKeyCookie();
         Zend_OpenId::redirect(dirname(Zend_OpenId::selfUrl()) . '/index.php', $_GET);
         // display openId login form
     } else {
         if (isset($_GET['openid_action']) && $_GET['openid_action'] === 'login') {
             $view = new Zend_View();
             $view->setScriptPath('Tinebase/views');
             $view->openIdIdentity = $_GET['openid_identity'];
             $view->loginName = $_GET['openid_identity'];
             header('Content-Type: text/html; charset=utf-8');
             echo $view->render('openidLogin.php');
             // handle openId trust form
         } else {
             if (isset($_POST['openid_action']) && $_POST['openid_action'] === 'trust') {
                 if (isset($_POST['allow'])) {
                     if (isset($_POST['forever'])) {
                         $server->allowSite($server->getSiteRoot($_GET));
                     }
                     $server->respondToConsumer($_GET);
                 } else {
                     if (isset($_POST['deny'])) {
                         if (isset($_POST['forever'])) {
                             $server->denySite($server->getSiteRoot($_GET));
                         }
                         Zend_OpenId::redirect($_GET['openid_return_to'], array('openid.mode' => 'cancel'));
                     }
                 }
                 // display openId trust form
             } else {
                 if (isset($_GET['openid_action']) && $_GET['openid_action'] === 'trust') {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Display openId trust screen");
                     }
                     $view = new Zend_View();
                     $view->setScriptPath('Tinebase/views');
                     $view->openIdConsumer = $server->getSiteRoot($_GET);
                     $view->openIdIdentity = $server->getLoggedInUser();
                     header('Content-Type: text/html; charset=utf-8');
                     echo $view->render('openidTrust.php');
                     // handle all other openId requests
                 } else {
                     $result = $server->handle();
                     if (is_string($result)) {
                         echo $result;
                     } elseif ($result !== true) {
                         header('HTTP/1.0 403 Forbidden');
                         return;
                     }
                 }
             }
         }
     }
 }
示例#6
0
    /**
     * testing testRedirect
     *
     */
    public function testRedirect()
    {
        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/", null, $response, 'GET');
        $this->assertSame( 302, $response->getHttpResponseCode() );
        $this->assertSame( array(), $response->getRawHeaders() );
        $headers = $response->getHeaders();
        $this->assertTrue( is_array($headers) );
        $this->assertSame( 1, count($headers) );
        $this->assertTrue( is_array($headers[0]) );
        $this->assertSame( 3, count($headers[0]) );
        $this->assertSame( 'Location', $headers[0]['name'] );
        $this->assertSame( 'http://www.test.com/', $headers[0]['value'] );
        $this->assertSame( true, $headers[0]['replace'] );
        $this->assertSame( '', $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php?a=b", null, $response, 'GET');
        $headers = $response->getHeaders();
        $this->assertSame( 'http://www.test.com/test.php?a=b', $headers[0]['value'] );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b'), $response, 'GET');
        $headers = $response->getHeaders();
        $this->assertSame( 'http://www.test.com/test.php?a=b', $headers[0]['value'] );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b', 'c'=>'d'), $response, 'GET');
        $headers = $response->getHeaders();
        $this->assertSame( 'http://www.test.com/test.php?a=b&c=d', $headers[0]['value'] );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('c'=>'d'), $response, 'GET');
        $headers = $response->getHeaders();
        $this->assertSame( 'http://www.test.com/test.php?a=b&c=d', $headers[0]['value'] );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'x y'), $response, 'GET');
        $headers = $response->getHeaders();
        $this->assertSame( 'http://www.test.com/test.php?a=x+y', $headers[0]['value'] );

        $response = new Zend_OpenId_ResponseHelper(false);
        Zend_OpenId::redirect("http://www.test.com/", null, $response, 'GET');
        $this->assertSame( 200, $response->getHttpResponseCode() );
        $this->assertSame( array(), $response->getRawHeaders() );
        $this->assertSame( array(), $response->getHeaders() );
        $this->assertSame(
            "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/';</script>",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(false);
        Zend_OpenId::redirect("http://www.test.com/test.php?a=b", null, $response, 'GET');
        $this->assertSame(
            "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b';</script>",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(false);
        Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b'), $response, 'GET');
        $this->assertSame(
            "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b';</script>",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(false);
        Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b','c'=>'d'), $response, 'GET');
        $this->assertSame(
            "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b&c=d';</script>",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(false);
        Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('c'=>'d'), $response, 'GET');
        $this->assertSame(
            "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b&c=d';</script>",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(false);
        Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'x y'), $response, 'GET');
        $this->assertSame(
            "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=x+y';</script>",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/", null, $response, 'POST');
        $this->assertSame( 200, $response->getHttpResponseCode() );
        $this->assertSame( array(), $response->getRawHeaders() );
        $this->assertSame( array(), $response->getHeaders() );
        $this->assertSame(
            "<html><body onLoad=\"document.forms[0].submit();\">\n" .
            "<form method=\"POST\" action=\"http://www.test.com/\">\n" .
            "<input type=\"submit\" value=\"Continue OpenID transaction\">\n" .
            "</form></body></html>\n",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('a'=>'b'), $response, 'POST');
        $this->assertSame(
            "<html><body onLoad=\"document.forms[0].submit();\">\n" .
            "<form method=\"POST\" action=\"http://www.test.com/test.php?a=b\">\n" .
            "<input type=\"hidden\" name=\"a\" value=\"b\">\n" .
            "<input type=\"submit\" value=\"Continue OpenID transaction\">\n" .
            "</form></body></html>\n",
            $response->getBody() );

        $response = new Zend_OpenId_ResponseHelper(true);
        Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('a'=>'b','c'=>'d'), $response, 'POST');
        $this->assertSame(
            "<html><body onLoad=\"document.forms[0].submit();\">\n" .
            "<form method=\"POST\" action=\"http://www.test.com/test.php?a=b\">\n" .
            "<input type=\"hidden\" name=\"a\" value=\"b\">\n" .
            "<input type=\"hidden\" name=\"c\" value=\"d\">\n" .
            "<input type=\"submit\" value=\"Continue OpenID transaction\">\n" .
            "</form></body></html>\n",
            $response->getBody() );
    }
示例#7
0
 if ($_POST['openid_action'] == 'trust') {
     if (isset($_GET['openid_return_to'])) {
         $sreg = new Zend_OpenId_Extension_Sreg();
         $sreg->parseResponse($_POST);
         if (isset($_POST['allow'])) {
             if (isset($_POST['forever'])) {
                 $server->allowSite($server->getSiteRoot($_GET), $sreg);
             }
             unset($_GET['openid_action']);
             $server->respondToConsumer($_GET, $sreg);
         } else {
             if (isset($_POST['deny'])) {
                 if (isset($_POST['forever'])) {
                     $server->denySite($server->getSiteRoot($_GET));
                 }
                 Zend_OpenId::redirect($_GET['openid_return_to'], array('openid.mode' => 'cancel'));
             }
         }
     } else {
         if (isset($_POST['allow'])) {
             $server->allowSite($_POST['site']);
             header('Location: ' . $_SERVER['PHP_SELF']);
             exit;
         } else {
             if (isset($_POST['deny'])) {
                 $server->denySite($_POST['site']);
                 header('Location: ' . $_SERVER['PHP_SELF']);
                 exit;
             } else {
                 if (isset($_POST['del'])) {
                     $server->delSite($_POST['site']);
示例#8
0
 /**
  * Performs check of OpenID identity.
  *
  * This is the first step of OpenID authentication process.
  * On success the function does not return (it does HTTP redirection to
  * server and exits). On failure it returns false.
  *
  * @param bool $immediate enables or disables interaction with user
  * @param string $id OpenID identity
  * @param string $returnTo HTTP URL to redirect response from server to
  * @param string $root HTTP URL to identify consumer on server
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     if (!Zend_OpenId::normalize($id)) {
         return false;
     }
     $claimedId = $id;
     if (!$this->_discovery($id, $server, $version)) {
         return false;
     }
     if (!$this->_associate($server, $version)) {
         return false;
     }
     if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) {
         /* Use dumb mode */
         unset($handle);
         unset($macFunc);
         unset($secret);
         unset($expires);
     }
     $params = array();
     if ($version >= 2.0) {
         $params['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup';
     $params['openid.identity'] = $id;
     $params['openid.claimed_id'] = $claimedId;
     if (isset($handle)) {
         $params['openid.assoc_handle'] = $handle;
     }
     $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
     if (empty($root)) {
         $root = dirname(Zend_OpenId::selfUrl());
     }
     if ($version >= 2.0) {
         $params['openid.realm'] = $root;
     } else {
         $params['openid.trust_root'] = $root;
     }
     if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
         return false;
     }
     Zend_OpenId::redirect($server, $params, $response);
     return true;
 }
function wikiplugin_subscribegroup($data, $params)
{
    global $tiki_p_subscribe_groups, $userlib, $user, $smarty;
    static $iSubscribeGroup = 0;
    ++$iSubscribeGroup;
    if (empty($user)) {
        return '';
    }
    if ($tiki_p_subscribe_groups != 'y') {
        return tra('Permission denied');
    }
    extract($params, EXTR_SKIP);
    if (empty($group)) {
        if (!empty($_REQUEST['group'])) {
            $group = $_REQUEST['group'];
        } else {
            return tra('Missing parameter');
        }
    }
    if ($group == 'Anonymous' || $group == 'Registered') {
        return tra('Incorrect param');
    }
    if (!($info = $userlib->get_group_info($group)) || $info['groupName'] != $group) {
        // must have the right case
        return tra('Incorrect param');
    }
    if ($info['userChoice'] != 'y') {
        return tra('Permission denied');
    }
    $groups = $userlib->get_user_groups_inclusion($user);
    $current_defgroup = $userlib->get_user_default_group($user);
    if (!empty($_REQUEST['subscribeGroup']) && !empty($_REQUEST['iSubscribeGroup']) && $_REQUEST['iSubscribeGroup'] == $iSubscribeGroup && $_REQUEST['group'] == $group) {
        if (isset($defgroup) || isset($defgroup_action) || isset($undefgroup) || isset($undefgroup_action)) {
            if ($current_defgroup == $group) {
                $new_group = !empty($undefgroup_group) ? $undefgroup_group : 'Registered';
                $userlib->set_default_group($user, $new_group);
            } else {
                if (!isset($groups[$group])) {
                    $userlib->assign_user_to_group($user, $group);
                }
                $userlib->set_default_group($user, $group);
            }
            if (!empty($params['defgroup_url']) && $params['defgroup_url'] === 'n') {
                Zend_OpenId::redirect(Zend_OpenId::selfUrl());
            } else {
                global $tikiroot;
                Zend_OpenId::redirect($tikiroot);
            }
            die;
        } else {
            if (isset($groups[$group])) {
                $userlib->remove_user_from_group($user, $group);
                unset($groups[$group]);
                if (!empty($postunsubscribe_url)) {
                    header("Location: {$postunsubscribe_url}");
                    die;
                }
            } else {
                $userlib->assign_user_to_group($user, $group);
                $groups[$group] = 'real';
                if (!empty($postsubscribe_url)) {
                    header("Location: {$postsubscribe_url}");
                    die;
                }
            }
        }
    }
    if (isset($undefgroup) || isset($undefgroup_action)) {
        if ($current_defgroup == $group) {
            $text = isset($undefgroup) ? $undefgroup : '';
            if (!isset($undefgroup_action)) {
                $undefgroup_action = tra('OK');
            }
            $smarty->assign('action', $undefgroup_action);
        } else {
            $text = isset($defgroup) ? $defgroup : '';
            if (!isset($defgroup_action)) {
                $defgroup_action = tra('OK');
            }
            $smarty->assign('action', $defgroup_action);
        }
    } else {
        if (isset($groups[$group])) {
            //user already in the group->
            if ($groups[$group] == 'included') {
                return tra('Incorrect param');
            }
            $text = isset($unsubscribe) ? $unsubscribe : tra('Unsubscribe') . '%s';
            if (!isset($unsubscribe_action)) {
                $unsubscribe_action = tra('OK');
            }
            $smarty->assign('action', $unsubscribe_action);
        } else {
            $text = isset($subscribe) ? $subscribe : tra('Subscribe') . '%s';
            if (!isset($subscribe_action)) {
                $subscribe_action = tra('OK');
            }
            $smarty->assign('action', $subscribe_action);
        }
    }
    $smarty->assign('text', sprintf(tra($text), $group));
    $smarty->assign('subscribeGroup', $group);
    $smarty->assign('iSubscribeGroup', $iSubscribeGroup);
    $data = $data . $smarty->fetch('wiki-plugins/wikiplugin_subscribegroup.tpl');
    return $data;
}
示例#10
0
 public function btnLogin_Click($strFormId, $strControlId, $strParameter)
 {
     require_once "Zend/Auth.php";
     require_once "Zend/Auth/Adapter/OpenId.php";
     require_once "Zend/Auth/Storage/NonPersistent.php";
     $this->txtOpenIdUrl->Text = preg_replace('/\\/$/', '', $this->txtOpenIdUrl->Text);
     $status = "";
     $auth = Zend_Auth::getInstance();
     $result = $auth->authenticate(new Zend_Auth_Adapter_OpenId($this->txtOpenIdUrl->Text));
     if ($result->isValid()) {
         Zend_OpenId::redirect(Zend_OpenId::selfURL());
     } else {
         $auth->clearIdentity();
         foreach ($result->getMessages() as $message) {
             $status .= "{$message}<br>\n";
         }
         $this->lblMessage->ForeColor = 'red';
         $this->lblMessage->Text = 'OpenId: ' . $status;
         return false;
     }
 }
 /**
  * Performs check of OpenID identity.
  *
  * This is the first step of OpenID authentication process.
  * On success the function does not return (it does HTTP redirection to
  * server and exits). On failure it returns false.
  *
  * @param bool $immediate enables or disables interaction with user
  * @param string $id OpenID identity
  * @param string $returnTo HTTP URL to redirect response from server to
  * @param string $root HTTP URL to identify consumer on server
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     $this->_setError('');
     if (!Zend_OpenId::normalize($id)) {
         $this->_setError("Normalisation failed");
         return false;
     }
     $claimedId = $id;
     if (!$this->_discovery($id, $server, $version)) {
         $this->_setError("Discovery failed: " . $this->getError());
         return false;
     }
     if (!$this->_associate($server, $version)) {
         $this->_setError("Association failed: " . $this->getError());
         return false;
     }
     if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) {
         /* Use dumb mode */
         unset($handle);
         unset($macFunc);
         unset($secret);
         unset($expires);
     }
     $params = array();
     if ($version >= 2.0) {
         $params['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup';
     $params['openid.identity'] = $id;
     $params['openid.claimed_id'] = $claimedId;
     if ($version <= 2.0) {
         if ($this->_session !== null) {
             $this->_session->identity = $id;
             $this->_session->claimed_id = $claimedId;
             if ($server == 'https://www.google.com/accounts/o8/ud') {
                 $params['openid.identity'] = 'http://specs.openid.net/auth/2.0/identifier_select';
                 $params['openid.claimed_id'] = 'http://specs.openid.net/auth/2.0/identifier_select';
                 $params['openid.ns.ax'] = 'http://openid.net/srv/ax/1.0';
                 $params['openid.ax.mode'] = 'fetch_request';
                 $params['openid.ax.type.email'] = 'http://axschema.org/contact/email';
                 $params['openid.ax.type.country'] = 'http://axschema.org/contact/country/home';
                 $params['openid.ax.type.firstname'] = 'http://axschema.org/namePerson/first';
                 $params['openid.ax.type.lastname'] = 'http://axschema.org/namePerson/last';
                 $params['openid.ax.type.language'] = 'http://axschema.org/pref/language';
                 $params['openid.ax.required'] = 'country,firstname,email,language,lastname';
             }
         } else {
             if (defined('SID')) {
                 $_SESSION["zend_openid"] = array("identity" => $id, "claimed_id" => $claimedId);
             } else {
                 require_once "Zend/Session/Namespace.php";
                 $this->_session = new Zend_Session_Namespace("zend_openid");
                 $this->_session->identity = $id;
                 $this->_session->claimed_id = $claimedId;
             }
         }
     }
     if (isset($handle)) {
         $params['openid.assoc_handle'] = $handle;
     }
     $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
     if (empty($root)) {
         $root = Zend_OpenId::selfUrl();
         if ($root[strlen($root) - 1] != '/') {
             $root = dirname($root);
         }
     }
     if ($version >= 2.0) {
         $params['openid.realm'] = $root;
     } else {
         $params['openid.trust_root'] = $root;
     }
     if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
         $this->_setError("Extension::prepareRequest failure");
         return false;
     }
     Zend_OpenId::redirect($server, $params, $response);
     return true;
 }
 public function trustAction()
 {
     $this->view->title = "Do you trust this website?";
     $server = $this->getServer();
     $this->view->site = $server->getSiteRoot($_GET);
     $this->view->user = $server->getLoggedInUser();
     $userDetails = new Default_Model_UserDetails();
     $sreg = new Zend_OpenId_Extension_Sreg($userDetails->getUserDetailsFromOpenId($server->getLoggedInUser()));
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['openid_action']) && $_POST['openid_action'] === 'trust') {
         if (isset($_POST['allow'])) {
             if (isset($_POST['forever'])) {
                 $server->allowSite($server->getSiteRoot($_GET), $sreg);
             }
             $server->respondToConsumer($_GET, $sreg);
         } else {
             if (isset($_POST['deny'])) {
                 if (isset($_POST['forever'])) {
                     $server->denySite($server->getSiteRoot($_GET));
                 }
                 Zend_OpenId::redirect(urldecode($_GET['openid_return_to']), array('openid.mode' => 'cancel'));
             }
         }
     }
 }