fix formatting

This commit is contained in:
Antonio Ramirez
2016-12-14 02:50:12 +01:00
parent f3f4b31bb4
commit 3ba01b4674
140 changed files with 512 additions and 523 deletions

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
@ -6,7 +7,7 @@ use Da\User\Contracts\AuthClientInterface;
class Facebook extends \yii\authclient\clients\Facebook implements AuthClientInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getEmail()
{
@ -16,7 +17,7 @@ class Facebook extends \yii\authclient\clients\Facebook implements AuthClientInt
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getUsername()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
@ -6,7 +7,7 @@ use Da\User\Contracts\AuthClientInterface;
class GitHub extends \yii\authclient\clients\GitHub implements AuthClientInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getEmail()
{
@ -16,7 +17,7 @@ class GitHub extends \yii\authclient\clients\GitHub implements AuthClientInterfa
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getUsername()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
@ -6,7 +7,7 @@ use Da\User\Contracts\AuthClientInterface;
class Google extends \yii\authclient\clients\Google implements AuthClientInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getEmail()
{
@ -16,7 +17,7 @@ class Google extends \yii\authclient\clients\Google implements AuthClientInterfa
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getUsername()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
@ -6,7 +7,7 @@ use Da\User\Contracts\AuthClientInterface;
class LinkedIn extends \yii\authclient\clients\LinkedIn implements AuthClientInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getEmail()
{
@ -16,7 +17,7 @@ class LinkedIn extends \yii\authclient\clients\LinkedIn implements AuthClientInt
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getUsername()
{

View File

@ -1,9 +1,9 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
class Twitter extends \yii\authclient\clients\Twitter implements AuthClientInterface
{
/**
@ -16,9 +16,6 @@ class Twitter extends \yii\authclient\clients\Twitter implements AuthClientInter
: null;
}
/**
* @return null Twitter does not provide user's email address
*/
public function getEmail()
{
return null;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
@ -7,12 +8,12 @@ use Yii;
class VKontakte extends \yii\authclient\clients\VKontakte implements AuthClientInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public $scope = 'email';
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getEmail()
{
@ -20,7 +21,7 @@ class VKontakte extends \yii\authclient\clients\VKontakte implements AuthClientI
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getUsername()
{
@ -30,7 +31,7 @@ class VKontakte extends \yii\authclient\clients\VKontakte implements AuthClientI
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function defaultTitle()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
@ -7,7 +8,7 @@ use Yii;
class Yandex extends \yii\authclient\clients\Yandex implements AuthClientInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getEmail()
{
@ -23,7 +24,7 @@ class Yandex extends \yii\authclient\clients\Yandex implements AuthClientInterfa
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getUsername()
{
@ -33,7 +34,7 @@ class Yandex extends \yii\authclient\clients\Yandex implements AuthClientInterfa
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function defaultTitle()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User;
use Da\User\Component\AuthDbManagerComponent;
@ -18,7 +19,7 @@ use yii\web\Application as WebApplication;
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function bootstrap($app)
{
@ -34,14 +35,14 @@ class Bootstrap implements BootstrapInterface
$this->initAuthCollection($app);
$this->initAuthManager($app);
} else {
/** @var $app ConsoleApplication */
/* @var $app ConsoleApplication */
$this->initConsoleCommands($app);
}
}
}
/**
* Initialize container with module classes
* Initialize container with module classes.
*
* @param \yii\base\Application $app
* @param array $map the previously built class map list
@ -131,7 +132,7 @@ class Bootstrap implements BootstrapInterface
[
'enableAutoLogin' => true,
'loginUrl' => ['/user/auth/login'],
'identityClass' => $di->get(ClassMapHelper::class)->get(User::class)
'identityClass' => $di->get(ClassMapHelper::class)->get(User::class),
]
);
}
@ -141,7 +142,7 @@ class Bootstrap implements BootstrapInterface
}
/**
* Registers module translation messages
* Registers module translation messages.
*
* @param Application $app
*/
@ -151,7 +152,7 @@ class Bootstrap implements BootstrapInterface
$app->get('i18n')->translations['user*'] = [
'class' => PhpMessageSource::class,
'basePath' => __DIR__.'/resources/i18n',
'sourceLanguage' => 'en-US'
'sourceLanguage' => 'en-US',
];
}
}
@ -167,14 +168,14 @@ class Bootstrap implements BootstrapInterface
$app->set(
'authManager',
[
'class' => AuthDbManagerComponent::class
'class' => AuthDbManagerComponent::class,
]
);
}
}
/**
* Initializes web url routes (rules in Yii2)
* Initializes web url routes (rules in Yii2).
*
* @param WebApplication $app
*/
@ -209,7 +210,7 @@ class Bootstrap implements BootstrapInterface
'welcomeMailSubject' => Yii::t('user', 'Welcome to {0}', $app->name),
'confirmationMailSubject' => Yii::t('user', 'Confirm account on {0}', $app->name),
'reconfirmationMailSubject' => Yii::t('user', 'Confirm email change on {0}', $app->name),
'recoveryMailSubject' => Yii::t('user', 'Complete password reset on {0}', $app->name)
'recoveryMailSubject' => Yii::t('user', 'Complete password reset on {0}', $app->name),
];
$module->mailParams = array_merge($defaults, $module->mailParams);
@ -238,7 +239,7 @@ class Bootstrap implements BootstrapInterface
}
/**
* Registers controllers
* Registers controllers.
*
* @param WebApplication $app
*/
@ -249,7 +250,7 @@ class Bootstrap implements BootstrapInterface
}
/**
* Builds class map according to user configuration
* Builds class map according to user configuration.
*
* @param array $userClassMap user configuration on the module
*
@ -288,12 +289,12 @@ class Bootstrap implements BootstrapInterface
'Token',
'Assignment',
'Permission',
'Role'
'Role',
],
'Da\User\Search' => [
'UserSearch',
'PermissionSearch',
'RoleSearch'
'RoleSearch',
],
'Da\UserForm' => [
'RegistrationForm',
@ -301,7 +302,7 @@ class Bootstrap implements BootstrapInterface
'LoginForm',
'SettingsForm',
'RecoveryForm',
]
],
];
$mapping = array_merge($defaults, $userClassMap);
@ -314,12 +315,13 @@ class Bootstrap implements BootstrapInterface
}
/**
* Returns the parent class name route of a short class name
* Returns the parent class name route of a short class name.
*
* @param array $routes class name routes
* @param string $name
*
* @return int|string
*
* @throws Exception
*/
protected function getRoute(array $routes, $name)
@ -331,5 +333,4 @@ class Bootstrap implements BootstrapInterface
}
throw new Exception("Unknown configuration class name '{$name}'");
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Command;
use Da\User\Query\UserQuery;
@ -28,7 +29,6 @@ class ConfirmController extends Controller
if ($user === null) {
$this->stdout(Yii::t('user', 'User is not found')."\n", Console::FG_RED);
} else {
if ($this->make(UserConfirmationService::class, [$user])->run()) {
$this->stdout(Yii::t('user', 'User has been confirmed')."\n", Console::FG_GREEN);
} else {
@ -37,5 +37,3 @@ class ConfirmController extends Controller
}
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Command;
use Da\User\Factory\MailFactory;
@ -31,6 +32,5 @@ class CreateController extends Controller
}
}
}
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Command;
use Da\User\Query\UserQuery;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Command;
use Da\User\Model\User;

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Component;
namespace Da\User\Component;
use Da\User\Contracts\AuthManagerInterface;
use yii\db\Query;
@ -9,8 +9,8 @@ use yii\rbac\DbManager;
class AuthDbManagerComponent extends DbManager implements AuthManagerInterface
{
/**
* @param int|null $type If null will return all auth items.
* @param array $excludeItems Items that should be excluded from result array.
* @param int|null $type If null will return all auth items
* @param array $excludeItems Items that should be excluded from result array
*
* @return array
*/
@ -40,7 +40,7 @@ class AuthDbManagerComponent extends DbManager implements AuthManagerInterface
/**
* Returns both roles and permissions assigned to user.
*
* @param integer $userId
* @param int $userId
*
* @return array
*/
@ -66,7 +66,7 @@ class AuthDbManagerComponent extends DbManager implements AuthManagerInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getItem($name)
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Contracts;
use yii\authclient\ClientInterface;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Contracts;
use yii\rbac\ManagerInterface;
@ -6,7 +7,7 @@ use yii\rbac\ManagerInterface;
interface AuthManagerInterface extends ManagerInterface
{
/**
* @param integer|null $type
* @param int|null $type
* @param array $excludeItems
*
* @return mixed
@ -14,7 +15,7 @@ interface AuthManagerInterface extends ManagerInterface
public function getItems($type = null, $excludeItems = []);
/**
* @param integer $userId
* @param int $userId
*
* @return mixed
*/

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Contracts;
interface MailChangeStrategyInterface extends StrategyInterface

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Contracts;
interface ServiceInterface

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Contracts;
interface StrategyInterface

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Contracts;
interface ValidatorInterface

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Filter\AccessRuleFilter;
@ -35,7 +36,7 @@ abstract class AbstractAuthItemController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -63,7 +64,7 @@ abstract class AbstractAuthItemController extends Controller
'index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->get())
'dataProvider' => $searchModel->search(Yii::$app->request->get()),
]
);
}
@ -82,7 +83,6 @@ abstract class AbstractAuthItemController extends Controller
->setFlash('success', Yii::t('user', 'Authorization item successfully created.'));
return $this->redirect(['index']);
} else {
Yii::$app->getSession()->setFlash('danger', Yii::t('user', 'Unable to create authorization item.'));
}
@ -92,7 +92,7 @@ abstract class AbstractAuthItemController extends Controller
'create',
[
'model' => $model,
'unassignedItems' => $this->authHelper->getUnassignedItems($model)
'unassignedItems' => $this->authHelper->getUnassignedItems($model),
]
);
}
@ -107,14 +107,12 @@ abstract class AbstractAuthItemController extends Controller
$this->make(AjaxRequestModelValidator::class, [$model])->validate();
if ($model->load(Yii::$app->request->post())) {
if ($this->make(AuthItemEditionService::class, [$model])->run()) {
Yii::$app
->getSession()
->setFlash('success', Yii::t('user', 'Authorization item successfully updated.'));
return $this->redirect(['index']);
} else {
Yii::$app->getSession()->setFlash('danger', Yii::t('user', 'Unable to update authorization item.'));
}
@ -124,7 +122,7 @@ abstract class AbstractAuthItemController extends Controller
'update',
[
'model' => $model,
'unassignedItems' => $this->authHelper->getUnassignedItems($model)
'unassignedItems' => $this->authHelper->getUnassignedItems($model),
]
);
}
@ -143,26 +141,25 @@ abstract class AbstractAuthItemController extends Controller
}
/**
* The fully qualified class name of the model
* The fully qualified class name of the model.
*
* @return string
*/
abstract protected function getModelClass();
/**
* The fully qualified class name of the search model
* The fully qualified class name of the search model.
*
* @return string
*/
abstract protected function getSearchModelClass();
/**
* Returns the an auth item
* Returns the an auth item.
*
* @param string $name
*
* @return \yii\rbac\Role|\yii\rbac\Permission|\yii\rbac\Rule
*/
abstract protected function getItem($name);
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Event\UserEvent;
@ -21,7 +22,6 @@ use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
class AdminController extends Controller
{
use ContainerTrait;
@ -60,7 +60,7 @@ class AdminController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -97,7 +97,7 @@ class AdminController extends Controller
'index',
[
'dataProvider' => $dataProvider,
'searchModel' => $searchModel
'searchModel' => $searchModel,
]
);
}
@ -113,13 +113,11 @@ class AdminController extends Controller
$this->make(AjaxRequestModelValidator::class, [$user])->validate();
if ($user->load(Yii::$app->request->post())) {
$this->trigger(UserEvent::EVENT_BEFORE_CREATE, $event);
$mailService = MailFactory::makeWelcomeMailerService($user);
if ($this->make(UserCreateService::class, [$user, $mailService])->run()) {
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been created'));
$this->trigger(UserEvent::EVENT_AFTER_CREATE, $event);
@ -181,7 +179,7 @@ class AdminController extends Controller
'_profile',
[
'user' => $user,
'profile' => $profile
'profile' => $profile,
]
);
}
@ -208,7 +206,7 @@ class AdminController extends Controller
'_assignments',
[
'user' => $user,
'params' => Yii::$app->request->post()
'params' => Yii::$app->request->post(),
]
);
}
@ -225,7 +223,6 @@ class AdminController extends Controller
if ($this->make(UserConfirmationService::class, [$user])->run()) {
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User has been confirmed'));
$this->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event);
} else {
Yii::$app->getSession()->setFlash('warning', Yii::t('user', 'Unable to confirm user. Please, try again.'));
}
@ -247,7 +244,6 @@ class AdminController extends Controller
if ($user->delete()) {
Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been deleted'));
$this->trigger(ActiveRecord::EVENT_AFTER_DELETE, $event);
} else {
Yii::$app->getSession()->setFlash(
'warning',
@ -279,4 +275,3 @@ class AdminController extends Controller
return $this->redirect(Url::previous('actions-redirect'));
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Controller;
namespace Da\User\Controller;
use Da\User\Model\Permission;
use Da\User\Search\PermissionSearch;
@ -9,7 +9,7 @@ use yii\web\NotFoundHttpException;
class PermissionController extends AbstractAuthItemController
{
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getModelClass()
{
@ -17,7 +17,7 @@ class PermissionController extends AbstractAuthItemController
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getSearchModelClass()
{
@ -25,7 +25,7 @@ class PermissionController extends AbstractAuthItemController
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getItem($name)
{
@ -37,5 +37,4 @@ class PermissionController extends AbstractAuthItemController
throw new NotFoundHttpException();
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Query\ProfileQuery;
@ -27,7 +28,7 @@ class ProfileController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -38,12 +39,12 @@ class ProfileController extends Controller
[
'allow' => true,
'actions' => ['index'],
'roles' => ['@']
'roles' => ['@'],
],
[
'allow' => true,
'actions' => ['show'],
'roles' => ['?', '@']
'roles' => ['?', '@'],
],
],
],
@ -70,5 +71,4 @@ class ProfileController extends Controller
]
);
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Event\FormEvent;
@ -42,7 +43,7 @@ class RecoveryController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -53,7 +54,7 @@ class RecoveryController extends Controller
[
'allow' => true,
'actions' => ['request', 'reset'],
'roles' => ['?']
'roles' => ['?'],
],
],
],
@ -64,11 +65,11 @@ class RecoveryController extends Controller
* Displays / handles user password recovery request.
*
* @return string
*
* @throws NotFoundHttpException
*/
public function actionRequest()
{
if (!$this->module->allowPasswordRecovery) {
throw new NotFoundHttpException();
}
@ -81,13 +82,11 @@ class RecoveryController extends Controller
$this->make(AjaxRequestModelValidator::class, $form)->validate();
if ($form->load(Yii::$app->request->post())) {
$this->trigger(FormEvent::EVENT_BEFORE_REQUEST, $event);
$mailService = MailFactory::makeRecoveryMailerService($form->email);
if ($this->make(PasswordRecoveryService::class, [$form->email, $mailService])->run()) {
$this->trigger(FormEvent::EVENT_AFTER_REQUEST, $event);
return $this->render(
@ -100,7 +99,7 @@ class RecoveryController extends Controller
}
}
return $this->render('request', ['model' => $form,]);
return $this->render('request', ['model' => $form]);
}
/**
@ -110,6 +109,7 @@ class RecoveryController extends Controller
* @param $code
*
* @return string
*
* @throws NotFoundHttpException
*/
public function actionReset($id, $code)
@ -159,6 +159,6 @@ class RecoveryController extends Controller
}
}
return $this->render('reset', ['model' => $form,]);
return $this->render('reset', ['model' => $form]);
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Event\FormEvent;
@ -47,14 +48,13 @@ class RegistrationController extends Controller
SocialNetworkAccountQuery $socialNetworkAccountQuery,
array $config = []
) {
$this->userQuery = $userQuery;
$this->socialNetworkAccountQuery = $socialNetworkAccountQuery;
parent::__construct($id, $module, $config);
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -65,12 +65,12 @@ class RegistrationController extends Controller
[
'allow' => true,
'actions' => ['register', 'connect'],
'roles' => ['?']
'roles' => ['?'],
],
[
'allow' => true,
'actions' => ['confirm', 'resend'],
'roles' => ['?', '@']
'roles' => ['?', '@'],
],
],
],
@ -97,7 +97,6 @@ class RegistrationController extends Controller
$mailService = MailFactory::makeWelcomeMailerService($user);
if ($this->make(UserRegisterService::class, [$user, $mailService])->run()) {
Yii::$app->session->setFlash(
'info',
Yii::t(
@ -110,7 +109,7 @@ class RegistrationController extends Controller
'/shared/message',
[
'title' => Yii::t('user', 'Your account has been created'),
'module' => $this->module
'module' => $this->module,
]
);
}
@ -143,7 +142,6 @@ class RegistrationController extends Controller
$this->make(AjaxRequestModelValidator::class, [$user])->validate();
if ($user->load(Yii::$app->request->post())) {
$this->trigger(SocialNetworkConnectEvent::EVENT_BEFORE_CONNECT, $event);
$mailService = MailFactory::makeWelcomeMailerService($user);

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Model\Role;
@ -8,7 +9,7 @@ use yii\web\NotFoundHttpException;
class RoleController extends AbstractAuthItemController
{
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getModelClass()
{
@ -16,7 +17,7 @@ class RoleController extends AbstractAuthItemController
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getSearchModelClass()
{
@ -24,7 +25,7 @@ class RoleController extends AbstractAuthItemController
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getItem($name)
{
@ -36,5 +37,4 @@ class RoleController extends AbstractAuthItemController
throw new NotFoundHttpException();
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Contracts\AuthClientInterface;
@ -10,11 +11,9 @@ use Da\User\Service\SocialNetworkAccountConnectService;
use Da\User\Service\SocialNetworkAuthenticateService;
use Da\User\Traits\ContainerTrait;
use yii\authclient\AuthAction;
use yii\authclient\ClientInterface;
use yii\base\Module;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use Yii;
@ -43,7 +42,7 @@ class SecurityController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -54,12 +53,12 @@ class SecurityController extends Controller
[
'allow' => true,
'actions' => ['login', 'auth', 'blocked'],
'roles' => ['?']
'roles' => ['?'],
],
[
'allow' => true,
'actions' => ['login', 'auth', 'logout'],
'roles' => ['@']
'roles' => ['@'],
],
],
],
@ -73,7 +72,7 @@ class SecurityController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function actions()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Controller;
use Da\User\Contracts\MailChangeStrategyInterface;
@ -24,7 +25,6 @@ use Yii;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
class SettingsController extends Controller
{
use ContainerTrait;
@ -34,7 +34,7 @@ class SettingsController extends Controller
protected $socialNetworkAccountQuery;
/**
* @inheritdoc
* {@inheritdoc}
*/
public $defaultAction = 'profile';
@ -63,7 +63,7 @@ class SettingsController extends Controller
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -196,7 +196,6 @@ class SettingsController extends Controller
$this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_DISCONNECT, $event);
return $this->redirect(['networks']);
}
public function actionDelete()

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Event;
use yii\base\Event;
@ -26,4 +27,3 @@ class FormEvent extends Event
return $this->form;
}
}

View File

@ -1,17 +1,16 @@
<?php
namespace Da\User\Event;
use Da\User\Model\Profile;
use yii\base\Event;
class ProfileEvent extends Event
{
protected $profile;
public function __construct(Profile $profile, array $config = [])
{
$this->profile = $profile;
return parent::__construct($config);

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Event;
namespace Da\User\Event;
use Da\User\Form\RecoveryForm;
use Da\User\Model\Token;

View File

@ -1,11 +1,11 @@
<?php
namespace Da\User\Event;
use Da\User\Model\SocialNetworkAccount;
use yii\authclient\ClientInterface;
use yii\base\Event;
class SocialNetworkAuthEvent extends Event
{
const EVENT_BEFORE_AUTHENTICATE = 'beforeAuthenticate';

View File

@ -1,11 +1,11 @@
<?php
namespace Da\User\Event;
use Da\User\Model\SocialNetworkAccount;
use Da\User\Model\User;
use yii\base\Event;
class SocialNetworkConnectEvent extends Event
{
const EVENT_BEFORE_CONNECT = 'beforeConnect';

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Event;
use Da\User\Model\User;
@ -25,7 +26,6 @@ class UserEvent extends Event
const EVENT_BEFORE_LOGOUT = 'beforeLogout';
const EVENT_AFTER_LOGOUT = 'afterLogout';
protected $user;
public function __construct(User $user, array $config = [])

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Factory;
use Yii;
@ -9,7 +10,7 @@ class AuthItemFactory
{
protected static $map = [
Item::TYPE_ROLE => 'makeRole',
Item::TYPE_PERMISSION => 'makePermission'
Item::TYPE_PERMISSION => 'makePermission',
];
/**
@ -37,6 +38,7 @@ class AuthItemFactory
* @param $name
*
* @return \yii\rbac\Role|\yii\rbac\Permission
*
* @throws Exception
*/
public static function makeByType($type, $name)

View File

@ -1,8 +1,8 @@
<?php
namespace Da\User\Factory;
use Da\User\Contracts\MailChangeStrategyInterface;
use Da\User\Contracts\StrategyInterface;
use Da\User\Form\SettingsForm;
use Da\User\Strategy\DefaultEmailChangeStrategy;
use Da\User\Strategy\InsecureEmailChangeStrategy;
@ -12,11 +12,10 @@ use Exception;
class EmailChangeStrategyFactory
{
protected static $map = [
MailChangeStrategyInterface::TYPE_INSECURE => InsecureEmailChangeStrategy::class,
MailChangeStrategyInterface::TYPE_DEFAULT => DefaultEmailChangeStrategy::class,
MailChangeStrategyInterface::TYPE_SECURE => SecureEmailChangeStrategy::class
MailChangeStrategyInterface::TYPE_SECURE => SecureEmailChangeStrategy::class,
];
/**
@ -24,6 +23,7 @@ class EmailChangeStrategyFactory
* @param SettingsForm $form
*
* @return MailChangeStrategyInterface
*
* @throws Exception
*/
public static function makeByStrategyType($strategy, SettingsForm $form)

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Factory;
use Da\User\Model\Token;
@ -25,7 +26,7 @@ class MailFactory
'user' => $user,
'token' => null,
'module' => $module,
'showPassword' => false
'showPassword' => false,
];
return static::makeMailerService($from, $to, $subject, 'welcome', $params);
@ -46,7 +47,7 @@ class MailFactory
$subject = $module->mailParams['recoveryMailSubject'];
$params = [
'user' => $token && $token->user ? $token->user : null,
'token' => $token
'token' => $token,
];
return static::makeMailerService($from, $to, $subject, 'recovery', $params);
@ -67,7 +68,7 @@ class MailFactory
$subject = $module->mailParams['confirmationMailSubject'];
$params = [
'user' => $token && $token->user ? $token->user : null,
'token' => $token
'token' => $token,
];
return static::makeMailerService($from, $to, $subject, 'recovery', $params);
@ -79,7 +80,8 @@ class MailFactory
*
* @return MailService
*/
public static function makeReconfirmationMailerService(User $user, Token $token) {
public static function makeReconfirmationMailerService(User $user, Token $token)
{
/** @var Module $module */
$module = Yii::$app->getModule('user');
$to = $token->type === Token::TYPE_CONFIRM_NEW_EMAIL
@ -90,14 +92,14 @@ class MailFactory
$subject = $module->mailParams['reconfirmationMailSubject'];
$params = [
'user' => $token && $token->user ? $token->user : null,
'token' => $token
'token' => $token,
];
return static::makeMailerService($from, $to, $subject, 'recovery', $params);
}
/**
* Builds a MailerService
* Builds a MailerService.
*
* @param string $from
* @param string $to

View File

@ -1,13 +1,12 @@
<?php
namespace Da\User\Factory;
use Da\User\Model\Token;
use Yii;
class TokenFactory
{
/**
* @param $userId
*
@ -20,7 +19,6 @@ class TokenFactory
$token->save(false);
return $token;
}
/**
@ -75,5 +73,4 @@ class TokenFactory
{
return Yii::createObject(['class' => Token::class, 'user_id' => $userId, 'type' => $type]);
}
}

View File

@ -5,11 +5,10 @@ namespace Da\User\Filter;
use Da\User\Model\User;
use yii\filters\AccessRule;
class AccessRuleFilter extends AccessRule
{
/**
* @inheritdoc
* {@inheritdoc}
* */
protected function matchRole($user)
{

View File

@ -51,7 +51,7 @@ class LoginForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
@ -63,7 +63,7 @@ class LoginForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
@ -78,7 +78,7 @@ class LoginForm extends Model
) {
$this->addError($attribute, Yii::t('user', 'Invalid login or password'));
}
}
},
],
'confirmationValidate' => [
'login',
@ -93,7 +93,7 @@ class LoginForm extends Model
$this->addError($attribute, Yii::t('user', 'Your account has been blocked'));
}
}
}
},
],
'rememberMe' => ['rememberMe', 'boolean'],
];
@ -108,6 +108,7 @@ class LoginForm extends Model
{
if ($this->validate()) {
$duration = $this->rememberMe ? $this->module->rememberLoginLifespan : 0;
return Yii::$app->getUser()->login($this->user, $duration);
} else {
return false;
@ -115,14 +116,16 @@ class LoginForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function beforeValidate()
{
if (parent::beforeValidate()) {
$this->user = $this->query->whereUsernameOrEmail(trim($this->login))->one();
return true;
}
return false;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Form;
use Da\User\Query\UserQuery;
@ -37,7 +38,7 @@ class RecoveryForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
@ -48,7 +49,7 @@ class RecoveryForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function scenarios()
{
@ -59,7 +60,7 @@ class RecoveryForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{

View File

@ -8,7 +8,6 @@ use Da\User\Traits\ModuleTrait;
use Yii;
use yii\base\Model;
class RegistrationForm extends Model
{
use ModuleTrait;
@ -28,7 +27,7 @@ class RegistrationForm extends Model
public $password;
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
@ -45,7 +44,7 @@ class RegistrationForm extends Model
'username',
'unique',
'targetClass' => $user,
'message' => Yii::t('user', 'This username has already been taken')
'message' => Yii::t('user', 'This username has already been taken'),
],
// email rules
'emailTrim' => ['email', 'filter', 'filter' => 'trim'],
@ -55,7 +54,7 @@ class RegistrationForm extends Model
'email',
'unique',
'targetClass' => $user,
'message' => Yii::t('user', 'This email address has already been taken')
'message' => Yii::t('user', 'This email address has already been taken'),
],
// password rules
'passwordRequired' => ['password', 'required', 'skipOnEmpty' => $this->module->generatePasswords],
@ -64,7 +63,7 @@ class RegistrationForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Form;
use Da\User\Query\UserQuery;
@ -27,7 +28,7 @@ class ResendForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
@ -38,7 +39,7 @@ class ResendForm extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{

View File

@ -64,7 +64,7 @@ class SettingsForm extends Model
'when' => function ($model, $attribute) {
return $this->getUser()->$attribute != $model->$attribute;
},
'targetClass' => $this->getClassMap()->get(User::class)
'targetClass' => $this->getClassMap()->get(User::class),
],
'newPasswordLength' => ['new_password', 'string', 'max' => 72, 'min' => 6],
'currentPasswordRequired' => ['current_password', 'required'],
@ -74,13 +74,13 @@ class SettingsForm extends Model
if (!$this->securityHelper->validatePassword($this->$attribute, $this->getUser()->password_hash)) {
$this->addError($attribute, Yii::t('user', 'Current password is not valid'));
}
}
},
],
];
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
@ -117,7 +117,6 @@ class SettingsForm extends Model
$this->user->password = $this->new_password;
if ($this->email == $this->user->email && $this->user->unconfirmed_email != null) {
$this->user->unconfirmed_email = null;
} elseif ($this->email != $this->user->email) {
$strategy = EmailChangeStrategyFactory::makeByStrategyType(
$this->getModule()->emailChangeStrategy,

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Helper;
use Da\User\Model\AbstractAuthItem;
@ -15,7 +16,7 @@ class AuthHelper
use AuthManagerTrait;
/**
* Checks whether a user has certain role
* Checks whether a user has certain role.
*
* @param $userId
* @param $role

View File

@ -3,11 +3,11 @@
namespace Da\User\Helper;
/**
*
* ModelMapHelper.php
* ModelMapHelper.php.
*
* Date: 3/12/16
* Time: 18:10
*
* @author Antonio Ramirez <hola@2amigos.us>
*/
class ClassMapHelper
@ -37,13 +37,14 @@ class ClassMapHelper
* @param $key
*
* @return mixed
*
* @throws \Exception
*/
public function get($key)
{
if (array_key_exists($key, $this->map)) {
return $this->map[$key];
};
}
throw new \Exception('Unknown model map key: '.$key);
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Helper;
class GravatarHelper

View File

@ -54,7 +54,7 @@ class SecurityHelper
}
$all = str_split($all);
for ($i = 0; $i < $length - count($sets); $i++) {
for ($i = 0; $i < $length - count($sets); ++$i) {
$password .= $all[array_rand($all)];
}

View File

@ -1,15 +1,15 @@
<?php
namespace Da\User\Helper;
use DateTimeZone;
use yii\helpers\ArrayHelper;
use DateTime;
class TimezoneHelper
{
/**
* Get all of the time zones with the offsets sorted by their offset
* Get all of the time zones with the offsets sorted by their offset.
*
* @return array
*/
@ -24,7 +24,7 @@ class TimezoneHelper
$timeZones[] = [
'timezone' => $timeZone,
'name' => "{$timeZone} (UTC ".($offset > 0 ? '+' : '')."{$offset})",
'offset' => $offset
'offset' => $offset,
];
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Migration;
use yii\db\Migration;
@ -19,7 +20,7 @@ class m000000_000001_create_user_table extends Migration
'confirmed_at' => $this->integer(),
'blocked_at' => $this->integer(),
'updated_at' => $this->integer()->notNull(),
'created_at' => $this->integer()->notNull()
'created_at' => $this->integer()->notNull(),
]);
$this->createIndex('idx_user_username', '{{%user}}', 'username', true);

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Migration;
use yii\db\Migration;
@ -18,7 +19,7 @@ class m000000_000002_create_profile_table extends Migration
'location' => $this->string(255),
'website' => $this->string(255),
'timezone' => $this->string(40),
'bio' => $this->text()
'bio' => $this->text(),
]
);

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Migration;
use yii\db\Migration;
@ -18,7 +19,7 @@ class m000000_000003_create_social_account_table extends Migration
'email' => $this->string(255),
'username' => $this->string(255),
'data' => $this->text(),
'created_at' => $this->integer()
'created_at' => $this->integer(),
]
);

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Migration;
use yii\db\Migration;
@ -13,7 +14,7 @@ class m000000_000004_create_token_table extends Migration
'user_id' => $this->integer(),
'code' => $this->string(32)->notNull(),
'type' => $this->smallInteger(6)->notNull(),
'created_at' => $this->integer()->notNull()
'created_at' => $this->integer()->notNull(),
]
);

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use Da\User\Traits\AuthManagerTrait;
@ -38,7 +39,7 @@ abstract class AbstractAuthItem extends Model
public $item;
/**
* @inheritdoc
* {@inheritdoc}
*/
public function init()
{
@ -56,7 +57,7 @@ abstract class AbstractAuthItem extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
@ -69,7 +70,7 @@ abstract class AbstractAuthItem extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function scenarios()
{
@ -80,7 +81,7 @@ abstract class AbstractAuthItem extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
@ -98,7 +99,7 @@ abstract class AbstractAuthItem extends Model
},
'when' => function () {
return $this->scenario == 'create' || $this->item->name != $this->name;
}
},
],
['children', RbacItemsValidator::class],
['rule', RbacRuleValidator::class],

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use Da\User\Traits\AuthManagerTrait;
@ -16,7 +17,8 @@ class Assignment extends Model
public $updated = false;
/**
* @inheritdoc
* {@inheritdoc}
*
* @throws InvalidConfigException
*/
public function init()
@ -31,24 +33,24 @@ class Assignment extends Model
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'items' => Yii::t('user', 'Items')
'items' => Yii::t('user', 'Items'),
];
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
return [
['user_id', 'required'],
['items', RbacItemsValidator::class],
['user_id', 'integer']
['user_id', 'integer'],
];
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use yii\rbac\Item;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use Da\User\Helper\GravatarHelper;
@ -13,8 +14,7 @@ use DateTimeZone;
use DateTime;
/**
*
* @property integer $user_id
* @property int $user_id
* @property string $name
* @property string $public_email
* @property string $gravatar_email
@ -23,7 +23,6 @@ use DateTime;
* @property string $website
* @property string $bio
* @property string $timezone
*
* @property User $user
*/
class Profile extends ActiveRecord
@ -32,12 +31,11 @@ class Profile extends ActiveRecord
use ContainerTrait;
/**
* @inheritdoc
* {@inheritdoc}
*/
public function beforeSave($insert)
{
if ($this->isAttributeChanged('gravatar_email')) {
$this->setAttribute(
'gravatar_id',
$this->make(GravatarHelper::class)->buildId(trim($this->getAttribute('gravatar_email')))
@ -48,7 +46,7 @@ class Profile extends ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function tableName()
{
@ -56,7 +54,7 @@ class Profile extends ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
@ -68,7 +66,7 @@ class Profile extends ActiveRecord
if ($this->make(TimeZoneValidator::class, [$attribute])->validate()) {
$this->addError($attribute, Yii::t('user', 'Time zone is not valid'));
}
}
},
],
'publicEmailPattern' => ['public_email', 'email'],
'gravatarEmailPattern' => ['gravatar_email', 'email'],
@ -82,7 +80,7 @@ class Profile extends ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
@ -112,7 +110,7 @@ class Profile extends ActiveRecord
}
/**
* Set the User's timezone
* Set the User's timezone.
*
* @param DateTimeZone $timezone
*/
@ -122,7 +120,7 @@ class Profile extends ActiveRecord
}
/**
* Get User's local time
* Get User's local time.
*
* @param DateTime|null $dateTime
*

View File

@ -1,9 +1,9 @@
<?php
namespace Da\User\Model;
use yii\rbac\Item;
class Role extends AbstractAuthItem
{
public function getType()

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use Da\User\Query\SocialNetworkAccountQuery;
@ -10,8 +11,8 @@ use yii\helpers\Url;
/**
* /**
* @property integer $id Id
* @property integer $user_id User id, null if account is not bind to user
* @property int $id Id
* @property int $user_id User id, null if account is not bind to user
* @property string $provider Name of service
* @property string $client_id Account id
* @property string $data Account properties returned by social network (json encoded)
@ -19,9 +20,8 @@ use yii\helpers\Url;
* @property string $code
* @property string $email
* @property string $username
* @property integer $created_at
*
* @property User $user User that this account is connected for.
* @property int $created_at
* @property User $user User that this account is connected for
*/
class SocialNetworkAccount extends ActiveRecord
{
@ -34,7 +34,7 @@ class SocialNetworkAccount extends ActiveRecord
protected $decodedData;
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function tableName()
{
@ -42,7 +42,7 @@ class SocialNetworkAccount extends ActiveRecord
}
/**
* @return bool Whether this social account is connected to user.
* @return bool Whether this social account is connected to user
*/
public function getIsConnected()
{
@ -73,7 +73,7 @@ class SocialNetworkAccount extends ActiveRecord
}
/**
* Connects account to a user
* Connects account to a user.
*
* @param User $user
*

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use Da\User\Helper\SecurityHelper;
@ -8,18 +9,16 @@ use Da\User\Traits\ModuleTrait;
use yii\db\ActiveRecord;
use yii\helpers\Url;
use RuntimeException;
use Yii;
/**
* Token Active Record model.
*
* @property integer $user_id
* @property int $user_id
* @property string $code
* @property integer $type
* @property int $type
* @property string $url
* @property bool $isExpired
* @property integer $created_at
*
* @property int $created_at
* @property User $user
*/
class Token extends ActiveRecord
@ -36,11 +35,11 @@ class Token extends ActiveRecord
self::TYPE_CONFIRMATION => '/user/registration/confirm',
self::TYPE_RECOVERY => '/usr/recovery/reset',
self::TYPE_CONFIRM_NEW_EMAIL => '/user/settings/confirm',
self::TYPE_CONFIRM_OLD_EMAIL => '/usr/settings/confirm'
self::TYPE_CONFIRM_OLD_EMAIL => '/usr/settings/confirm',
];
/**
* @inheritdoc
* {@inheritdoc}
*/
public function beforeSave($insert)
{
@ -54,7 +53,7 @@ class Token extends ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function tableName()
{
@ -62,7 +61,7 @@ class Token extends ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function primaryKey()
{
@ -86,7 +85,7 @@ class Token extends ActiveRecord
}
/**
* @return bool Whether token has expired.
* @return bool Whether token has expired
*/
public function getIsExpired()
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Model;
use Da\User\Helper\SecurityHelper;
@ -21,18 +22,18 @@ use yii\web\IdentityInterface;
* @property bool $isConfirmed
*
* Database fields:
* @property integer $id
* @property int $id
* @property string $username
* @property string $email
* @property string $unconfirmed_email
* @property string $password_hash
* @property string $auth_key
* @property integer $registration_ip
* @property integer $confirmed_at
* @property integer $blocked_at
* @property integer $flags
* @property integer $created_at
* @property integer $updated_at
* @property int $registration_ip
* @property int $confirmed_at
* @property int $blocked_at
* @property int $flags
* @property int $created_at
* @property int $updated_at
*
* Defined relations:
* @property SocialNetworkAccount[] $socialNetworkAccounts
@ -48,7 +49,7 @@ class User extends ActiveRecord implements IdentityInterface
const NEW_EMAIL_CONFIRMED = 0b10;
/**
* @var string Plain password. Used for model validation.
* @var string Plain password. Used for model validation
*/
public $password;
/**
@ -57,7 +58,7 @@ class User extends ActiveRecord implements IdentityInterface
protected $connectedAccounts;
/**
* @inheritdoc
* {@inheritdoc}
*/
public function beforeSave($insert)
{
@ -81,7 +82,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function tableName()
{
@ -89,7 +90,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function behaviors()
{
@ -99,7 +100,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
@ -115,7 +116,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function scenarios()
{
@ -132,7 +133,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
@ -145,7 +146,7 @@ class User extends ActiveRecord implements IdentityInterface
'usernameUnique' => [
'username',
'unique',
'message' => Yii::t('user', 'This username has already been taken')
'message' => Yii::t('user', 'This username has already been taken'),
],
// email rules
@ -155,7 +156,7 @@ class User extends ActiveRecord implements IdentityInterface
'emailUnique' => [
'email',
'unique',
'message' => Yii::t('user', 'This email address has already been taken')
'message' => Yii::t('user', 'This email address has already been taken'),
],
'emailTrim' => ['email', 'trim'],
@ -166,7 +167,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function validateAuthKey($authKey)
{
@ -174,7 +175,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getId()
{
@ -182,7 +183,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getAuthKey()
{
@ -190,7 +191,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function findIdentity($id)
{
@ -198,7 +199,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @return bool whether is blocked or not.
* @return bool whether is blocked or not
*/
public function getIsBlocked()
{
@ -222,7 +223,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* Checks whether a user has a specific role
* Checks whether a user has a specific role.
*
* @param string $role
*
@ -269,7 +270,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function findIdentityByAccessToken($token, $type = null)
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User;
use Da\User\Contracts\MailChangeStrategyInterface;
@ -6,11 +7,11 @@ use Da\User\Contracts\MailChangeStrategyInterface;
class Module extends \yii\base\Module
{
/**
* @var bool whether to allow registration process or not.
* @var bool whether to allow registration process or not
*/
public $enableRegistration = true;
/**
* @var bool whether to force email confirmation to.
* @var bool whether to force email confirmation to
*/
public $enableEmailConfirmation = true;
/**
@ -18,15 +19,15 @@ class Module extends \yii\base\Module
*/
public $enableFlashMessages = true;
/**
* @var bool whether to generate passwords automatically and remove the password field from the registration form.
* @var bool whether to generate passwords automatically and remove the password field from the registration form
*/
public $generatePasswords = false;
/**
* @var bool whether to allow login accounts with unconfirmed emails.
* @var bool whether to allow login accounts with unconfirmed emails
*/
public $allowUnconfirmedEmailLogin = false;
/**
* @var bool whether to enable password recovery or not.
* @var bool whether to enable password recovery or not
*/
public $allowPasswordRecovery = true;
/**
@ -34,19 +35,19 @@ class Module extends \yii\base\Module
*/
public $allowAccountDelete = false;
/**
* @var string the class name of the strategy class to handle user's email change.
* @var string the class name of the strategy class to handle user's email change
*/
public $emailChangeStrategy = MailChangeStrategyInterface::TYPE_DEFAULT;
/**
* @var int the time user will be auto logged in.
* @var int the time user will be auto logged in
*/
public $rememberLoginLifespan = 1209600;
/**
* @var int the time before the confirmation token becomes invalid. Defaults to 24 hours.
* @var int the time before the confirmation token becomes invalid. Defaults to 24 hours
*/
public $tokenConfirmationLifespan = 86400;
/**
* @var int the time before a recovery token is invalid. Defaults to 6 hours.
* @var int the time before a recovery token is invalid. Defaults to 6 hours
*/
public $tokenRecoveryLifespan = 21600;
/**
@ -71,11 +72,11 @@ class Module extends \yii\base\Module
* the longer it takes to generate the hash and to verify a password against it. Higher cost
* therefore slows down a brute-force attack. For best protection against brute-force attacks,
* set it to the highest value that is tolerable on production servers. The time taken to
* compute the hash doubles for every increment by one of $cost.
* compute the hash doubles for every increment by one of $cost
*/
public $blowfishCost = 10;
/**
* @var array the class map. How the container should load specific classes.
* @var array the class map. How the container should load specific classes
*/
public $classMap = [];
@ -89,7 +90,7 @@ class Module extends \yii\base\Module
'confirm/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'registration/confirm',
'forgot' => 'recovery/request',
'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset',
'settings/<action:\w+>' => 'settings/<action>'
'settings/<action:\w+>' => 'settings/<action>',
];
public $viewPath = '@Da/User/resources/views';

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Query;
use yii\db\ActiveQuery;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Query;
use Da\User\Contracts\AuthClientInterface;
@ -16,7 +17,7 @@ class SocialNetworkAccountQuery extends ActiveQuery
return $this->andWhere(
[
'provider' => $client->getId(),
'client_id' => $client->getUserAttributes()['id']
'client_id' => $client->getUserAttributes()['id'],
]
);
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Query;
use Da\User\Model\Token;

View File

@ -48,7 +48,6 @@ class UserQuery extends ActiveQuery
return $this->andWhere(['id' => $id]);
}
/**
* @param $id
*

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Search;
use Da\User\Traits\AuthManagerTrait;
@ -26,7 +27,7 @@ abstract class AbstractAuthItemSearch extends Model
public $rule_name;
/**
* @return integer
* @return int
*/
abstract public function getType();
@ -60,6 +61,5 @@ abstract class AbstractAuthItemSearch extends Model
$dataProvider->allModels = $query->all($this->getAuthManager()->db);
return $dataProvider;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Search;
use yii\rbac\Item;
@ -6,11 +7,10 @@ use yii\rbac\Item;
class PermissionSearch extends AbstractAuthItemSearch
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getType()
{
return Item::TYPE_PERMISSION;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Search;
use yii\rbac\Item;
@ -6,7 +7,7 @@ use yii\rbac\Item;
class RoleSearch extends AbstractAuthItemSearch
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getType()
{

View File

@ -1,9 +1,8 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
use Da\User\Event\UserEvent;
use Da\User\Model\Token;
use Da\User\Model\User;
use Da\User\Query\TokenQuery;
@ -43,5 +42,4 @@ class AccountConfirmationService implements ServiceInterface
return false;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
@ -55,14 +56,13 @@ class AuthItemEditionService implements ServiceInterface
$this->model->item = $item;
return $this->updateChildren();
} catch (Exception $e) {
return false;
}
}
/**
* Updates Auth Item children
* Updates Auth Item children.
*
* @return bool
*/
@ -78,7 +78,6 @@ class AuthItemEditionService implements ServiceInterface
if (!$this->getAuthManager()->removeChild($this->model->item, $children[$item])) {
return false;
}
}
// add new children
foreach (array_diff($this->model->children, $childrenNames) as $item) {

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\MailChangeStrategyInterface;
@ -44,9 +45,7 @@ class EmailChangeService implements ServiceInterface
$token->delete();
if (empty($this->model->unconfirmed_email)) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'An error occurred processing your request'));
} elseif ($this->userQuery->whereEmail($this->model->unconfirmed_email)->exists() === false) {
if ($this->getModule()->emailChangeStrategy === MailChangeStrategyInterface::TYPE_SECURE) {
if ($token->type === Token::TYPE_CONFIRM_NEW_EMAIL) {
$this->model->flags |= User::NEW_EMAIL_CONFIRMED;
@ -81,7 +80,7 @@ class EmailChangeService implements ServiceInterface
return $this->model->save(false);
}
}
return false;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
@ -51,12 +52,10 @@ class PasswordRecoveryService implements ServiceInterface
);
return true;
} catch (Exception $e) {
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
return false;
}
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Service;
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
use Da\User\Factory\TokenFactory;
@ -31,5 +31,4 @@ class ResendConfirmationService implements ServiceInterface
return false;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Service;
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
use Da\User\Helper\SecurityHelper;
@ -21,12 +21,10 @@ class ResetPasswordService implements ServiceInterface
public function run()
{
return $this->model && (bool) $this->model->updateAttributes(
[
'password_hash' => $this->securityHelper->generatePasswordHash($this->password)
'password_hash' => $this->securityHelper->generatePasswordHash($this->password),
]
);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Service;
namespace Da\User\Service;
use Da\User\Contracts\AuthClientInterface;
use Da\User\Contracts\ServiceInterface;
@ -12,7 +12,6 @@ use Da\User\Query\SocialNetworkAccountQuery;
use Da\User\Traits\ContainerTrait;
use Yii;
class SocialNetworkAccountConnectService implements ServiceInterface
{
use ContainerTrait;
@ -54,7 +53,6 @@ class SocialNetworkAccountConnectService implements ServiceInterface
$this->controller->trigger(SocialNetworkAuthEvent::EVENT_AFTER_CONNECT, $event);
return true;
} else {
Yii::$app->session->setFlash(
'danger',
@ -77,7 +75,7 @@ class SocialNetworkAccountConnectService implements ServiceInterface
[
'provider' => $this->client->getId(),
'client_id' => $data['id'],
'data' => json_encode($data)
'data' => json_encode($data),
]
);

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Service;
namespace Da\User\Service;
use Da\User\Contracts\AuthClientInterface;
use Da\User\Contracts\ServiceInterface;
@ -17,7 +17,6 @@ use yii\helpers\Url;
class SocialNetworkAuthenticateService implements ServiceInterface
{
protected $controller;
protected $authAction;
protected $client;
@ -38,7 +37,6 @@ class SocialNetworkAuthenticateService implements ServiceInterface
$this->userQuery = $userQuery;
}
public function run()
{
$account = $this->socialNetworkAccountQuery->whereClient($this->client)->one();
@ -87,7 +85,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface
'client_id' => $data['id'],
'data' => json_encode($data),
'username' => $this->client->getUserName(),
'email' => $this->client->getEmail()
'email' => $this->client->getEmail(),
]
);
@ -113,7 +111,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface
[
'scenario' => 'connect',
'username' => $account->username,
'email' => $account->email
'email' => $account->email,
]
);

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Service;
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
use Da\User\Model\Assignment;
@ -39,6 +39,5 @@ class UpdateAuthAssignmentsService implements ServiceInterface
}
return $this->model->updated = true;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
@ -39,6 +40,7 @@ class UserBlockService implements ServiceInterface
);
$this->controller->trigger(UserEvent::EVENT_AFTER_BLOCK, $this->event);
}
return $result;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
@ -22,6 +23,7 @@ class UserConfirmationService implements ServiceInterface
return true;
}
return false;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
@ -7,7 +8,6 @@ use Da\User\Helper\SecurityHelper;
use Da\User\Model\User;
use yii\base\InvalidCallException;
use Exception;
use yii\db\ActiveRecord;
use yii\log\Logger;
class UserCreateService implements ServiceInterface
@ -58,14 +58,11 @@ class UserCreateService implements ServiceInterface
$transaction->commit();
return true;
} catch (Exception $e) {
$transaction->rollBack();
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
return false;
}
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Service;
use Da\User\Contracts\ServiceInterface;
@ -49,6 +50,7 @@ class UserRegisterService implements ServiceInterface
if (!$model->save()) {
$transaction->rollBack();
return false;
}
@ -66,7 +68,6 @@ class UserRegisterService implements ServiceInterface
$transaction->commit();
return true;
} catch (Exception $e) {
$transaction->rollBack();
$this->logger->log($e->getMessage(), Logger::LEVEL_WARNING);
@ -74,5 +75,4 @@ class UserRegisterService implements ServiceInterface
return false;
}
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Strategy;
use Da\User\Contracts\MailChangeStrategyInterface;
@ -17,7 +18,6 @@ class DefaultEmailChangeStrategy implements MailChangeStrategyInterface
public function __construct(SettingsForm $form)
{
$this->form = $form;
}
public function run()
@ -37,7 +37,5 @@ class DefaultEmailChangeStrategy implements MailChangeStrategyInterface
}
return false;
}
}

