當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。