Add container aware

This commit is contained in:
E.Alamo
2018-05-27 05:57:46 +02:00
parent 83e7359a23
commit 5dcaad02e7
4 changed files with 72 additions and 7 deletions

View File

@ -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);

View 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;
}
}

View File

@ -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;
}
}

View File

@ -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
*/