diff --git a/lib/User/Controller/SecurityController.php b/lib/User/Controller/SecurityController.php index 55b4eb2..589d4c5 100644 --- a/lib/User/Controller/SecurityController.php +++ b/lib/User/Controller/SecurityController.php @@ -135,7 +135,8 @@ class SecurityController extends Controller $this->make(SocialNetworkAuthenticateService::class, [$this, $this->action, $client])->run(); } - public function connect(AuthClientInterface $client) { + public function connect(AuthClientInterface $client) + { if (Yii::$app->user->isGuest) { Yii::$app->session->setFlash('danger', Yii::t('user', 'Something went wrong')); diff --git a/lib/User/Controller/SettingsController.php b/lib/User/Controller/SettingsController.php index e77cd5a..2eaba88 100644 --- a/lib/User/Controller/SettingsController.php +++ b/lib/User/Controller/SettingsController.php @@ -199,7 +199,7 @@ class SettingsController extends Controller public function actionDelete() { - if (!$this->module->enableAccountDelete) { + if (!$this->module->allowAccountDelete) { throw new NotFoundHttpException(\Yii::t('user', 'Not found')); } diff --git a/lib/User/Module.php b/lib/User/Module.php index df7fc9a..da417b1 100644 --- a/lib/User/Module.php +++ b/lib/User/Module.php @@ -26,6 +26,10 @@ class Module extends \yii\base\Module * @var bool whether to enable password recovery or not. */ public $allowPasswordRecovery = true; + /** + * @var bool Whether user can remove his account + */ + public $allowAccountDelete = false; /** * @var string the class name of the strategy class to handle user's email change. */ diff --git a/lib/User/Widget/ConnectWidget.php b/lib/User/Widget/ConnectWidget.php new file mode 100644 index 0000000..5514d79 --- /dev/null +++ b/lib/User/Widget/ConnectWidget.php @@ -0,0 +1,55 @@ +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()]); + } +} diff --git a/lib/User/Widget/LoginWidget.php b/lib/User/Widget/LoginWidget.php new file mode 100644 index 0000000..8bce6fe --- /dev/null +++ b/lib/User/Widget/LoginWidget.php @@ -0,0 +1,21 @@ +render( + 'login', + [ + 'model' => Yii::createObject(LoginForm::class) + ] + ); + } +} diff --git a/lib/User/resources/views/mail/confirmation.php b/lib/User/resources/views/mail/confirmation.php index 75ded1e..df27956 100644 --- a/lib/User/resources/views/mail/confirmation.php +++ b/lib/User/resources/views/mail/confirmation.php @@ -1,19 +1,10 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; /** - * @var dektrium\user\models\User $user - * @var dektrium\user\models\Token $token + * @var \Da\User\Model\User $user + * @var \Da\User\Model\Token $token */ ?>

diff --git a/lib/User/resources/views/mail/layouts/html.php b/lib/User/resources/views/mail/layouts/html.php index cd80b96..8981ab4 100644 --- a/lib/User/resources/views/mail/layouts/html.php +++ b/lib/User/resources/views/mail/layouts/html.php @@ -1,14 +1,4 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - /** * @var \yii\web\View $this * @var yii\mail\BaseMessage $content diff --git a/lib/User/resources/views/mail/layouts/text.php b/lib/User/resources/views/mail/layouts/text.php index 097eb30..43ce060 100644 --- a/lib/User/resources/views/mail/layouts/text.php +++ b/lib/User/resources/views/mail/layouts/text.php @@ -1,14 +1,4 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - /** * @var string $content main view render result */ diff --git a/lib/User/resources/views/mail/reconfirmation.php b/lib/User/resources/views/mail/reconfirmation.php index 312e166..02073c1 100644 --- a/lib/User/resources/views/mail/reconfirmation.php +++ b/lib/User/resources/views/mail/reconfirmation.php @@ -1,18 +1,8 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; /** - * @var dektrium\user\models\Token $token + * @var \Da\User\Model\Token $token */ ?>

diff --git a/lib/User/resources/views/mail/recovery.php b/lib/User/resources/views/mail/recovery.php index a7aadb2..1a98f78 100644 --- a/lib/User/resources/views/mail/recovery.php +++ b/lib/User/resources/views/mail/recovery.php @@ -1,19 +1,10 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; /** - * @var dektrium\user\models\User $user - * @var dektrium\user\models\Token $token + * @var \Da\User\Model\User $user + * @var \Da\User\Model\Token $token */ ?>

