Пример #1
0
 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 ..
 }
Пример #2
0
 public function actionLogin()
 {
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         /** @var $eauth \nodge\eauth\ServiceBase */
         $eauth = Yii::$app->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 ($model->load(Yii::$app->request->post()) and $model->login()) {
         return $this->goBack();
     } else {
         $this->layout = '/login';
         return $this->render('login', ['model' => $model]);
     }
 }