/**
  * 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 {
             if ($account->user->esActivo) {
                 Yii::$app->user->login($account->user, $this->module->rememberFor);
                 $this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
             }
         }
     } else {
         $this->action->successUrl = $account->getConnectUrl();
     }
 }
Example #2
0
 /**
  * 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();
     }
 }
Example #3
0
 /**
  * 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)
 {
     $wechatAccount = $this->finder->findAccount()->byWechatClient($client)->one();
     $account = $this->finder->findAccount()->byClient($client)->one();
     if ($account === null) {
         if ($client->getId() == 'weixin_backend' && $wechatAccount === null) {
             echo '后台禁止用户注册, 请先在微信端登录';
             exit;
         } else {
             $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();
     }
 }