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


PHP common_ensure_session函数代码示例

本文整理汇总了PHP中common_ensure_session函数的典型用法代码示例。如果您正苦于以下问题:PHP common_ensure_session函数的具体用法?PHP common_ensure_session怎么用?PHP common_ensure_session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了common_ensure_session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepare

 /**
  * Prepare page to run
  *
  *
  * @param $args
  * @return string title
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->code = $this->trimmed('code');
     $this->type = $this->trimmed('type');
     if (empty($this->code)) {
         common_ensure_session();
         if (array_key_exists('invitecode', $_SESSION)) {
             $this->code = $_SESSION['invitecode'];
         }
     }
     if (common_config('site', 'inviteonly') && empty($this->code)) {
         $this->clientError(_('Sorry, only invited people can register.'));
         return false;
     }
     if (!empty($this->code)) {
         $this->invite = Invitation::staticGet('code', $this->code);
         if (empty($this->invite)) {
             $this->clientError(_('Sorry, invalid invitation code.'));
             return false;
         }
         // Store this in case we need it
         common_ensure_session();
         $_SESSION['invitecode'] = $this->code;
     }
     return true;
 }
开发者ID:himmelex,项目名称:NTW,代码行数:34,代码来源:register.php

示例2: handle

 function handle($args)
 {
     parent::handle($args);
     if (common_is_real_login()) {
         // TRANS: Client error message trying to log on with OpenID while already logged on.
         $this->clientError(_m('Already logged in.'));
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $provider = common_config('openid', 'trusted_provider');
             if ($provider) {
                 $openid_url = $provider;
                 if (common_config('openid', 'append_username')) {
                     $openid_url .= $this->trimmed('openid_username');
                 }
             } else {
                 $openid_url = $this->trimmed('openid_url');
             }
             oid_assert_allowed($openid_url);
             $rememberme = $this->boolean('rememberme');
             common_ensure_session();
             $_SESSION['openid_rememberme'] = $rememberme;
             $result = oid_authenticate($openid_url, 'finishopenidlogin');
             if (is_string($result)) {
                 # error message
                 unset($_SESSION['openid_rememberme']);
                 $this->showForm($result, $openid_url);
             }
         } else {
             $openid_url = oid_get_last();
             $this->showForm(null, $openid_url);
         }
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:33,代码来源:openidlogin.php

示例3: prepare

 /**
  * Prepare page to run
  *
  *
  * @param $args
  * @return string title
  */
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $this->code = $this->trimmed('code');
     if (empty($this->code)) {
         common_ensure_session();
         if (array_key_exists('invitecode', $_SESSION)) {
             $this->code = $_SESSION['invitecode'];
         }
     }
     if (common_config('site', 'inviteonly') && empty($this->code)) {
         // TRANS: Client error displayed when trying to register to an invite-only site without an invitation.
         $this->clientError(_('Sorry, only invited people can register.'));
     }
     if (!empty($this->code)) {
         $this->invite = Invitation::getKV('code', $this->code);
         if (!$this->invite instanceof Invitation) {
             // TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation.
             $this->clientError(_('Sorry, invalid invitation code.'));
         }
         // Store this in case we need it
         common_ensure_session();
         $_SESSION['invitecode'] = $this->code;
     }
     return true;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:33,代码来源:register.php

示例4: handle

 function handle($args)
 {
     parent::handle($args);
     if (common_is_real_login()) {
         $this->clientError(_('Already logged in.'));
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $openid_url = $this->trimmed('openid_url');
             # CSRF protection
             $token = $this->trimmed('token');
             if (!$token || $token != common_session_token()) {
                 $this->showForm(_('There was a problem with your session token. Try again, please.'), $openid_url);
                 return;
             }
             $rememberme = $this->boolean('rememberme');
             common_ensure_session();
             $_SESSION['openid_rememberme'] = $rememberme;
             $result = oid_authenticate($openid_url, 'finishopenidlogin');
             if (is_string($result)) {
                 # error message
                 unset($_SESSION['openid_rememberme']);
                 $this->showForm($result, $openid_url);
             }
         } else {
             $openid_url = oid_get_last();
             $this->showForm(null, $openid_url);
         }
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:29,代码来源:openidlogin.php

示例5: handle

 /**
  * Handle input, produce output
  *
  * Switches on request method; either shows the form or handles its input.
  *
  * @param array $args $_REQUEST data
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (common_is_real_login()) {
         $this->clientError(_('Already logged in.'));
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->checkLogin();
         } else {
             common_ensure_session();
             $this->showForm();
         }
     }
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:23,代码来源:login.php

示例6: prepare

 function prepare($args)
 {
     parent::prepare($args);
     common_ensure_session();
     $this->user = common_current_user();
     if (empty($this->user)) {
         /* Go log in, and then come back. */
         common_set_returnto($_SERVER['REQUEST_URI']);
         common_redirect(common_local_url('login'));
         return;
     }
     $this->trust_root = $_SESSION['openid_trust_root'];
     $this->allowUrl = $_SESSION['openid_allow_url'];
     $this->denyUrl = $_SESSION['openid_deny_url'];
     if (empty($this->trust_root) || empty($this->allowUrl) || empty($this->denyUrl)) {
         $this->clientError(_m('This page should only be reached during OpenID processing, not directly.'));
         return;
     }
     return true;
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:20,代码来源:openidtrust.php

