update folder location
This commit is contained in:
79
src/User/Widget/AssignmentsWidget.php
Normal file
79
src/User/Widget/AssignmentsWidget.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Widget;
|
||||
|
||||
use Da\User\Model\Assignment;
|
||||
use Da\User\Service\UpdateAuthAssignmentsService;
|
||||
use Da\User\Traits\AuthManagerAwareTrait;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\Widget;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class AssignmentsWidget extends Widget
|
||||
{
|
||||
use AuthManagerAwareTrait;
|
||||
use ContainerAwareTrait;
|
||||
|
||||
/**
|
||||
* @var int ID of the user to whom auth items will be assigned
|
||||
*/
|
||||
public $userId;
|
||||
/**
|
||||
* @var string[] the post parameters
|
||||
*/
|
||||
public $params = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
if ($this->userId === null) {
|
||||
throw new InvalidConfigException(__CLASS__.'::$userId is required');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$model = $this->make(Assignment::class, [], ['user_id' => $this->userId]);
|
||||
|
||||
if ($model->load($this->params)) {
|
||||
$this->make(UpdateAuthAssignmentsService::class, [$model])->run();
|
||||
}
|
||||
|
||||
return $this->render('/widgets/assignments/form', [
|
||||
'model' => $model,
|
||||
'availableItems' => $this->getAvailableItems(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available auth items to be attached to the user.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableItems()
|
||||
{
|
||||
return ArrayHelper::map($this->getAuthManager()->getItems(), 'name', function ($item) {
|
||||
return empty($item->description)
|
||||
? $item->name
|
||||
: $item->name.' ('.$item->description.')';
|
||||
});
|
||||
}
|
||||
}
|
||||
64
src/User/Widget/ConnectWidget.php
Normal file
64
src/User/Widget/ConnectWidget.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
31
src/User/Widget/LoginWidget.php
Normal file
31
src/User/Widget/LoginWidget.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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(
|
||||
'/widgets/login',
|
||||
[
|
||||
'model' => Yii::createObject(LoginForm::class),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user