Add container aware
This commit is contained in:
@ -71,6 +71,7 @@ class Bootstrap implements BootstrapInterface
|
|||||||
$di->set(Event\SocialNetworkAuthEvent::class);
|
$di->set(Event\SocialNetworkAuthEvent::class);
|
||||||
$di->set(Event\SocialNetworkConnectEvent::class);
|
$di->set(Event\SocialNetworkConnectEvent::class);
|
||||||
$di->set(Event\UserEvent::class);
|
$di->set(Event\UserEvent::class);
|
||||||
|
$di->set(Event\GdprEvent::class);
|
||||||
|
|
||||||
// forms
|
// forms
|
||||||
$di->set(Form\LoginForm::class);
|
$di->set(Form\LoginForm::class);
|
||||||
@ -78,6 +79,7 @@ class Bootstrap implements BootstrapInterface
|
|||||||
$di->set(Form\RegistrationForm::class);
|
$di->set(Form\RegistrationForm::class);
|
||||||
$di->set(Form\ResendForm::class);
|
$di->set(Form\ResendForm::class);
|
||||||
$di->set(Form\SettingsForm::class);
|
$di->set(Form\SettingsForm::class);
|
||||||
|
$di->set(Form\GdprDeleteForm::class);
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
$di->set(Helper\AuthHelper::class);
|
$di->set(Helper\AuthHelper::class);
|
||||||
|
|||||||
39
src/User/Event/GdprEvent.php
Normal file
39
src/User/Event/GdprEvent.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the 2amigos/yii2-usuario project.
|
||||||
|
*
|
||||||
|
* (c) 2amigOS! <http://2amigos.us/>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Da\User\Event;
|
||||||
|
|
||||||
|
use Da\User\Model\User;
|
||||||
|
use yii\base\Event;
|
||||||
|
|
||||||
|
class GdprEvent extends Event
|
||||||
|
{
|
||||||
|
|
||||||
|
const EVENT_BEFORE_DELETE = 'beforeDelete';
|
||||||
|
const EVENT_AFTER_DELETE = 'afterDelete';
|
||||||
|
/**
|
||||||
|
* @var bool whether logic must continue after this event. Valid only for beforeDelete
|
||||||
|
*/
|
||||||
|
public $isValid = true;
|
||||||
|
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
public function __construct(User $user, array $config = [])
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
parent::__construct($config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,13 +4,20 @@
|
|||||||
namespace Da\User\Form;
|
namespace Da\User\Form;
|
||||||
|
|
||||||
|
|
||||||
use yii\base\Model;
|
|
||||||
use Yii;
|
|
||||||
use Da\User\Model\User;
|
|
||||||
use Da\User\Helper\SecurityHelper;
|
use Da\User\Helper\SecurityHelper;
|
||||||
|
use Da\User\Model\User;
|
||||||
|
use Da\User\Traits\ContainerAwareTrait;
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GdprDeleteForm
|
||||||
|
* @package Da\User\Form
|
||||||
|
*/
|
||||||
class GdprDeleteForm extends Model
|
class GdprDeleteForm extends Model
|
||||||
{
|
{
|
||||||
|
use ContainerAwareTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string User's password
|
* @var string User's password
|
||||||
*/
|
*/
|
||||||
@ -26,7 +33,7 @@ class GdprDeleteForm extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param SecurityHelper $securityHelper
|
* @param SecurityHelper $securityHelper
|
||||||
* @param array $config
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
public function __construct(SecurityHelper $securityHelper, $config = [])
|
public function __construct(SecurityHelper $securityHelper, $config = [])
|
||||||
{
|
{
|
||||||
@ -44,14 +51,27 @@ class GdprDeleteForm extends Model
|
|||||||
'passwordValidate' => [
|
'passwordValidate' => [
|
||||||
'password',
|
'password',
|
||||||
function ($attribute) {
|
function ($attribute) {
|
||||||
if ($this->user === null ||
|
if (!$this->securityHelper
|
||||||
!$this->securityHelper->validatePassword($this->password, $this->user->password_hash)
|
->validatePassword($this->password, $this->getUser()->password_hash)
|
||||||
) {
|
) {
|
||||||
$this->addError($attribute, Yii::t('usuario', 'Invalid login or password'));
|
$this->addError($attribute, Yii::t('usuario', 'Invalid password'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User|null|\yii\web\IdentityInterface
|
||||||
|
*/
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
if ($this->user == null) {
|
||||||
|
$this->user = Yii::$app->user->identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -52,6 +52,10 @@ class Module extends BaseModule
|
|||||||
'profile.website',
|
'profile.website',
|
||||||
'profile.bio'
|
'profile.bio'
|
||||||
];
|
];
|
||||||
|
/**
|
||||||
|
* @var string prefix to be used as a replacement when user requeste deletion of his data.
|
||||||
|
*/
|
||||||
|
public $GDPRanonymPrefix = 'GDPR';
|
||||||
/**
|
/**
|
||||||
* @var bool whether to enable two factor authentication or not
|
* @var bool whether to enable two factor authentication or not
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user