示例7: handle

 function handle($args)
 {
     parent::handle($args);
     if (common_is_real_login()) {
         // TRANS: Client error message trying to log on with OpenID while already logged on.
         $this->clientError(_m('Already logged in.'));
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $provider = common_config('openid', 'trusted_provider');
             if ($provider) {
                 $openid_url = $provider;
                 if (common_config('openid', 'append_username')) {
                     $openid_url .= $this->trimmed('openid_username');
                 }
             } else {
                 $openid_url = $this->trimmed('openid_url');
             }
             oid_assert_allowed($openid_url);
             # CSRF protection
             $token = $this->trimmed('token');
             if (!$token || $token != common_session_token()) {
                 // TRANS: Message given when there is a problem with the user's session token.
                 $this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url);
                 return;
             }
             $rememberme = $this->boolean('rememberme');
             common_ensure_session();
             $_SESSION['openid_rememberme'] = $rememberme;
             $result = oid_authenticate($openid_url, 'finishopenidlogin');
             if (is_string($result)) {
                 # error message
                 unset($_SESSION['openid_rememberme']);
                 $this->showForm($result, $openid_url);
             }
         } else {
             $openid_url = oid_get_last();
             $this->showForm(null, $openid_url);
         }
     }
 }
开发者ID:Br3nda,项目名称:StatusNet,代码行数:40,代码来源:openidlogin.php

示例8: oid_authenticate

function oid_authenticate($openid_url, $returnto, $immediate = false)
{
    $consumer = oid_consumer();
    if (!$consumer) {
        common_server_error(_m('Cannot instantiate OpenID consumer object.'));
        return false;
    }
    common_ensure_session();
    $auth_request = $consumer->begin($openid_url);
    // Handle failure status return values.
    if (!$auth_request) {
        return _m('Not a valid OpenID.');
    } else {
        if (Auth_OpenID::isFailure($auth_request)) {
            return sprintf(_m('OpenID failure: %s'), $auth_request->message);
        }
    }
    $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname', 'language', 'timezone', 'postcode', 'country'));
    if ($sreg_request) {
        $auth_request->addExtension($sreg_request);
    }
    $trust_root = common_root_url(true);
    $process_url = common_local_url($returnto);
    if ($auth_request->shouldSendRedirect()) {
        $redirect_url = $auth_request->redirectURL($trust_root, $process_url, $immediate);
        if (!$redirect_url) {
        } else {
            if (Auth_OpenID::isFailure($redirect_url)) {
                return sprintf(_m('Could not redirect to server: %s'), $redirect_url->message);
            } else {
                common_redirect($redirect_url, 303);
            }
        }
    } else {
        // Generate form markup and render it.
        $form_id = 'openid_message';
        $form_html = $auth_request->formMarkup($trust_root, $process_url, $immediate, array('id' => $form_id));
        # XXX: This is cheap, but things choke if we don't escape ampersands
        # in the HTML attributes
        $form_html = preg_replace('/&/', '&', $form_html);
        // Display an error if the form markup couldn't be generated;
        // otherwise, render the HTML.
        if (Auth_OpenID::isFailure($form_html)) {
            common_server_error(sprintf(_m('Could not create OpenID form: %s'), $form_html->message));
        } else {
            $action = new AutosubmitAction();
            // see below
            $action->form_html = $form_html;
            $action->form_id = $form_id;
            $action->prepare(array('action' => 'autosubmit'));
            $action->handle(array('action' => 'autosubmit'));
        }
    }
}
开发者ID:himmelex,项目名称:NTW,代码行数:54,代码来源:openid.php

示例9: setLoginUser

 function setLoginUser($user)
 {
     if (common_is_real_login()) {
         $this->logoutWeb();
     }
     common_ensure_session();
     // success!
     if (!common_set_user($user)) {
         // TRANS: Server error displayed when during login a server error occurs.
         $this->serverError(_('Error setting user. You are probably not authorized.'));
         return;
     }
     common_real_login(true);
 }
开发者ID:jianoll,项目名称:SpeakEnglish_Server,代码行数:14,代码来源:apiaccountbindplatform.php

