minor fixes and user events docs
This commit is contained in:
@ -281,6 +281,7 @@ class AdminController extends Controller
|
||||
Yii::$app->getSession()->setFlash('success', Yii::t('usuario', 'User block status has been updated.'));
|
||||
} else {
|
||||
Yii::$app->getSession()->setFlash('danger', Yii::t('usuario', 'Unable to update block status.'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -106,6 +106,7 @@ class RegistrationController extends Controller
|
||||
$mailService = MailFactory::makeWelcomeMailerService($user);
|
||||
|
||||
if ($this->make(UserRegisterService::class, [$user, $mailService])->run()) {
|
||||
|
||||
Yii::$app->session->setFlash(
|
||||
'info',
|
||||
Yii::t(
|
||||
@ -113,6 +114,7 @@ class RegistrationController extends Controller
|
||||
'Your account has been created and a message with further instructions has been sent to your email'
|
||||
)
|
||||
);
|
||||
$this->trigger(UserEvent::EVENT_AFTER_REGISTER, $event);
|
||||
|
||||
return $this->render(
|
||||
'/shared/message',
|
||||
@ -175,6 +177,7 @@ class RegistrationController extends Controller
|
||||
|
||||
public function actionConfirm($id, $code)
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->userQuery->whereId($id)->one();
|
||||
|
||||
if ($user === null || $this->module->enableEmailConfirmation === false) {
|
||||
|
||||
@ -137,7 +137,7 @@ class SettingsController extends Controller
|
||||
{
|
||||
/** @var SettingsForm $form */
|
||||
$form = $this->make(SettingsForm::class);
|
||||
$event = $this->make(FormEvent::class, [$form]);
|
||||
$event = $this->make(UserEvent::class, [$form->getUser()]);
|
||||
|
||||
$this->make(AjaxRequestModelValidator::class, [$form])->validate();
|
||||
|
||||
|
||||
@ -121,12 +121,13 @@ class SettingsForm extends Model
|
||||
public function save()
|
||||
{
|
||||
if ($this->validate()) {
|
||||
$this->user->scenario = 'settings';
|
||||
$this->user->username = $this->username;
|
||||
$this->user->password = $this->new_password;
|
||||
if ($this->email == $this->user->email && $this->user->unconfirmed_email != null) {
|
||||
$this->user->unconfirmed_email = null;
|
||||
} elseif ($this->email != $this->user->email) {
|
||||
$user = $this->getUser();
|
||||
$user->scenario = 'settings';
|
||||
$user->username = $this->username;
|
||||
$user->password = $this->new_password;
|
||||
if ($this->email == $user->email && $user->unconfirmed_email != null) {
|
||||
$user->unconfirmed_email = null;
|
||||
} elseif ($this->email != $user->email) {
|
||||
$strategy = EmailChangeStrategyFactory::makeByStrategyType(
|
||||
$this->getModule()->emailChangeStrategy,
|
||||
$this
|
||||
@ -135,7 +136,7 @@ class SettingsForm extends Model
|
||||
return $strategy->run();
|
||||
}
|
||||
|
||||
return $this->user->save();
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@ -39,17 +39,23 @@ class UserBlockService implements ServiceInterface
|
||||
public function run()
|
||||
{
|
||||
if ($this->model->getIsBlocked()) {
|
||||
$this->controller->trigger(UserEvent::EVENT_BEFORE_UNBLOCK, $this->event);
|
||||
$this->triggerEvents(UserEvent::EVENT_BEFORE_UNBLOCK);
|
||||
$result = (bool)$this->model->updateAttributes(['blocked_at' => null]);
|
||||
$this->controller->trigger(UserEvent::EVENT_AFTER_UNBLOCK, $this->event);
|
||||
$this->triggerEvents(UserEvent::EVENT_AFTER_UNBLOCK);
|
||||
} else {
|
||||
$this->controller->trigger(UserEvent::EVENT_BEFORE_BLOCK, $this->event);
|
||||
$this->triggerEvents(UserEvent::EVENT_BEFORE_BLOCK);
|
||||
$result = (bool)$this->model->updateAttributes(
|
||||
['blocked_at' => time(), 'auth_key' => $this->securityHelper->generateRandomString()]
|
||||
);
|
||||
$this->controller->trigger(UserEvent::EVENT_AFTER_BLOCK, $this->event);
|
||||
$this->triggerEvents(UserEvent::EVENT_AFTER_BLOCK);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function triggerEvents($name)
|
||||
{
|
||||
$this->controller->trigger($name, $this->event);
|
||||
$this->model->trigger($name, $this->event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user