View File

@ -1,10 +1,10 @@
<?php
namespace Da\User\Strategy;
use Da\User\Contracts\MailChangeStrategyInterface;
use Da\User\Form\SettingsForm;
class InsecureEmailChangeStrategy implements MailChangeStrategyInterface
{
protected $form;
@ -17,7 +17,7 @@ class InsecureEmailChangeStrategy implements MailChangeStrategyInterface
public function run()
{
$this->form->getUser()->email = $this->form->email;
return $this->form->getUser()->save();
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Strategy;
use Da\User\Contracts\MailChangeStrategyInterface;
@ -18,13 +19,11 @@ class SecureEmailChangeStrategy implements MailChangeStrategyInterface
public function __construct(SettingsForm $form)
{
$this->form = $form;
}
public function run()
{
if ($this->make(DefaultEmailChangeStrategy::class, [$this->form])->run()) {
$token = TokenFactory::makeConfirmOldMailToken($this->form->getUser()->id);
$mailService = MailFactory::makeReconfirmationMailerService($this->form->getUser(), $token);
@ -51,5 +50,4 @@ class SecureEmailChangeStrategy implements MailChangeStrategyInterface
return false;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Traits;
use Da\User\Component\AuthDbManagerComponent;
@ -9,8 +10,8 @@ trait AuthManagerTrait
/**
* @return AuthDbManagerComponent|\yii\rbac\ManagerInterface
*/
public function getAuthManager() {
public function getAuthManager()
{
return Yii::$app->getAuthManager();
}
}

View File

@ -8,11 +8,9 @@ use Yii;
use yii\di\Container;
/**
*
* @property-read Container $di
* @property-ready Da\User\Helper\AuthHelper $auth
* @property-ready Da\User\Helper\ClassMapHelper $classMap
*
*/
trait ContainerTrait
{
@ -28,8 +26,7 @@ trait ContainerTrait
* Gets a class from the container.
*
* @param string $class he class name or an alias name (e.g. `foo`) that was previously registered via [[set()]]
* or [[setSingleton()]].
*
* or [[setSingleton()]]
* @param array $params constructor parameters
* @param array $config attributes
*
@ -55,5 +52,4 @@ trait ContainerTrait
{
return $this->getDi()->get(ClassMapHelper::class);
}
}

View File

@ -2,7 +2,6 @@
namespace Da\User\Traits;
use Da\User\Helper\AuthHelper;
use Da\User\Module;
use Yii;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Validator;
use Da\User\Contracts\ValidatorInterface;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Validator;
use Da\User\Traits\AuthManagerTrait;
@ -21,5 +22,4 @@ class RbacItemsValidator extends Validator
}
}
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Validator;
use ReflectionClass;

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Validator;
use Da\User\Contracts\ValidatorInterface;
@ -16,5 +17,4 @@ class TimeZoneValidator implements ValidatorInterface
{
return in_array($this->timezone, timezone_identifiers_list());
}
}

View File

@ -16,7 +16,7 @@ class AssignmentsWidget extends Widget
use ContainerTrait;
/**
* @var integer ID of the user to whom auth items will be assigned.
* @var int ID of the user to whom auth items will be assigned
*/
public $userId;
/**
@ -25,7 +25,8 @@ class AssignmentsWidget extends Widget
public $params = [];
/**
* @inheritdoc
* {@inheritdoc}
*
* @throws InvalidConfigException
*/
public function init()
@ -37,7 +38,7 @@ class AssignmentsWidget extends Widget
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function run()
{
@ -49,12 +50,12 @@ class AssignmentsWidget extends Widget
return $this->render('/widgets/assignments/form', [
'model' => $model,
'availableItems' => $this->getAvailableItems()
'availableItems' => $this->getAvailableItems(),
]);
}
/**
* Returns all available auth items to be attached to the user
* Returns all available auth items to be attached to the user.
*
* @return array
*/

View File

@ -1,6 +1,6 @@
<?php
namespace Da\User\Widget;
namespace Da\User\Widget;
use Yii;
use yii\authclient\ClientInterface;
@ -17,7 +17,7 @@ class ConnectWidget extends AuthChoice
public $accounts;
/**
* @inheritdoc
* {@inheritdoc}
*/
public function init()
{
@ -30,7 +30,7 @@ class ConnectWidget extends AuthChoice
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function createClientUrl($provider)
{

View File

@ -1,4 +1,5 @@
<?php
namespace Da\User\Widget;
use Da\User\Form\LoginForm;
@ -14,7 +15,7 @@ class LoginWidget extends Widget
return $this->render(
'/widgets/login',
[
'model' => Yii::createObject(LoginForm::class)
'model' => Yii::createObject(LoginForm::class),
]
);
}

View File

@ -40,7 +40,7 @@ return [
'.gitignore',
'.gitkeep',
'.hgignore',
'.hgkeep'
'.hgkeep',
],
'format' => 'php',
];

View File

@ -3,7 +3,7 @@
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
/**
/*
* @var yii\web\View $this
* @var \Da\User\Model\User $user
*/

View File

@ -2,7 +2,7 @@
use Da\User\Widget\AssignmentsWidget;
/**
/*
* @var yii\web\View $this
* @var \Da\User\Model\User $user
* @var string[] $params

View File

@ -1,7 +1,7 @@
<?php
/**
* @var yii\web\View $this
* @var yii\web\View
* @var \Da\User\Model\User $user
*/
?>

Some files were not shown because too many files have changed in this diff Show More