本文整理汇总了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());
}
}
示例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 ..
}
示例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]);
}
}
示例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]);
}
示例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());
}
}