diff --git a/lib/User/resources/views/mail/text/confirmation.php b/lib/User/resources/views/mail/text/confirmation.php index e2f7a38..e1d2daf 100644 --- a/lib/User/resources/views/mail/text/confirmation.php +++ b/lib/User/resources/views/mail/text/confirmation.php @@ -1,17 +1,8 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - /** - * @var dektrium\user\models\User $user - * @var dektrium\user\models\Token $token + * @var \Da\User\Model\User $user + * @var \Da\User\Model\Token $token */ ?> , diff --git a/lib/User/resources/views/mail/text/reconfirmation.php b/lib/User/resources/views/mail/text/reconfirmation.php index fdb6c64..6c5a388 100644 --- a/lib/User/resources/views/mail/text/reconfirmation.php +++ b/lib/User/resources/views/mail/text/reconfirmation.php @@ -1,16 +1,6 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - /** - * @var dektrium\user\models\Token $token + * @var \Da\User\Model\Token $token */ ?> , diff --git a/lib/User/resources/views/mail/text/recovery.php b/lib/User/resources/views/mail/text/recovery.php index 3ffec17..9be9cad 100644 --- a/lib/User/resources/views/mail/text/recovery.php +++ b/lib/User/resources/views/mail/text/recovery.php @@ -1,17 +1,7 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - /** - * @var dektrium\user\models\User $user - * @var dektrium\user\models\Token $token + * @var \Da\User\Model\User $user + * @var \Da\User\Model\Token $token */ ?> , diff --git a/lib/User/resources/views/mail/text/welcome.php b/lib/User/resources/views/mail/text/welcome.php index a9f208c..8cff168 100644 --- a/lib/User/resources/views/mail/text/welcome.php +++ b/lib/User/resources/views/mail/text/welcome.php @@ -1,32 +1,23 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - /** - * @var dektrium\user\models\User + * @var \Da\User\Model\User $user + * @var \Da\User\Model\Token $token + * @var \Da\User\Module $module */ ?> , name) ?>. -enableGeneratingPassword): ?> -: -password ?> +generatePasswords): ?> + : + password ?> -. - -url ?> - -. + . + url ?> + . . diff --git a/lib/User/resources/views/mail/welcome.php b/lib/User/resources/views/mail/welcome.php index 79da04e..1e708ac 100644 --- a/lib/User/resources/views/mail/welcome.php +++ b/lib/User/resources/views/mail/welcome.php @@ -1,21 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; /** - * @var dektrium\user\Module $module - * @var dektrium\user\models\User $user - * @var dektrium\user\models\Token $token - * @var bool $showPassword + * @var \Da\User\Module $module + * @var \Da\User\Model\User $user + * @var \Da\User\Model\Token $token + * @var bool $showPassword */ ?> @@ -25,22 +15,22 @@ use yii\helpers\Html;

name) ?>. - enableGeneratingPassword): ?> + generatePasswords): ?> : password ?>

-

- . -

-

- url), $token->url); ?> -

-

- . -

+

+ . +

+

+ url), $token->url); ?> +

+

+ . +

diff --git a/lib/User/resources/views/profile/show.php b/lib/User/resources/views/profile/show.php index 076ff3e..bdabcae 100644 --- a/lib/User/resources/views/profile/show.php +++ b/lib/User/resources/views/profile/show.php @@ -1,19 +1,10 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; /** * @var \yii\web\View $this - * @var \dektrium\user\models\Profile $profile + * @var \Da\User\Model\Profile $profile */ $this->title = empty($profile->name) ? Html::encode($profile->user->username) : Html::encode($profile->name); @@ -32,15 +23,29 @@ $this->params['breadcrumbs'][] = $this->title;

title ?>

bio)): ?>

bio) ?>

diff --git a/lib/User/resources/views/recovery/request.php b/lib/User/resources/views/recovery/request.php index 7635380..fce2d37 100644 --- a/lib/User/resources/views/recovery/request.php +++ b/lib/User/resources/views/recovery/request.php @@ -1,21 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; use yii\widgets\ActiveForm; -/* +/** * @var yii\web\View $this * @var yii\widgets\ActiveForm $form - * @var dektrium\user\models\RecoveryForm $model + * @var \Da\User\Form\RecoveryForm $model */ $this->title = Yii::t('user', 'Recover your password'); @@ -28,11 +18,13 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

- 'password-recovery-form', - 'enableAjaxValidation' => true, - 'enableClientValidation' => false, - ]); ?> + $model->formName(), + 'enableAjaxValidation' => true, + 'enableClientValidation' => false, + ] + ); ?> field($model, 'email')->textInput(['autofocus' => true]) ?> diff --git a/lib/User/resources/views/recovery/reset.php b/lib/User/resources/views/recovery/reset.php index 6f29ea3..3ced36c 100644 --- a/lib/User/resources/views/recovery/reset.php +++ b/lib/User/resources/views/recovery/reset.php @@ -1,21 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; use yii\widgets\ActiveForm; -/* +/** * @var yii\web\View $this * @var yii\widgets\ActiveForm $form - * @var dektrium\user\models\RecoveryForm $model + * @var \Da\User\Form\RecoveryForm $model */ $this->title = Yii::t('user', 'Reset your password'); @@ -28,11 +19,13 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

