/** * Users authorization via services. */ 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('/'); $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login')); try { if ($eauth->authenticate()) { $serviceUserClass = Yii::$app->getModule('eauth')->serviceUserClass; $identity = $serviceUserClass::findByEAuth($eauth); if (!$identity) { $identity = new ServiceUser(); if (!$identity->register($eauth)) { $identity = null; } } else { 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->redirect($eauth->getCancelUrl()); } } }
/** * User updating. * * @param string $id user primary key (service_name:service_user_id) * * @throws HttpException */ public function actionUpdate($id) { list($service_name, $service_user_id) = explode(':', $id); $model = ServiceUser::findIdentity(['service_name' => $service_name, 'service_user_id' => $service_user_id]); if (!$model) { throw new HttpException(); } return $this->render('update', compact('model')); }