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


PHP UserIdentity::load方法代码示例

本文整理汇总了PHP中UserIdentity::load方法的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity::load方法的具体用法?PHP UserIdentity::load怎么用?PHP UserIdentity::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserIdentity的用法示例。


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

示例1: actionIndex

 /**
  * Action: Index
  *
  * @access public
  * @return void
  */
 public function actionIndex()
 {
     // Only go ahead with the logout if the end-user is logged in, if the end-user is a guest then we can skip
     // the entire logout procedure, and skip to the redirect back home!
     if (!Yii::app()->user->isGuest) {
         // Has the "authUser" persistent state been set, which contains the user's true authenticated ID, and is
         // it different to the user's current ID?
         if (is_int(Yii::app()->user->getState('authUser')) && Yii::app()->user->getState('authUser') != Yii::app()->user->getState('id') && is_object($authUser = User::model()->findByPk(Yii::app()->user->getState('authUser')))) {
             $model = new \application\model\form\Logout();
             $form = new CForm('application.forms.logout', $model);
             if ($form->submitted() && $form->validate()) {
                 // Has the user opted to switch back to their original account?
                 if ($model->switch) {
                     // Create a new user identity instance, but since we aren't going to use any credentials to
                     // authenticate the user, we can just pass in empty strings.
                     $identity = new UserIdentity('', '');
                     // Attempt to load the identitiy of the user defined by the ID in the "authUser" persistent
                     // state.
                     if ($identity->load(Yii::app()->user->getState('authUser')) && Yii::app()->user->login($identity)) {
                         // The original user account was successfully logged in, redirect to the homepage.
                         $this->redirect(Yii::app()->homeUrl);
                     } else {
                         throw new CException(Yii::t('application', 'An error occured whilst attempting to load your original user account. You have been logged out for security reasons.'));
                     }
                 } else {
                     // Log out the current user. Pass bool(false) as an argument to prevent the entire session
                     // from being destroyed, and instead only delete the persistent states that were created
                     // specifically for the user logged in. An example of why this is the behaviour we want is
                     // storing the language selection in a session - if the website visitor selects French as
                     // the language to view the website in (regardless of whether this functionality is actually
                     // implemented), we don't want that session variable destroyed causing the entire website to
                     // switch back to the default language of English just because the user wanted to log out.
                     // Personally I believe that this should be the default behaviour, but it's not.
                     Yii::app()->user->logout(false);
                     $this->redirect(Yii::app()->homeUrl);
                 }
             }
             // Render the logout page, so that the end-user may be presented with a choice instead of
             // automatically logged out (as if the default).
             $this->render('index', array('form' => $form, 'displayName' => $authUser->displayName));
             // End the application here to prevent any redirection.
             Yii::app()->end();
         } else {
             // Log out the current user. Please refer to the lengthy explaination earlier in this method for why
             // we pass bool(false).
             Yii::app()->user->logout(false);
         }
     }
     // We don't want the user to stay on the logout page. Redirect them back to the homepage.
     $this->redirect(Yii::app()->homeUrl);
 }
开发者ID:mynameiszanders,项目名称:yiiskeleton,代码行数:57,代码来源:LogoutController.php


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