- 'password-recovery-form', - 'enableAjaxValidation' => true, - 'enableClientValidation' => false, - ]); ?> + $model->formName(), + 'enableAjaxValidation' => true, + 'enableClientValidation' => false, + ] + ); ?> field($model, 'password')->passwordInput() ?> diff --git a/lib/User/resources/views/registration/connect.php b/lib/User/resources/views/registration/connect.php index 9ed4957..992b098 100644 --- a/lib/User/resources/views/registration/connect.php +++ b/lib/User/resources/views/registration/connect.php @@ -1,22 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; use yii\widgets\ActiveForm; /** - * @var yii\web\View $this - * @var yii\widgets\ActiveForm $form - * @var dektrium\user\models\User $model - * @var dektrium\user\models\Account $account + * @var yii\web\View $this + * @var yii\widgets\ActiveForm $form + * @var \Da\User\Model\User $model + * @var \Da\User\Model\SocialNetworkAccount $account */ $this->title = Yii::t('user', 'Sign in'); @@ -37,9 +27,11 @@ $this->params['breadcrumbs'][] = $this->title; ) ?>:

- 'connect-account-form', - ]); ?> + $model->formName(), + ] + ); ?> field($model, 'email') ?> diff --git a/lib/User/resources/views/registration/register.php b/lib/User/resources/views/registration/register.php index a5d774f..1cf07e9 100644 --- a/lib/User/resources/views/registration/register.php +++ b/lib/User/resources/views/registration/register.php @@ -13,9 +13,10 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; /** - * @var yii\web\View $this - * @var dektrium\user\models\User $user - * @var dektrium\user\Module $module + * @var yii\web\View $this + * @var \Da\User\Form\RegistrationForm $model + * @var \Da\User\Model\User $user + * @var \Da\User\Module $module */ $this->title = Yii::t('user', 'Sign up'); @@ -28,17 +29,19 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

- 'registration-form', - 'enableAjaxValidation' => true, - 'enableClientValidation' => false, - ]); ?> + $model->formName(), + 'enableAjaxValidation' => true, + 'enableClientValidation' => false, + ] + ); ?> field($model, 'email') ?> field($model, 'username') ?> - enableGeneratingPassword == false): ?> + generatePasswords == false): ?> field($model, 'password')->passwordInput() ?> diff --git a/lib/User/resources/views/registration/resend.php b/lib/User/resources/views/registration/resend.php index d370aa5..98b925b 100644 --- a/lib/User/resources/views/registration/resend.php +++ b/lib/User/resources/views/registration/resend.php @@ -1,20 +1,10 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; use yii\widgets\ActiveForm; -/* - * @var yii\web\View $this - * @var dektrium\user\models\ResendForm $model +/** + * @var yii\web\View $this + * @var \Da\User\Form\ResendForm $model */ $this->title = Yii::t('user', 'Request new confirmation message'); @@ -27,11 +17,13 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

- 'resend-form', - 'enableAjaxValidation' => true, - 'enableClientValidation' => false, - ]); ?> + $model->formName(), + 'enableAjaxValidation' => true, + 'enableClientValidation' => false, + ] + ); ?> field($model, 'email')->textInput(['autofocus' => true]) ?> diff --git a/lib/User/resources/views/security/login.php b/lib/User/resources/views/security/login.php index 06f8280..70251f1 100644 --- a/lib/User/resources/views/security/login.php +++ b/lib/User/resources/views/security/login.php @@ -1,22 +1,13 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use dektrium\user\widgets\Connect; use yii\helpers\Html; use yii\widgets\ActiveForm; /** - * @var yii\web\View $this - * @var dektrium\user\models\LoginForm $model - * @var dektrium\user\Module $module + * @var yii\web\View $this + * @var \Da\User\Form\LoginForm $model + * @var \Da\User\Module $module */ $this->title = Yii::t('user', 'Sign in'); @@ -32,14 +23,16 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