示例10: prepare

 /**
  * Prepare page to run
  *
  *
  * @param $args
  * @return string title
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->code = $this->trimmed('code');
     // @todo this check should really be in index.php for all sensitive actions
     $ssl = common_config('site', 'ssl');
     if (empty($_SERVER['HTTPS']) && ($ssl == 'always' || $ssl == 'sometimes')) {
         common_redirect(common_local_url('register'));
         // exit
     }
     if (empty($this->code)) {
         common_ensure_session();
         if (array_key_exists('invitecode', $_SESSION)) {
             $this->code = $_SESSION['invitecode'];
         }
     }
     if (common_config('site', 'inviteonly') && empty($this->code)) {
         $this->clientError(_('Sorry, only invited people can register.'));
         return false;
     }
     if (!empty($this->code)) {
         $this->invite = Invitation::staticGet('code', $this->code);
         if (empty($this->invite)) {
             $this->clientError(_('Sorry, invalid invitation code.'));
             return false;
         }
         // Store this in case we need it
         common_ensure_session();
         $_SESSION['invitecode'] = $this->code;
     }
     return true;
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:39,代码来源:register.php

示例11: oid_authenticate

function oid_authenticate($openid_url, $returnto, $immediate = false)
{
    $consumer = oid_consumer();
    if (!$consumer) {
        // TRANS: OpenID plugin server error.
        common_server_error(_m('Cannot instantiate OpenID consumer object.'));
        return false;
    }
    common_ensure_session();
    $auth_request = $consumer->begin($openid_url);
    // Handle failure status return values.
    if (!$auth_request) {
        common_log(LOG_ERR, __METHOD__ . ": mystery fail contacting {$openid_url}");
        // TRANS: OpenID plugin message. Given when an OpenID is not valid.
        return _m('Not a valid OpenID.');
    } else {
        if (Auth_OpenID::isFailure($auth_request)) {
            common_log(LOG_ERR, __METHOD__ . ": OpenID fail to {$openid_url}: {$auth_request->message}");
            // TRANS: OpenID plugin server error. Given when the OpenID authentication request fails.
            // TRANS: %s is the failure message.
            return sprintf(_m('OpenID failure: %s'), $auth_request->message);
        }
    }
    $sreg_request = Auth_OpenID_SRegRequest::build(array(), array('nickname', 'email', 'fullname', 'language', 'timezone', 'postcode', 'country'));
    if ($sreg_request) {
        $auth_request->addExtension($sreg_request);
    }
    $requiredTeam = common_config('openid', 'required_team');
    if ($requiredTeam) {
        // LaunchPad OpenID extension
        $team_request = new Auth_OpenID_TeamsRequest(array($requiredTeam));
        if ($team_request) {
            $auth_request->addExtension($team_request);
        }
    }
    $trust_root = common_root_url(true);
    $process_url = common_local_url($returnto);
    // Net::OpenID::Server as used on LiveJournal appears to incorrectly
    // reject POST requests for data submissions that OpenID 1.1 specs
    // as GET, although 2.0 allows them:
    // https://rt.cpan.org/Public/Bug/Display.html?id=42202
    //
    // Our OpenID libraries would have switched in the redirect automatically
    // if it were detecting 1.1 compatibility mode, however the server is
    // advertising itself as 2.0-compatible, so we got switched to the POST.
    //
    // Since the GET should always work anyway, we'll just take out the
    // autosubmitter for now.
    //
    //if ($auth_request->shouldSendRedirect()) {
    $redirect_url = $auth_request->redirectURL($trust_root, $process_url, $immediate);
    if (!$redirect_url) {
    } else {
        if (Auth_OpenID::isFailure($redirect_url)) {
            // TRANS: OpenID plugin server error. Given when the OpenID authentication request cannot be redirected.
            // TRANS: %s is the failure message.
            return sprintf(_m('Could not redirect to server: %s'), $redirect_url->message);
        } else {
            common_redirect($redirect_url, 303);
        }
    }
    /*
    } else {
        // Generate form markup and render it.
        $form_id = 'openid_message';
        $form_html = $auth_request->formMarkup($trust_root, $process_url,
                                               $immediate, array('id' => $form_id));
    
        # XXX: This is cheap, but things choke if we don't escape ampersands
        # in the HTML attributes
    
        $form_html = preg_replace('/&/', '&', $form_html);
    
        // Display an error if the form markup couldn't be generated;
        // otherwise, render the HTML.
        if (Auth_OpenID::isFailure($form_html)) {
            // TRANS: OpenID plugin server error if the form markup could not be generated.
            // TRANS: %s is the failure message.
            common_server_error(sprintf(_m('Could not create OpenID form: %s'), $form_html->message));
        } else {
            $action = new AutosubmitAction(); // see below
            $action->form_html = $form_html;
            $action->form_id = $form_id;
            $action->prepare(array('action' => 'autosubmit'));
            $action->handle(array('action' => 'autosubmit'));
        }
    }
    */
}
开发者ID:Br3nda,项目名称:statusnet-debian,代码行数:89,代码来源:openid.php

