本文整理汇总了PHP中frontend\models\User::findByEAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findByEAuth方法的具体用法?PHP User::findByEAuth怎么用?PHP User::findByEAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frontend\models\User
的用法示例。
在下文中一共展示了User::findByEAuth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionLogin
/**
* Logs in a user.
*
* @return mixed
*/
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->redirect(['user-panel/settings']);
}
$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();
$this->redirect($eauth->getCancelUrl());
}
} else {
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', ['model' => $model]);
}
}
}