Close #68 fix documentation + events raised on User model

This commit is contained in:
Antonio Ramirez
2017-10-15 15:46:20 +02:00
parent 803a8ff4f0
commit 9607e8d775
6 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,7 @@
# CHANGELOG # CHANGELOG
## 1.0.14 - Work in progress ## 1.0.14 - Work in progress
- Fix #68: Fix user events documentation and events raised from User model (tonydspaniard)
- Fix #69: Log level when user can't register should be L_ERROR (tonydspaniard) - Fix #69: Log level when user can't register should be L_ERROR (tonydspaniard)
- Enh #81: Update `AccessRuleFilter` to evaluate `roleParams` (kartik-v) - Enh #81: Update `AccessRuleFilter` to evaluate `roleParams` (kartik-v)
- Enh #56: Added two factor authentication (tonydspaniard) - Enh #56: Added two factor authentication (tonydspaniard)

View File

@ -14,6 +14,8 @@ On Controllers
- **RegistrationController** - **RegistrationController**
- **FormEvent::EVENT_BEFORE_RESEND**: Occurs before a confirmation message is being sent via email - **FormEvent::EVENT_BEFORE_RESEND**: Occurs before a confirmation message is being sent via email
- **FormEvent::EVENT_AFTER_RESEND**: Occurs after a confirmation message is being sent via email - **FormEvent::EVENT_AFTER_RESEND**: Occurs after a confirmation message is being sent via email
- **FormEvent::EVENT_BEFORE_REGISTER**: Occurs before user registration
- **FormEvent::EVENT_AFTER_REGISTER**: Occurs after user registration
- **SecurityController** - **SecurityController**

View File

@ -22,8 +22,6 @@ On Controllers
- **RegistrationController** - **RegistrationController**
- **UserEvent::EVENT_BEFORE_REGISTER**: Occurs before user registration
- **UserEvent::EVENT_AFTER_REGISTER**: Occurs after user registration
- **UserEvent::EVENT_BEFORE_CONFIRMATION** - **UserEvent::EVENT_BEFORE_CONFIRMATION**
- **UserEvent::EVENT_AFTER_CONFIRMATION** - **UserEvent::EVENT_AFTER_CONFIRMATION**

View File

@ -99,7 +99,7 @@ class RegistrationController extends Controller
$this->make(AjaxRequestModelValidator::class, [$form])->validate(); $this->make(AjaxRequestModelValidator::class, [$form])->validate();
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
$this->trigger(UserEvent::EVENT_BEFORE_REGISTER, $event); $this->trigger(FormEvent::EVENT_BEFORE_REGISTER, $event);
/** @var User $user */ /** @var User $user */
$user = $this->make(User::class, [], $form->attributes); $user = $this->make(User::class, [], $form->attributes);
$user->setScenario('register'); $user->setScenario('register');
@ -113,7 +113,7 @@ class RegistrationController extends Controller
'Your account has been created and a message with further instructions has been sent to your email' 'Your account has been created and a message with further instructions has been sent to your email'
) )
); );
$this->trigger(UserEvent::EVENT_AFTER_REGISTER, $event); $this->trigger(FormEvent::EVENT_AFTER_REGISTER, $event);
return $this->render( return $this->render(
'/shared/message', '/shared/message',

View File

@ -22,6 +22,8 @@ class FormEvent extends Event
const EVENT_AFTER_RESEND = 'afterResend'; const EVENT_AFTER_RESEND = 'afterResend';
const EVENT_BEFORE_LOGIN = 'beforeLogin'; const EVENT_BEFORE_LOGIN = 'beforeLogin';
const EVENT_AFTER_LOGIN = 'afterLogin'; const EVENT_AFTER_LOGIN = 'afterLogin';
const EVENT_BEFORE_REGISTER = 'beforeRegister';
const EVENT_AFTER_REGISTER = 'afterRegister';
protected $form; protected $form;

View File

@ -16,6 +16,7 @@ use Da\User\Event\UserEvent;
use Da\User\Factory\TokenFactory; use Da\User\Factory\TokenFactory;
use Da\User\Helper\SecurityHelper; use Da\User\Helper\SecurityHelper;
use Da\User\Model\User; use Da\User\Model\User;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Traits\ModuleAwareTrait; use Da\User\Traits\ModuleAwareTrait;
use Exception; use Exception;
use yii\base\InvalidCallException; use yii\base\InvalidCallException;
@ -24,6 +25,7 @@ use yii\log\Logger;
class UserRegisterService implements ServiceInterface class UserRegisterService implements ServiceInterface
{ {
use ModuleAwareTrait; use ModuleAwareTrait;
use ContainerAwareTrait;
protected $model; protected $model;
protected $securityHelper; protected $securityHelper;
@ -54,7 +56,8 @@ class UserRegisterService implements ServiceInterface
? $this->securityHelper->generatePassword(8) ? $this->securityHelper->generatePassword(8)
: $model->password; : $model->password;
$model->trigger(UserEvent::EVENT_BEFORE_REGISTER); $userEvent = $this->make(UserEvent::class, [$model]);
$model->trigger(UserEvent::EVENT_BEFORE_REGISTER, $userEvent);
if (!$model->save()) { if (!$model->save()) {
$transaction->rollBack(); $transaction->rollBack();
@ -71,7 +74,7 @@ class UserRegisterService implements ServiceInterface
} }
$this->mailService->run(); $this->mailService->run();
$model->trigger(UserEvent::EVENT_AFTER_REGISTER); $model->trigger(UserEvent::EVENT_AFTER_REGISTER, $userEvent);
$transaction->commit(); $transaction->commit();