本文整理匯總了PHP中dektrium\user\Finder::findAccount方法的典型用法代碼示例。如果您正苦於以下問題:PHP Finder::findAccount方法的具體用法?PHP Finder::findAccount怎麽用?PHP Finder::findAccount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dektrium\user\Finder
的用法示例。
在下文中一共展示了Finder::findAccount方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionConnect
/**
* Displays page where user can create new account that will be connected to social account.
*
* @param string $code
*
* @return string
* @throws NotFoundHttpException
*/
public function actionConnect($code)
{
$account = $this->finder->findAccount()->byCode($code)->one();
if ($account === null || $account->getIsConnected()) {
throw new NotFoundHttpException();
}
/**
* xiaoma update;
*/
$accountData = json_decode($account->data);
switch ($account->provider) {
case 'qq':
$avatar = $accountData->figureurl;
$nickname = $accountData->nickname;
break;
case 'sina':
$avatar = $accountData->profile_image_url;
$nickname = $accountData->name;
break;
case 'github':
$avatar = $accountData->avatar_url;
$nickname = $accountData->login;
break;
default:
$avatar = $nickname = '';
}
/** @var User $user */
$user = Yii::createObject(['class' => User::className(), 'scenario' => 'connect', 'username' => $account->username, 'email' => $account->email]);
if ($user->load(Yii::$app->request->post()) && $user->create()) {
$account->connect($user);
Yii::$app->user->login($user, $this->module->rememberFor);
return $this->goBack();
}
return $this->render('connect', ['model' => $user, 'account' => $account, 'avatar' => $avatar, 'nickname' => $nickname, 'provider' => $account->provider]);
}
示例2: actionConnect
/**
* Displays page where user can create new account that will be connected to social account.
*
* @param string $code
*
* @return string
* @throws NotFoundHttpException
*/
public function actionConnect($code)
{
$account = $this->finder->findAccount()->byCode($code)->one();
if ($account === null || $account->getIsConnected()) {
throw new NotFoundHttpException();
}
/** @var User $user */
$user = Yii::createObject(['class' => User::className(), 'scenario' => 'connect', 'username' => $account->username, 'email' => $account->email]);
if ($user->load(Yii::$app->request->post()) && $user->create()) {
$account->connect($user);
Yii::$app->user->login($user, $this->module->rememberFor);
return $this->goBack();
}
return $this->render('connect', ['model' => $user, 'account' => $account]);
}
示例3: authenticate
/**
* Tries to authenticate user via social network. If user has already used
* this network's account, he will be logged in. Otherwise, it will try
* to create new user account.
*
* @param ClientInterface $client
*/
public function authenticate(ClientInterface $client)
{
$account = $this->finder->findAccount()->byClient($client)->one();
if (!$this->module->enableRegistration && ($account === null || $account->user === null)) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'Registration on this website is disabled'));
$this->action->successUrl = Url::to(['/user/security/login']);
return;
}
if ($account === null) {
/** @var Account $account */
$accountObj = Yii::createObject(Account::className());
$account = $accountObj::create($client);
}
$event = $this->getAuthEvent($account, $client);
$this->trigger(self::EVENT_BEFORE_AUTHENTICATE, $event);
if ($account->user instanceof User) {
if ($account->user->isBlocked) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'Your account has been blocked.'));
$this->action->successUrl = Url::to(['/user/security/login']);
} else {
Yii::$app->user->login($account->user, $this->module->rememberFor);
$this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
}
} else {
$this->action->successUrl = $account->getConnectUrl();
}
$this->trigger(self::EVENT_AFTER_AUTHENTICATE, $event);
}
示例4: actionDisconnect
/**
* Disconnects a network account from user.
*
* @param int $id
*
* @return \yii\web\Response
* @throws \yii\web\NotFoundHttpException
* @throws \yii\web\ForbiddenHttpException
*/
public function actionDisconnect($id)
{
$account = $this->finder->findAccount()->byId($id)->one();
if ($account === null) {
throw new NotFoundHttpException();
}
if ($account->user_id != Yii::$app->user->id) {
throw new ForbiddenHttpException();
}
$account->delete();
return $this->redirect(['networks']);
}
示例5: authenticate
/**
* Tries to authenticate user via social network. If user has already used
* this network's account, he will be logged in. Otherwise, it will try
* to create new user account.
*
* @param ClientInterface $client
*/
public function authenticate(ClientInterface $client)
{
$account = $this->finder->findAccount()->byClient($client)->one();
if ($account === null) {
$account = Account::create($client);
}
if ($account->user instanceof User) {
Yii::$app->user->login($account->user, $this->module->rememberFor);
$this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
} else {
$this->action->successUrl = $account->getConnectUrl();
}
}
示例6: actionDisconnect
/**
* Disconnects a network account from user.
*
* @param int $id
*
* @return \yii\web\Response
* @throws \yii\web\NotFoundHttpException
* @throws \yii\web\ForbiddenHttpException
*/
public function actionDisconnect($id)
{
$account = $this->finder->findAccount()->byId($id)->one();
if ($account === null) {
throw new NotFoundHttpException();
}
if ($account->user_id != Yii::$app->user->id) {
throw new ForbiddenHttpException();
}
$event = $this->getConnectEvent($account, $account->user);
$this->trigger(self::EVENT_BEFORE_DISCONNECT, $event);
$account->delete();
$this->trigger(self::EVENT_AFTER_DISCONNECT, $event);
return $this->redirect(['networks']);
}
示例7: authenticate
/**
* Tries to authenticate user via social network. If user has already used
* this network's account, he will be logged in. Otherwise, it will try
* to create new user account.
*
* @param ClientInterface $client
*/
public function authenticate(ClientInterface $client)
{
$account = $this->finder->findAccount()->byClient($client)->one();
if ($account === null) {
$account = Account::create($client);
}
if ($account->user instanceof User) {
if ($account->user->isBlocked) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'Your account has been blocked.'));
$this->action->successUrl = Url::to(['/user/security/login']);
} else {
Yii::$app->user->login($account->user, $this->module->rememberFor);
$this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
}
} else {
$this->action->successUrl = $account->getConnectUrl();
}
}