示例12: onArgsInitialize

 function onArgsInitialize()
 {
     // We always want a session because we're tracking anon users
     common_ensure_session();
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:5,代码来源:AnonymousFavePlugin.php

示例13: handle

 /**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $nickname = $this->trimmed('nickname');
     $email = $this->trimmed('email');
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $bio = $this->trimmed('bio');
     $location = $this->trimmed('location');
     // We don't trim these... whitespace is OK in a password!
     $password = $this->arg('password');
     $confirm = $this->arg('confirm');
     if (empty($this->code)) {
         common_ensure_session();
         if (array_key_exists('invitecode', $_SESSION)) {
             $this->code = $_SESSION['invitecode'];
         }
     }
     if (common_config('site', 'inviteonly') && empty($this->code)) {
         // TRANS: Client error displayed when trying to register to an invite-only site without an invitation.
         $this->clientError(_('Sorry, only invited people can register.'), 401);
     }
     if (!empty($this->code)) {
         $this->invite = Invitation::getKV('code', $this->code);
         if (empty($this->invite)) {
             // TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation.
             $this->clientError(_('Sorry, invalid invitation code.'), 401);
         }
         // Store this in case we need it
         common_ensure_session();
         $_SESSION['invitecode'] = $this->code;
     }
     // Input scrubbing
     try {
         $nickname = Nickname::normalize($nickname, true);
     } catch (NicknameException $e) {
         // clientError handles Api exceptions with various formats and stuff
         $this->clientError($e->getMessage(), $e->getCode());
     }
     $email = common_canonical_email($email);
     if ($email && !Validate::email($email, common_config('email', 'check_domain'))) {
         // TRANS: Form validation error displayed when trying to register without a valid e-mail address.
         $this->clientError(_('Not a valid email address.'), 400);
     } else {
         if ($this->emailExists($email)) {
             // TRANS: Form validation error displayed when trying to register with an already registered e-mail address.
             $this->clientError(_('Email address already exists.'), 400);
         } else {
             if (!is_null($homepage) && strlen($homepage) > 0 && !common_valid_http_url($homepage)) {
                 // TRANS: Form validation error displayed when trying to register with an invalid homepage URL.
                 $this->clientError(_('Homepage is not a valid URL.'), 400);
             } else {
                 if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                     // TRANS: Form validation error displayed when trying to register with a too long full name.
                     $this->clientError(_('Full name is too long (maximum 255 characters).'), 400);
                 } else {
                     if (Profile::bioTooLong($bio)) {
                         // TRANS: Form validation error on registration page when providing too long a bio text.
                         // TRANS: %d is the maximum number of characters for bio; used for plural.
                         $this->clientError(sprintf(_m('Bio is too long (maximum %d character).', 'Bio is too long (maximum %d characters).', Profile::maxBio()), Profile::maxBio()), 400);
                     } else {
                         if (!is_null($location) && mb_strlen($location) > 255) {
                             // TRANS: Form validation error displayed when trying to register with a too long location.
                             $this->clientError(_('Location is too long (maximum 255 characters).'), 400);
                         } else {
                             if (strlen($password) < 6) {
                                 // TRANS: Form validation error displayed when trying to register with too short a password.
                                 $this->clientError(_('Password must be 6 or more characters.'), 400);
                             } else {
                                 if ($password != $confirm) {
                                     // TRANS: Form validation error displayed when trying to register with non-matching passwords.
                                     $this->clientError(_('Passwords do not match.'), 400);
                                 } else {
                                     // annoy spammers
                                     sleep(7);
                                     try {
                                         $user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email, 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 'location' => $location, 'code' => $this->code));
                                         Event::handle('EndRegistrationTry', array($this));
                                         $this->initDocument('json');
                                         $this->showJsonObjects($this->twitterUserArray($user->getProfile()));
                                         $this->endDocument('json');
                                     } catch (Exception $e) {
                                         $this->clientError($e->getMessage(), 400);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:100,代码来源:apiaccountregister.php

示例14: handle

 /**
  * Handle input, produce output
  *
  * Switches on request method; either shows the form or handles its input.
  *
  * @param array $args $_REQUEST data
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (common_is_real_login()) {
         $user = common_current_user();
         common_redirect(common_local_url('all', array('nickname' => $user->nickname)), 307);
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->checkLogin();
         } else {
             common_ensure_session();
             $this->showForm();
         }
     }
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:24,代码来源:login.php

示例15: common_session_token

function common_session_token()
{
    common_ensure_session();
    if (!array_key_exists('token', $_SESSION)) {
        $_SESSION['token'] = common_good_rand(64);
    }
    return $_SESSION['token'];
}
开发者ID:himmelex,项目名称:NTW,代码行数:8,代码来源:util.php


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