diff --git a/src/User/Bootstrap.php b/src/User/Bootstrap.php index 0f36307..3ece9fe 100644 --- a/src/User/Bootstrap.php +++ b/src/User/Bootstrap.php @@ -71,6 +71,7 @@ class Bootstrap implements BootstrapInterface $di->set(Event\SocialNetworkAuthEvent::class); $di->set(Event\SocialNetworkConnectEvent::class); $di->set(Event\UserEvent::class); + $di->set(Event\GdprEvent::class); // forms $di->set(Form\LoginForm::class); @@ -78,6 +79,7 @@ class Bootstrap implements BootstrapInterface $di->set(Form\RegistrationForm::class); $di->set(Form\ResendForm::class); $di->set(Form\SettingsForm::class); + $di->set(Form\GdprDeleteForm::class); // helpers $di->set(Helper\AuthHelper::class); diff --git a/src/User/Event/GdprEvent.php b/src/User/Event/GdprEvent.php new file mode 100644 index 0000000..89872c5 --- /dev/null +++ b/src/User/Event/GdprEvent.php @@ -0,0 +1,39 @@ + + * + * 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; + } +} diff --git a/src/User/Form/GdprDeleteForm.php b/src/User/Form/GdprDeleteForm.php index 2cd023d..c7f9ee4 100644 --- a/src/User/Form/GdprDeleteForm.php +++ b/src/User/Form/GdprDeleteForm.php @@ -4,13 +4,20 @@ namespace Da\User\Form; -use yii\base\Model; -use Yii; -use Da\User\Model\User; 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 { + use ContainerAwareTrait; + /** * @var string User's password */ @@ -26,7 +33,7 @@ class GdprDeleteForm extends Model /** * @param SecurityHelper $securityHelper - * @param array $config + * @param array $config */ public function __construct(SecurityHelper $securityHelper, $config = []) { @@ -44,14 +51,27 @@ class GdprDeleteForm extends Model 'passwordValidate' => [ 'password', function ($attribute) { - if ($this->user === null || - !$this->securityHelper->validatePassword($this->password, $this->user->password_hash) + if (!$this->securityHelper + ->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; + } + + } \ No newline at end of file diff --git a/src/User/Module.php b/src/User/Module.php index 9325b0f..0e8ceef 100644 --- a/src/User/Module.php +++ b/src/User/Module.php @@ -52,6 +52,10 @@ class Module extends BaseModule 'profile.website', '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 */