fixed all tests

This commit is contained in:
Antonio Ramirez
2016-12-11 21:34:22 +01:00
parent 4588d77129
commit 4c9b9671b5
37 changed files with 214 additions and 135 deletions

View File

@ -105,7 +105,7 @@ class AdminController extends Controller
public function actionCreate()
{
/** @var User $user */
$user = $this->make(User::class, ['scenario' => 'create']);
$user = $this->make(User::class, [], ['scenario' => 'create']);
/** @var UserEvent $event */
$event = $this->make(UserEvent::class, [$user]);
@ -168,7 +168,7 @@ class AdminController extends Controller
$this->make(AjaxRequestModelValidator::class, [$user])->validate();
if ($profile->load(Yii::$app->request->post())) {
if($profile->save()) {
if ($profile->save()) {
$this->trigger(UserEvent::EVENT_BEFORE_PROFILE_UPDATE, $event);
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile details have been updated'));
$this->trigger(UserEvent::EVENT_AFTER_PROFILE_UPDATE, $event);

View File

@ -74,7 +74,7 @@ class RecoveryController extends Controller
}
/** @var RecoveryForm $form */
$form = $this->make(RecoveryForm::class, ['scenario' => RecoveryForm::SCENARIO_REQUEST]);
$form = $this->make(RecoveryForm::class, [], ['scenario' => RecoveryForm::SCENARIO_REQUEST]);
$event = $this->make(FormEvent::class, [$form]);
@ -87,6 +87,7 @@ class RecoveryController extends Controller
$mailService = MailFactory::makeRecoveryMailerService($form->email);
if ($this->make(PasswordRecoveryService::class, [$form->email, $mailService])->run()) {
$this->trigger(FormEvent::EVENT_AFTER_REQUEST, $event);
return $this->render(
@ -139,7 +140,7 @@ class RecoveryController extends Controller
}
/** @var RecoveryForm $form */
$form = $this->make(RecoveryForm::class, ['scenario' => RecoveryForm::SCENARIO_RESET]);
$form = $this->make(RecoveryForm::class, [], ['scenario' => RecoveryForm::SCENARIO_RESET]);
$event = $event->updateForm($form);
$this->make(AjaxRequestModelValidator::class, [$form])->validate();

View File

@ -12,13 +12,11 @@ use Da\User\Model\User;
use Da\User\Query\SocialNetworkAccountQuery;
use Da\User\Query\UserQuery;
use Da\User\Service\AccountConfirmationService;
use Da\User\Service\EmailConfirmationService;
use Da\User\Service\ResendConfirmationService;
use Da\User\Service\UserConfirmationService;
use Da\User\Service\UserCreateService;
use Da\User\Service\UserRegisterService;
use Da\User\Traits\ContainerTrait;
use Da\User\Traits\ModuleTrait;
use Da\User\Validator\AjaxRequestModelValidator;
use Yii;
use yii\base\Module;
@ -81,7 +79,7 @@ class RegistrationController extends Controller
public function actionRegister()
{
if(!$this->module->enableRegistration) {
if (!$this->module->enableRegistration) {
throw new NotFoundHttpException();
}
/** @var RegistrationForm $form */
@ -91,14 +89,15 @@ class RegistrationController extends Controller
$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);
$user = $this->make(User::class, [$form->attributes]);
$user = $this->make(User::class, [], $form->attributes);
$user->setScenario('register');
$mailService = MailFactory::makeWelcomeMailerService($user);
if($this->make(UserRegisterService::class, [$user, $mailService])->run()) {
if ($this->make(UserRegisterService::class, [$user, $mailService])->run()) {
Yii::$app->session->setFlash(
'info',
Yii::t(
@ -106,16 +105,24 @@ class RegistrationController extends Controller
'Your account has been created and a message with further instructions has been sent to your email'
)
);
return $this->render('/shared/message', [
'title' => Yii::t('user', 'Your account has been created')
]);
}
return $this->render('register', [
'model' => $form,
'module' => $this->module,
]);
return $this->render(
'/shared/message',
[
'title' => Yii::t('user', 'Your account has been created'),
'module' => $this->module
]
);
}
}
return $this->render(
'register',
[
'model' => $form,
'module' => $this->module,
]
);
}
public function actionConnect($code)
@ -206,29 +213,48 @@ class RegistrationController extends Controller
$this->make(AjaxRequestModelValidator::class, [$form])->validate();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
$this->trigger(FormEvent::EVENT_BEFORE_RESEND, $event);
/** @var User $user */
$user = $this->userQuery->whereEmail($form->email)->one();
$mailService = MailFactory::makeConfirmationMailerService($user);
if ($this->make(ResendConfirmationService::class, [$user, $mailService])->run()) {
$this->trigger(FormEvent::EVENT_AFTER_RESEND, $event);
Yii::$app->session->setFlash(
'info',
Yii::t(
'user',
'A message has been sent to your email address. It contains a confirmation link that you must
click to complete registration.'
)
);
} else {
$success = true;
if ($user !== null) {
$this->trigger(FormEvent::EVENT_BEFORE_RESEND, $event);
$mailService = MailFactory::makeConfirmationMailerService($user);
if ($success = $this->make(ResendConfirmationService::class, [$user, $mailService])->run()) {
$this->trigger(FormEvent::EVENT_AFTER_RESEND, $event);
Yii::$app->session->setFlash(
'info',
Yii::t(
'user',
'A message has been sent to your email address. ' .
'It contains a confirmation link that you must click to complete registration.'
)
);
}
}
if ($user === null || $success === false) {
Yii::$app->session->setFlash(
'danger',
Yii::t(
'user',
'We couldn\'t re-send the mail to confirm your address. Please, verify is the correct email.'
'We couldn\'t re-send the mail to confirm your address. ' .
'Please, verify is the correct email or if it has been confirmed already.'
)
);
}
return $this->render('/shared/message', [
'title' => $success
? Yii::t('user', 'A new confirmation link has been sent')
: Yii::t('user', 'Unable to send confirmation link'),
'module' => $this->module,
]);
}
return $this->render(
'resend',
[
'model' => $form,
]
);
}
}

View File

@ -126,6 +126,7 @@ class SettingsController extends Controller
public function actionAccount()
{
/** @var SettingsForm $form */
$form = $this->make(SettingsForm::class);
$event = $this->make(FormEvent::class, [$form]);
@ -133,8 +134,9 @@ class SettingsController extends Controller
if ($form->load(Yii::$app->request->post())) {
$this->trigger(UserEvent::EVENT_BEFORE_ACCOUNT_UPDATE, $event);
if ($form->save()) {
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Your account details have been updated-'));
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Your account details have been updated'));
$this->trigger(UserEvent::EVENT_AFTER_ACCOUNT_UPDATE, $event);
return $this->refresh();