- 'login-form', - 'enableAjaxValidation' => true, - 'enableClientValidation' => false, - 'validateOnBlur' => false, - 'validateOnType' => false, - 'validateOnChange' => false, - ]) ?> + $model->formName(), + 'enableAjaxValidation' => true, + 'enableClientValidation' => false, + 'validateOnBlur' => false, + 'validateOnType' => false, + 'validateOnChange' => false, + ] + ) ?> field( $model, @@ -56,7 +49,7 @@ $this->params['breadcrumbs'][] = $this->title; ->passwordInput() ->label( Yii::t('user', 'Password') - .($module->enablePasswordRecovery ? + . ($module->allowPasswordRecovery ? ' (' . Html::a( Yii::t('user', 'Forgot password?'), ['/user/recovery/request'], @@ -75,7 +68,7 @@ $this->params['breadcrumbs'][] = $this->title;
- enableConfirmation): ?> + enableEmailConfirmation): ?>

@@ -85,8 +78,10 @@ $this->params['breadcrumbs'][] = $this->title;

- ['/user/security/auth'], - ]) ?> + ['/user/security/auth'], + ] + ) ?> diff --git a/lib/User/resources/views/settings/_menu.php b/lib/User/resources/views/settings/_menu.php index 71554ee..b0faa38 100644 --- a/lib/User/resources/views/settings/_menu.php +++ b/lib/User/resources/views/settings/_menu.php @@ -1,18 +1,9 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; use yii\widgets\Menu; -/** @var dektrium\user\models\User $user */ +/** @var \Da\User\Model\User $user */ $user = Yii::$app->user->identity; $networksVisible = count(Yii::$app->authClientCollection->clients) > 0; @@ -21,27 +12,32 @@ $networksVisible = count(Yii::$app->authClientCollection->clients) > 0;

- profile->getAvatarUrl(24), [ - 'class' => 'img-rounded', - 'alt' => $user->username, - ]) ?> + profile->getAvatarUrl(24), + [ + 'class' => 'img-rounded', + 'alt' => $user->username, + ] + ) ?> username ?>

- [ - 'class' => 'nav nav-pills nav-stacked', - ], - 'items' => [ - ['label' => Yii::t('user', 'Profile'), 'url' => ['/user/settings/profile']], - ['label' => Yii::t('user', 'Account'), 'url' => ['/user/settings/account']], - [ - 'label' => Yii::t('user', 'Networks'), - 'url' => ['/user/settings/networks'], - 'visible' => $networksVisible + [ + 'class' => 'nav nav-pills nav-stacked', ], - ], - ]) ?> + 'items' => [ + ['label' => Yii::t('user', 'Profile'), 'url' => ['/user/settings/profile']], + ['label' => Yii::t('user', 'Account'), 'url' => ['/user/settings/account']], + [ + 'label' => Yii::t('user', 'Networks'), + 'url' => ['/user/settings/networks'], + 'visible' => $networksVisible + ], + ], + ] + ) ?>
diff --git a/lib/User/resources/views/settings/account.php b/lib/User/resources/views/settings/account.php index ca1ee4c..ad6d7b4 100644 --- a/lib/User/resources/views/settings/account.php +++ b/lib/User/resources/views/settings/account.php @@ -1,21 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - use yii\helpers\Html; use yii\widgets\ActiveForm; /** - * @var $this yii\web\View - * @var $form yii\widgets\ActiveForm - * @var $model dektrium\user\models\SettingsForm + * @var yii\web\View $this + * @var yii\widgets\ActiveForm $form + * @var \Da\User\Form\SettingsForm $model */ $this->title = Yii::t('user', 'Account settings'); @@ -35,7 +26,7 @@ $this->params['breadcrumbs'][] = $this->title;
'account-form', + 'id' => $model->formName(), 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => "{label}\n
{input}
\n
{error}\n{hint}
", @@ -65,7 +56,7 @@ $this->params['breadcrumbs'][] = $this->title;
- module->enableAccountDelete): ?> + module->allowAccountDelete): ?>

diff --git a/lib/User/resources/views/settings/networks.php b/lib/User/resources/views/settings/networks.php index 1ee1c7d..ad810af 100644 --- a/lib/User/resources/views/settings/networks.php +++ b/lib/User/resources/views/settings/networks.php @@ -1,20 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE.md - * file that was distributed with this source code. - */ - -use dektrium\user\widgets\Connect; +use Da\User\Widget\ConnectWidget; use yii\helpers\Html; -/* +/** * @var yii\web\View $this * @var yii\widgets\ActiveForm $form + * @var \Da\User\Model\User $user */ $this->title = Yii::t('user', 'Networks'); @@ -36,9 +28,9 @@ $this->params['breadcrumbs'][] = $this->title;

.

- ['/user/security/auth'], - 'accounts' => $user->accounts, + 'accounts' => $user->socialNetworkAccounts, 'autoRender' => false, 'popupMode' => false, ]) ?> @@ -65,7 +57,7 @@ $this->params['breadcrumbs'][] = $this->title; - +