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


PHP User::findByEAuth方法代码示例

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


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

示例1: actionLogin

 /**
  * Logs in a user.
  *
  * @return mixed
  */
 public function actionLogin()
 {
     /** @var $eauth \nodge\eauth\ServiceBase */
     $eauth = Yii::$app->get('eauth')->getIdentity('steam');
     $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
     $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
     try {
         if ($eauth->authenticate()) {
             $identity = User::findByEAuth($eauth);
             $user = User::findOne(['steamid' => $identity->steamid]);
             if (!$user) {
                 $user = new User();
             }
             $user->username = $identity->username;
             $user->steamid = $identity->steamid;
             $user->profile_url = $identity->profile_url;
             $user->avatar = $identity->avatar;
             $user->avatar_md = $identity->avatar_md;
             $user->avatar_lg = $identity->avatar_lg;
             $user->generateAuthKey();
             $user->save();
             Yii::$app->getUser()->login($identity);
             $eauth->redirect();
         } else {
             $eauth->cancel();
         }
     } catch (ErrorException $e) {
         Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
         $eauth->redirect($eauth->getCancelUrl());
     }
 }
开发者ID:CyanoFresh,项目名称:Yii2-steam-login,代码行数:36,代码来源:SiteController.php

示例2: actionLogin

 /**
  * Logs in a user.
  *
  * @return mixed
  */
 public function actionLogin()
 {
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         /** @var $eauth \nodge\eauth\ServiceBase */
         $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
         $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
         $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
         try {
             if ($eauth->authenticate()) {
                 //                  var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit;
                 $identity = User::findByEAuth($eauth);
                 Yii::$app->getUser()->login($identity);
                 // special redirect with closing popup window
                 $eauth->redirect();
             } else {
                 // close popup window and redirect to cancelUrl
                 $eauth->cancel();
             }
         } catch (\nodge\eauth\ErrorException $e) {
             // save error to show it later
             Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
             // close popup window and redirect to cancelUrl
             //              $eauth->cancel();
             $eauth->redirect($eauth->getCancelUrl());
         }
     }
     // default authorization code through login/password ..
 }
开发者ID:h11Nox,项目名称:slug,代码行数:34,代码来源:SiteController.php

示例3: actionLogin

 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         /** @var $eauth \nodge\eauth\ServiceBase */
         $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
         $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
         $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
         try {
             if ($eauth->authenticate()) {
                 $identity = User::findByEAuth($eauth);
                 Yii::$app->getUser()->login($identity);
                 // special redirect with closing popup window
                 $eauth->redirect();
             } else {
                 // close popup window and redirect to cancelUrl
                 $eauth->cancel();
             }
         } catch (\nodge\eauth\ErrorException $e) {
             // save error to show it later
             Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
             // close popup window and redirect to cancelUrl
             //              $eauth->cancel();
             $eauth->redirect($eauth->getCancelUrl());
         }
     } elseif ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack(Yii::$app->homeUrl);
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
开发者ID:KPEMATOP,项目名称:findspree_old,代码行数:35,代码来源:SiteController.php

示例4: actionLogin

 public function actionLogin()
 {
     $this->layout = '/blog';
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         /** @var $eauth \nodge\eauth\ServiceBase */
         $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
         $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
         $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
         try {
             if ($eauth->authenticate()) {
                 //var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit;
                 $identity = User::findByEAuth($eauth);
                 Yii::$app->getUser()->login($identity);
                 // special redirect with closing popup window
                 $eauth->redirect();
             } else {
                 // close popup window and redirect to cancelUrl
                 $eauth->cancel();
             }
         } catch (\nodge\eauth\ErrorException $e) {
             // save error to show it later
             Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
             // close popup window and redirect to cancelUrl
             //              $eauth->cancel();
             $eauth->redirect($eauth->getCancelUrl());
         }
     }
     $model = new LoginForm();
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $model->load(Yii::$app->request->post());
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->login();
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model]);
 }
开发者ID:kotmonstr,项目名称:kotmonstr,代码行数:43,代码来源:DefaultController.php

示例5: loginByEAuth

 /**
  * @param $serviceName
  * @param bool $auth
  * @throws \yii\base\InvalidConfigException
  */
 public static function loginByEAuth($serviceName, $auth = true)
 {
     /** @var \nodge\eauth\ServiceBase $eauth */
     $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
     try {
         if ($eauth->authenticate()) {
             $identity = User::findByEAuth($eauth);
             if ($auth) {
                 Yii::$app->getUser()->login($identity);
             }
             $eauth->redirect();
         } else {
             $eauth->cancel(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
         }
     } catch (ErrorException $e) {
         Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
         $eauth->redirect($eauth->getCancelUrl());
     }
 }
开发者ID:darkffh,项目名称:yii2-lowbase,代码行数:24,代码来源:User.php


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