AuthChoice.php 991 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: NODELOG
  5. * DateTime: 2017/3/20 15:20
  6. * Description:
  7. */
  8. namespace common\modules\user\widgets;
  9. use common\modules\user\models\Auth;
  10. use Yii;
  11. use yii\authclient\ClientInterface;
  12. class AuthChoice extends \yii\authclient\widgets\AuthChoice
  13. {
  14. public function run()
  15. {
  16. list(, $url) = Yii::$app->assetManager->publish(__DIR__ . '/static');
  17. Yii::$app->view->registerCss(<<<CSS
  18. .auth-icon.QQ {
  19. background: url({$url}/qq.png) no-repeat;
  20. background-size: 32px 32px;
  21. }
  22. .auth-icon.weibo {
  23. background: url({$url}/weibo.png) no-repeat;
  24. background-size: 32px 32px;
  25. }
  26. .auth-icon.weixin {
  27. background: url({$url}/weixin.png) no-repeat;
  28. background-size: 32px 32px;
  29. }
  30. CSS
  31. );
  32. return parent::run();
  33. }
  34. public function isConnected(ClientInterface $client)
  35. {
  36. return Auth::find()->where(['user_id' => \Yii::$app->user->id])->andWhere(['source' => $client->getId()])->exists();
  37. }
  38. }