re #108 use app main logger + multiple fixes
This commit is contained in:
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
## 1.1.1 - Work in progress
|
## 1.1.1 - Work in progress
|
||||||
- Bug #106: Correct exception value returned in `MailEvent::getException` (kartik-v)
|
- Bug #106: Correct exception value returned in `MailEvent::getException` (kartik-v)
|
||||||
- Enh #99: Added German translation (jkmssoft)
|
- Enh #99: Added German translation (jkmssoft)
|
||||||
- Enh #100: Added pt-BR translation (gugoan)
|
- Enh #100: Added pt-BR translation (gugoan)
|
||||||
|
- Enh #105: Consolidate 2fa messages (maxxer)
|
||||||
|
- Fix #108: Use main logger app (tonydspaniard)
|
||||||
|
|
||||||
## 1.1.0 - October 22, 2017
|
## 1.1.0 - October 22, 2017
|
||||||
- Enh #91: Documentation for Mail events (kartik-v)
|
- Enh #91: Documentation for Mail events (kartik-v)
|
||||||
|
|||||||
@ -20,6 +20,7 @@ use yii\authclient\Collection;
|
|||||||
use yii\base\Application;
|
use yii\base\Application;
|
||||||
use yii\base\BootstrapInterface;
|
use yii\base\BootstrapInterface;
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
use yii\console\Application as ConsoleApplication;
|
use yii\console\Application as ConsoleApplication;
|
||||||
use yii\i18n\PhpMessageSource;
|
use yii\i18n\PhpMessageSource;
|
||||||
use yii\web\Application as WebApplication;
|
use yii\web\Application as WebApplication;
|
||||||
@ -161,6 +162,8 @@ class Bootstrap implements BootstrapInterface
|
|||||||
* Registers module translation messages.
|
* Registers module translation messages.
|
||||||
*
|
*
|
||||||
* @param Application $app
|
* @param Application $app
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
protected function initTranslations(Application $app)
|
protected function initTranslations(Application $app)
|
||||||
{
|
{
|
||||||
@ -177,6 +180,8 @@ class Bootstrap implements BootstrapInterface
|
|||||||
* Ensures the auth manager is the one provided by the library.
|
* Ensures the auth manager is the one provided by the library.
|
||||||
*
|
*
|
||||||
* @param Application $app
|
* @param Application $app
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
protected function initAuthManager(Application $app)
|
protected function initAuthManager(Application $app)
|
||||||
{
|
{
|
||||||
@ -194,6 +199,8 @@ class Bootstrap implements BootstrapInterface
|
|||||||
* Initializes web url routes (rules in Yii2).
|
* Initializes web url routes (rules in Yii2).
|
||||||
*
|
*
|
||||||
* @param WebApplication $app
|
* @param WebApplication $app
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
protected function initUrlRoutes(WebApplication $app)
|
protected function initUrlRoutes(WebApplication $app)
|
||||||
{
|
{
|
||||||
@ -236,6 +243,8 @@ class Bootstrap implements BootstrapInterface
|
|||||||
* Ensures the authCollection component is configured.
|
* Ensures the authCollection component is configured.
|
||||||
*
|
*
|
||||||
* @param WebApplication $app
|
* @param WebApplication $app
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
protected function initAuthCollection(WebApplication $app)
|
protected function initAuthCollection(WebApplication $app)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -68,7 +68,6 @@ class AuthDbManagerComponent extends DbManager implements AuthManagerInterface
|
|||||||
$roles = [];
|
$roles = [];
|
||||||
foreach ($query->all($this->db) as $row) {
|
foreach ($query->all($this->db) as $row) {
|
||||||
$roles[$row['name']] = $this->populateItem($row);
|
$roles[$row['name']] = $this->populateItem($row);
|
||||||
$roles[$row['name']] = $this->populateItem($row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $roles;
|
return $roles;
|
||||||
|
|||||||
@ -29,6 +29,8 @@ class ReCaptchaComponent extends Component
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,11 +15,6 @@ use Da\User\Model\User;
|
|||||||
use Da\User\Service\MailService;
|
use Da\User\Service\MailService;
|
||||||
use yii\base\Event;
|
use yii\base\Event;
|
||||||
|
|
||||||
/**
|
|
||||||
* Mailer event to trap and handle mail exceptions for user model actions
|
|
||||||
*
|
|
||||||
* @author Kartik Visweswaran <kartikv2@gmail.com>
|
|
||||||
*/
|
|
||||||
class MailEvent extends Event
|
class MailEvent extends Event
|
||||||
{
|
{
|
||||||
const TYPE_WELCOME = 'welcome';
|
const TYPE_WELCOME = 'welcome';
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class ProfileEvent extends Event
|
|||||||
{
|
{
|
||||||
$this->profile = $profile;
|
$this->profile = $profile;
|
||||||
|
|
||||||
return parent::__construct($config);
|
parent::__construct($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProfile()
|
public function getProfile()
|
||||||
|
|||||||
@ -17,13 +17,8 @@ use Da\User\Model\User;
|
|||||||
use Da\User\Module;
|
use Da\User\Module;
|
||||||
use Da\User\Service\MailService;
|
use Da\User\Service\MailService;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class MailFactory
|
|
||||||
*
|
|
||||||
* @package Da\User\Factory
|
|
||||||
* @modified 2017-10-18 by Kartik Visweswaran <kartikv2@gmail.com>
|
|
||||||
*/
|
|
||||||
class MailFactory
|
class MailFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -126,6 +121,8 @@ class MailFactory
|
|||||||
* @param array $params
|
* @param array $params
|
||||||
*
|
*
|
||||||
* @return MailService
|
* @return MailService
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
public static function makeMailerService($type, $from, $to, $subject, $view, $params = [])
|
public static function makeMailerService($type, $from, $to, $subject, $view, $params = [])
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Da\User\Form;
|
namespace Da\User\Form;
|
||||||
|
|
||||||
|
use Da\TwoFA\Exception\InvalidSecretKeyException;
|
||||||
use Da\User\Helper\SecurityHelper;
|
use Da\User\Helper\SecurityHelper;
|
||||||
use Da\User\Model\User;
|
use Da\User\Model\User;
|
||||||
use Da\User\Query\UserQuery;
|
use Da\User\Query\UserQuery;
|
||||||
@ -79,6 +80,8 @@ class LoginForm extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws InvalidSecretKeyException
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,6 +37,8 @@ class RegistrationForm extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,6 +17,7 @@ use Da\User\Model\User;
|
|||||||
use Da\User\Traits\ContainerAwareTrait;
|
use Da\User\Traits\ContainerAwareTrait;
|
||||||
use Da\User\Traits\ModuleAwareTrait;
|
use Da\User\Traits\ModuleAwareTrait;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
use yii\base\Model;
|
use yii\base\Model;
|
||||||
|
|
||||||
class SettingsForm extends Model
|
class SettingsForm extends Model
|
||||||
@ -60,6 +61,9 @@ class SettingsForm extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
@ -75,7 +79,7 @@ class SettingsForm extends Model
|
|||||||
['email', 'username'],
|
['email', 'username'],
|
||||||
'unique',
|
'unique',
|
||||||
'when' => function ($model, $attribute) {
|
'when' => function ($model, $attribute) {
|
||||||
return $this->getUser()->$attribute != $model->$attribute;
|
return $this->getUser()->$attribute !== $model->$attribute;
|
||||||
},
|
},
|
||||||
'targetClass' => $this->getClassMap()->get(User::class),
|
'targetClass' => $this->getClassMap()->get(User::class),
|
||||||
],
|
],
|
||||||
@ -110,7 +114,7 @@ class SettingsForm extends Model
|
|||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
if ($this->user == null) {
|
if (null === $this->user) {
|
||||||
$this->user = Yii::$app->user->identity;
|
$this->user = Yii::$app->user->identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +125,8 @@ class SettingsForm extends Model
|
|||||||
* Saves new account settings.
|
* Saves new account settings.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
@ -130,9 +136,9 @@ class SettingsForm extends Model
|
|||||||
$user->scenario = 'settings';
|
$user->scenario = 'settings';
|
||||||
$user->username = $this->username;
|
$user->username = $this->username;
|
||||||
$user->password = $this->new_password;
|
$user->password = $this->new_password;
|
||||||
if ($this->email == $user->email && $user->unconfirmed_email != null) {
|
if ($this->email === $user->email && $user->unconfirmed_email !== null) {
|
||||||
$user->unconfirmed_email = null;
|
$user->unconfirmed_email = null;
|
||||||
} elseif ($this->email != $user->email) {
|
} elseif ($this->email !== $user->email) {
|
||||||
$strategy = EmailChangeStrategyFactory::makeByStrategyType(
|
$strategy = EmailChangeStrategyFactory::makeByStrategyType(
|
||||||
$this->getModule()->emailChangeStrategy,
|
$this->getModule()->emailChangeStrategy,
|
||||||
$this
|
$this
|
||||||
|
|||||||
@ -56,7 +56,7 @@ class AuthHelper
|
|||||||
? Yii::$app->getUser()->can($module->administratorPermissionName)
|
? Yii::$app->getUser()->can($module->administratorPermissionName)
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
return $hasAdministratorPermissionName || in_array($username, $module->administrators);
|
return $hasAdministratorPermissionName || in_array($username, $module->administrators, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +99,7 @@ class AuthHelper
|
|||||||
public function getUnassignedItems(AbstractAuthItem $model)
|
public function getUnassignedItems(AbstractAuthItem $model)
|
||||||
{
|
{
|
||||||
$excludeItems = $model->item !== null ? [$model->item->name] : [];
|
$excludeItems = $model->item !== null ? [$model->item->name] : [];
|
||||||
$type = $model->getType() == Permission::TYPE_PERMISSION ? Permission::TYPE_PERMISSION : null;
|
$type = $model->getType() === Permission::TYPE_PERMISSION ? Permission::TYPE_PERMISSION : null;
|
||||||
$items = $this->getAuthManager()->getItems($type, $excludeItems);
|
$items = $this->getAuthManager()->getItems($type, $excludeItems);
|
||||||
|
|
||||||
return ArrayHelper::map(
|
return ArrayHelper::map(
|
||||||
|
|||||||
@ -11,14 +11,6 @@
|
|||||||
|
|
||||||
namespace Da\User\Helper;
|
namespace Da\User\Helper;
|
||||||
|
|
||||||
/**
|
|
||||||
* ModelMapHelper.php.
|
|
||||||
*
|
|
||||||
* Date: 3/12/16
|
|
||||||
* Time: 18:10
|
|
||||||
*
|
|
||||||
* @author Antonio Ramirez <hola@2amigos.us>
|
|
||||||
*/
|
|
||||||
class ClassMapHelper
|
class ClassMapHelper
|
||||||
{
|
{
|
||||||
protected $map = [];
|
protected $map = [];
|
||||||
|
|||||||
@ -19,6 +19,8 @@ class MigrationHelper
|
|||||||
* @param string $driverName
|
* @param string $driverName
|
||||||
*
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public static function resolveTableOptions($driverName)
|
public static function resolveTableOptions($driverName)
|
||||||
{
|
{
|
||||||
@ -39,6 +41,8 @@ class MigrationHelper
|
|||||||
* @param $driverName
|
* @param $driverName
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public static function resolveDbType($driverName)
|
public static function resolveDbType($driverName)
|
||||||
{
|
{
|
||||||
@ -60,9 +64,11 @@ class MigrationHelper
|
|||||||
* @param string $driverName
|
* @param string $driverName
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public static function isMicrosoftSQLServer($driverName)
|
public static function isMicrosoftSQLServer($driverName)
|
||||||
{
|
{
|
||||||
return self::resolveDbType($driverName) == 'sqlsrv';
|
return self::resolveDbType($driverName) === 'sqlsrv';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Da\User\Helper;
|
namespace Da\User\Helper;
|
||||||
|
|
||||||
|
use yii\base\Exception;
|
||||||
use yii\base\Security;
|
use yii\base\Security;
|
||||||
|
|
||||||
class SecurityHelper
|
class SecurityHelper
|
||||||
@ -32,12 +33,23 @@ class SecurityHelper
|
|||||||
* @param null|int $cost
|
* @param null|int $cost
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function generatePasswordHash($password, $cost = null)
|
public function generatePasswordHash($password, $cost = null)
|
||||||
{
|
{
|
||||||
return $this->security->generatePasswordHash($password, $cost);
|
return $this->security->generatePasswordHash($password, $cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a random string
|
||||||
|
*
|
||||||
|
* @param int $length
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function generateRandomString($length = 32)
|
public function generateRandomString($length = 32)
|
||||||
{
|
{
|
||||||
return $this->security->generateRandomString($length);
|
return $this->security->generateRandomString($length);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ namespace Da\User\Helper;
|
|||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
|
use yii\base\InvalidParamException;
|
||||||
use yii\helpers\ArrayHelper;
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
class TimezoneHelper
|
class TimezoneHelper
|
||||||
@ -21,6 +22,8 @@ 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
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws InvalidParamException
|
||||||
*/
|
*/
|
||||||
public static function getAll()
|
public static function getAll()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,6 +20,7 @@ use DateTime;
|
|||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidParamException;
|
||||||
use yii\db\ActiveRecord;
|
use yii\db\ActiveRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,6 +42,8 @@ class Profile extends ActiveRecord
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws InvalidParamException
|
||||||
*/
|
*/
|
||||||
public function beforeSave($insert)
|
public function beforeSave($insert)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -16,6 +16,7 @@ use Da\User\Query\UserQuery;
|
|||||||
use Da\User\Traits\ContainerAwareTrait;
|
use Da\User\Traits\ContainerAwareTrait;
|
||||||
use Da\User\Traits\ModuleAwareTrait;
|
use Da\User\Traits\ModuleAwareTrait;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidParamException;
|
||||||
use yii\base\NotSupportedException;
|
use yii\base\NotSupportedException;
|
||||||
use yii\behaviors\TimestampBehavior;
|
use yii\behaviors\TimestampBehavior;
|
||||||
use yii\db\ActiveRecord;
|
use yii\db\ActiveRecord;
|
||||||
@ -71,6 +72,8 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws InvalidParamException
|
||||||
*/
|
*/
|
||||||
public function beforeSave($insert)
|
public function beforeSave($insert)
|
||||||
{
|
{
|
||||||
@ -277,6 +280,8 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return SocialNetworkAccount[] social connected accounts [ 'providerName' => socialAccountModel ]
|
* @return SocialNetworkAccount[] social connected accounts [ 'providerName' => socialAccountModel ]
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getSocialNetworkAccounts()
|
public function getSocialNetworkAccounts()
|
||||||
{
|
{
|
||||||
@ -307,6 +312,8 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws NotSupportedException
|
||||||
*/
|
*/
|
||||||
public static function findIdentityByAccessToken($token, $type = null)
|
public static function findIdentityByAccessToken($token, $type = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,14 +31,14 @@ class AuthRuleEditionService implements ServiceInterface
|
|||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
if (!$this->model->validate() || (!in_array($this->model->scenario, ['create', 'update']))) {
|
if (!$this->model->validate() || (!in_array($this->model->scenario, ['create', 'update'], false))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rule = $this->make($this->model->className, [], ['name' => $this->model->name]);
|
$rule = $this->make($this->model->className, [], ['name' => $this->model->name]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->model->scenario == 'create') {
|
if ($this->model->scenario === 'create') {
|
||||||
$this->getAuthManager()->add($rule);
|
$this->getAuthManager()->add($rule);
|
||||||
} else {
|
} else {
|
||||||
$this->getAuthManager()->update($this->model->previousName, $rule);
|
$this->getAuthManager()->update($this->model->previousName, $rule);
|
||||||
|
|||||||
@ -76,8 +76,8 @@ class EmailChangeService implements ServiceInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($this->getModule()->emailChangeStrategy === MailChangeStrategyInterface::TYPE_DEFAULT
|
if (($this->model->flags & User::NEW_EMAIL_CONFIRMED & $this->model->flags & User::OLD_EMAIL_CONFIRMED)
|
||||||
|| ($this->model->flags & User::NEW_EMAIL_CONFIRMED & $this->model->flags & User::OLD_EMAIL_CONFIRMED)
|
|| $this->getModule()->emailChangeStrategy === MailChangeStrategyInterface::TYPE_DEFAULT
|
||||||
) {
|
) {
|
||||||
$this->model->email = $this->model->unconfirmed_email;
|
$this->model->email = $this->model->unconfirmed_email;
|
||||||
$this->model->unconfirmed_email = null;
|
$this->model->unconfirmed_email = null;
|
||||||
|
|||||||
@ -13,13 +13,11 @@ namespace Da\User\Service;
|
|||||||
|
|
||||||
use Da\User\Contracts\ServiceInterface;
|
use Da\User\Contracts\ServiceInterface;
|
||||||
use Da\User\Factory\TokenFactory;
|
use Da\User\Factory\TokenFactory;
|
||||||
use Da\User\Model\Token;
|
|
||||||
use Da\User\Model\User;
|
use Da\User\Model\User;
|
||||||
use Da\User\Query\UserQuery;
|
use Da\User\Query\UserQuery;
|
||||||
use Da\User\Traits\MailAwareTrait;
|
use Da\User\Traits\MailAwareTrait;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\log\Logger;
|
|
||||||
|
|
||||||
class PasswordRecoveryService implements ServiceInterface
|
class PasswordRecoveryService implements ServiceInterface
|
||||||
{
|
{
|
||||||
@ -30,14 +28,12 @@ class PasswordRecoveryService implements ServiceInterface
|
|||||||
protected $email;
|
protected $email;
|
||||||
protected $mailService;
|
protected $mailService;
|
||||||
protected $securityHelper;
|
protected $securityHelper;
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct($email, MailService $mailService, UserQuery $query, Logger $logger)
|
public function __construct($email, MailService $mailService, UserQuery $query)
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
$this->mailService = $mailService;
|
$this->mailService = $mailService;
|
||||||
$this->query = $query;
|
$this->query = $query;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
@ -65,7 +61,7 @@ class PasswordRecoveryService implements ServiceInterface
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
|
Yii::error($e->getMessage(), 'usuario');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use Da\User\Contracts\ServiceInterface;
|
|||||||
use Da\User\Factory\TokenFactory;
|
use Da\User\Factory\TokenFactory;
|
||||||
use Da\User\Model\User;
|
use Da\User\Model\User;
|
||||||
use Da\User\Traits\MailAwareTrait;
|
use Da\User\Traits\MailAwareTrait;
|
||||||
use yii\log\Logger;
|
|
||||||
|
|
||||||
class ResendConfirmationService implements ServiceInterface
|
class ResendConfirmationService implements ServiceInterface
|
||||||
{
|
{
|
||||||
@ -23,13 +22,11 @@ class ResendConfirmationService implements ServiceInterface
|
|||||||
|
|
||||||
protected $model;
|
protected $model;
|
||||||
protected $mailService;
|
protected $mailService;
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(User $model, MailService $mailService, Logger $logger)
|
public function __construct(User $model, MailService $mailService)
|
||||||
{
|
{
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
$this->mailService = $mailService;
|
$this->mailService = $mailService;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
@ -37,6 +34,7 @@ class ResendConfirmationService implements ServiceInterface
|
|||||||
if ($this->model && !$this->model->getIsConfirmed()) {
|
if ($this->model && !$this->model->getIsConfirmed()) {
|
||||||
$token = TokenFactory::makeConfirmationToken($this->model->id);
|
$token = TokenFactory::makeConfirmationToken($this->model->id);
|
||||||
$this->mailService->setViewParam('token', $token);
|
$this->mailService->setViewParam('token', $token);
|
||||||
|
|
||||||
return $this->sendMail($this->model);
|
return $this->sendMail($this->model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,8 +47,7 @@ class TwoFactorQrCodeUriGeneratorService implements ServiceInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$totpUri = (new TOTPSecretKeyUriGeneratorService(Yii::$app->name, $user->email, $user->auth_tf_key))->run();
|
$totpUri = (new TOTPSecretKeyUriGeneratorService(Yii::$app->name, $user->email, $user->auth_tf_key))->run();
|
||||||
$dataUri = (new QrCodeDataUriGeneratorService($totpUri))->run();
|
|
||||||
|
|
||||||
return $dataUri;
|
return (new QrCodeDataUriGeneratorService($totpUri))->run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@ use Da\User\Traits\MailAwareTrait;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\InvalidCallException;
|
use yii\base\InvalidCallException;
|
||||||
use yii\log\Logger;
|
|
||||||
|
|
||||||
class UserCreateService implements ServiceInterface
|
class UserCreateService implements ServiceInterface
|
||||||
{
|
{
|
||||||
@ -28,18 +27,19 @@ class UserCreateService implements ServiceInterface
|
|||||||
protected $model;
|
protected $model;
|
||||||
protected $securityHelper;
|
protected $securityHelper;
|
||||||
protected $mailService;
|
protected $mailService;
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(User $model, MailService $mailService, SecurityHelper $securityHelper, Logger $logger)
|
public function __construct(User $model, MailService $mailService, SecurityHelper $securityHelper)
|
||||||
{
|
{
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
$this->mailService = $mailService;
|
$this->mailService = $mailService;
|
||||||
$this->securityHelper = $securityHelper;
|
$this->securityHelper = $securityHelper;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
|
* @throws InvalidCallException
|
||||||
|
* @throws \yii\db\Exception
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
@ -49,7 +49,7 @@ class UserCreateService implements ServiceInterface
|
|||||||
throw new InvalidCallException('Cannot create a new user from an existing one.');
|
throw new InvalidCallException('Cannot create a new user from an existing one.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$transaction = $model->getDb()->beginTransaction();
|
$transaction = $model::getDb()->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$model->confirmed_at = time();
|
$model->confirmed_at = time();
|
||||||
@ -81,7 +81,7 @@ class UserCreateService implements ServiceInterface
|
|||||||
return true;
|
return true;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$transaction->rollBack();
|
$transaction->rollBack();
|
||||||
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
|
Yii::error($e->getMessage(), 'usuario');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,6 @@ use Da\User\Traits\MailAwareTrait;
|
|||||||
use Da\User\Traits\ModuleAwareTrait;
|
use Da\User\Traits\ModuleAwareTrait;
|
||||||
use Exception;
|
use Exception;
|
||||||
use yii\base\InvalidCallException;
|
use yii\base\InvalidCallException;
|
||||||
use yii\log\Logger;
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
|
||||||
class UserRegisterService implements ServiceInterface
|
class UserRegisterService implements ServiceInterface
|
||||||
@ -31,14 +30,12 @@ class UserRegisterService implements ServiceInterface
|
|||||||
protected $model;
|
protected $model;
|
||||||
protected $securityHelper;
|
protected $securityHelper;
|
||||||
protected $mailService;
|
protected $mailService;
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(User $model, MailService $mailService, SecurityHelper $securityHelper, Logger $logger)
|
public function __construct(User $model, MailService $mailService, SecurityHelper $securityHelper)
|
||||||
{
|
{
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
$this->mailService = $mailService;
|
$this->mailService = $mailService;
|
||||||
$this->securityHelper = $securityHelper;
|
$this->securityHelper = $securityHelper;
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
@ -49,7 +46,7 @@ class UserRegisterService implements ServiceInterface
|
|||||||
throw new InvalidCallException('Cannot register user from an existing one.');
|
throw new InvalidCallException('Cannot register user from an existing one.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$transaction = $model->getDb()->beginTransaction();
|
$transaction = $model::getDb()->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$model->confirmed_at = $this->getModule()->enableEmailConfirmation ? null : time();
|
$model->confirmed_at = $this->getModule()->enableEmailConfirmation ? null : time();
|
||||||
@ -91,7 +88,7 @@ class UserRegisterService implements ServiceInterface
|
|||||||
return true;
|
return true;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$transaction->rollBack();
|
$transaction->rollBack();
|
||||||
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
|
Yii::error($e->getMessage(), 'usuario');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ namespace Da\User\Traits;
|
|||||||
use Da\User\Helper\AuthHelper;
|
use Da\User\Helper\AuthHelper;
|
||||||
use Da\User\Helper\ClassMapHelper;
|
use Da\User\Helper\ClassMapHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
use yii\di\Container;
|
use yii\di\Container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,6 +49,8 @@ trait ContainerAwareTrait
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Da\User\Helper\AuthHelper|object
|
* @return \Da\User\Helper\AuthHelper|object
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
public function getAuth()
|
public function getAuth()
|
||||||
{
|
{
|
||||||
@ -56,6 +59,8 @@ trait ContainerAwareTrait
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Da\User\Helper\ClassMapHelper|object
|
* @return \Da\User\Helper\ClassMapHelper|object
|
||||||
|
*
|
||||||
|
* @throws InvalidConfigException
|
||||||
*/
|
*/
|
||||||
public function getClassMap()
|
public function getClassMap()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,12 +15,10 @@ use Da\User\Event\MailEvent;
|
|||||||
use Da\User\Model\User;
|
use Da\User\Model\User;
|
||||||
use Da\User\Service\MailService;
|
use Da\User\Service\MailService;
|
||||||
use Exception;
|
use Exception;
|
||||||
use yii\log\Logger;
|
use Yii;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property MailService $mailService
|
* @property MailService $mailService
|
||||||
* @property Logger $logger
|
|
||||||
* @author Kartik Visweswaran <kartikv2@gmail.com>
|
|
||||||
*/
|
*/
|
||||||
trait MailAwareTrait
|
trait MailAwareTrait
|
||||||
{
|
{
|
||||||
@ -42,7 +40,7 @@ trait MailAwareTrait
|
|||||||
$this->mailService->run();
|
$this->mailService->run();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$event = $this->make(MailEvent::class, [$type, $user, $this->mailService, $e]);
|
$event = $this->make(MailEvent::class, [$type, $user, $this->mailService, $e]);
|
||||||
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
|
Yii::error($e->getMessage(), 'usuario');
|
||||||
$user->trigger(MailEvent::EVENT_AFTER_SEND_MAIL, $event);
|
$user->trigger(MailEvent::EVENT_AFTER_SEND_MAIL, $event);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class RbacItemsValidator extends Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($value as $item) {
|
foreach ($value as $item) {
|
||||||
if ($this->getAuthManager()->getItem($item) == null) {
|
if ($this->getAuthManager()->getItem($item) === null) {
|
||||||
return [Yii::t('usuario', 'There is neither role nor permission with name "{0}"', [$item]), []];
|
return [Yii::t('usuario', 'There is neither role nor permission with name "{0}"', [$item]), []];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class RbacRuleNameValidator extends Validator
|
|||||||
*/
|
*/
|
||||||
protected function validateValue($value)
|
protected function validateValue($value)
|
||||||
{
|
{
|
||||||
if ($this->previousName != $value) {
|
if ($this->previousName !== $value) {
|
||||||
$rule = $this->getAuthManager()->getRule($value);
|
$rule = $this->getAuthManager()->getRule($value);
|
||||||
|
|
||||||
if ($rule instanceof Rule) {
|
if ($rule instanceof Rule) {
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Da\User\Validator;
|
namespace Da\User\Validator;
|
||||||
|
|
||||||
|
use Da\TwoFA\Exception\InvalidSecretKeyException;
|
||||||
use Da\TwoFA\Manager;
|
use Da\TwoFA\Manager;
|
||||||
use Da\User\Contracts\ValidatorInterface;
|
use Da\User\Contracts\ValidatorInterface;
|
||||||
use Da\User\Model\User;
|
use Da\User\Model\User;
|
||||||
@ -37,6 +38,8 @@ class TwoFactorCodeValidator implements ValidatorInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|int
|
* @return bool|int
|
||||||
|
*
|
||||||
|
* @throws InvalidSecretKeyException
|
||||||
*/
|
*/
|
||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -16,6 +16,7 @@ use Da\User\Service\UpdateAuthAssignmentsService;
|
|||||||
use Da\User\Traits\AuthManagerAwareTrait;
|
use Da\User\Traits\AuthManagerAwareTrait;
|
||||||
use Da\User\Traits\ContainerAwareTrait;
|
use Da\User\Traits\ContainerAwareTrait;
|
||||||
use yii\base\InvalidConfigException;
|
use yii\base\InvalidConfigException;
|
||||||
|
use yii\base\InvalidParamException;
|
||||||
use yii\base\Widget;
|
use yii\base\Widget;
|
||||||
use yii\helpers\ArrayHelper;
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
@ -48,6 +49,8 @@ class AssignmentsWidget extends Widget
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws InvalidParamException
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user