fix views
This commit is contained in:
55
lib/User/Widget/ConnectWidget.php
Normal file
55
lib/User/Widget/ConnectWidget.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Da\User\Widget;
|
||||
|
||||
|
||||
use Yii;
|
||||
use yii\authclient\ClientInterface;
|
||||
use yii\authclient\widgets\AuthChoice;
|
||||
use yii\authclient\widgets\AuthChoiceAsset;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
|
||||
class ConnectWidget extends AuthChoice
|
||||
{
|
||||
/**
|
||||
* @var array|null An array of user's accounts
|
||||
*/
|
||||
public $accounts;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
AuthChoiceAsset::register(Yii::$app->view);
|
||||
if ($this->popupMode) {
|
||||
Yii::$app->view->registerJs("\$('#" . $this->getId() . "').authchoice();");
|
||||
}
|
||||
$this->options['id'] = $this->getId();
|
||||
echo Html::beginTag('div', $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function createClientUrl($provider)
|
||||
{
|
||||
if ($this->isConnected($provider)) {
|
||||
return Url::to(['/user/settings/disconnect', 'id' => $this->accounts[$provider->getId()]->id]);
|
||||
} else {
|
||||
return parent::createClientUrl($provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if provider already connected to user.
|
||||
*
|
||||
* @param ClientInterface $provider
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConnected(ClientInterface $provider)
|
||||
{
|
||||
return $this->accounts != null && isset($this->accounts[$provider->getId()]);
|
||||
}
|
||||
}
|
||||
21
lib/User/Widget/LoginWidget.php
Normal file
21
lib/User/Widget/LoginWidget.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Da\User\Widget;
|
||||
|
||||
use Da\User\Form\LoginForm;
|
||||
use Yii;
|
||||
use yii\base\Widget;
|
||||
|
||||
class LoginWidget extends Widget
|
||||
{
|
||||
public $validate = true;
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->render(
|
||||
'login',
|
||||
[
|
||||
'model' => Yii::createObject(LoginForm::class)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user