diff --git a/docs/install/configuration-options.md b/docs/install/configuration-options.md index 7cdf9ed..ba775e1 100755 --- a/docs/install/configuration-options.md +++ b/docs/install/configuration-options.md @@ -148,6 +148,10 @@ register by throwing a `NotFoundHttpException` if the `RegistrationController::a Setting this attribute allows the registration process via social networks. If you set it to `false`, the module won't allow users to register. +#### sendWelcomeMailAfterSocialNetworkRegistration (type: `boolean`, default: `true`) + +Setting this attribute controls wether a confirmation mail should be send or not. + #### enableEmailConfirmation (type: `boolean`, default: `true`) If `true`, the module will send an email with a confirmation link that user needs to click through to complete its diff --git a/src/User/Controller/RegistrationController.php b/src/User/Controller/RegistrationController.php index c1c11f6..0cfe195 100644 --- a/src/User/Controller/RegistrationController.php +++ b/src/User/Controller/RegistrationController.php @@ -17,6 +17,7 @@ use Da\User\Event\UserEvent; use Da\User\Factory\MailFactory; use Da\User\Form\RegistrationForm; use Da\User\Form\ResendForm; +use Da\User\Helper\SecurityHelper; use Da\User\Model\SocialNetworkAccount; use Da\User\Model\User; use Da\User\Query\SocialNetworkAccountQuery; @@ -175,7 +176,11 @@ class RegistrationController extends Controller if ($user->load(Yii::$app->request->post()) && $user->validate()) { $this->trigger(SocialNetworkConnectEvent::EVENT_BEFORE_CONNECT, $event); - $mailService = MailFactory::makeWelcomeMailerService($user); + if ($this->module->sendWelcomeMailAfterSocialNetworkRegistration) { + $mailService = MailFactory::makeWelcomeMailerService($user); + } else { + $mailService = null; + } if ($this->make(UserCreateService::class, [$user, $mailService])->run()) { $account->connect($user); $this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_CONNECT, $event); diff --git a/src/User/Module.php b/src/User/Module.php index f160d02..d8b4e03 100755 --- a/src/User/Module.php +++ b/src/User/Module.php @@ -121,6 +121,10 @@ class Module extends BaseModule * @var bool whether to allow registration process for social network or not */ public $enableSocialNetworkRegistration = true; + /** + * @var bool whether to send a welcome mail after the registration process for social network + */ + public $sendWelcomeMailAfterSocialNetworkRegistration = true; /** * @var bool whether to force email confirmation to */ diff --git a/src/User/Service/UserCreateService.php b/src/User/Service/UserCreateService.php index 74ecc73..491873e 100644 --- a/src/User/Service/UserCreateService.php +++ b/src/User/Service/UserCreateService.php @@ -31,7 +31,7 @@ class UserCreateService implements ServiceInterface protected $securityHelper; protected $mailService; - public function __construct(User $model, MailService $mailService, SecurityHelper $securityHelper) + public function __construct(User $model, ?MailService $mailService, SecurityHelper $securityHelper) { $this->model = $model; $this->mailService = $mailService; @@ -70,7 +70,7 @@ class UserCreateService implements ServiceInterface } $model->trigger(UserEvent::EVENT_AFTER_CREATE, $event); - if (!$this->sendMail($model)) { + if ($this->mailService instanceof MailService && !$this->sendMail($model)) { $error_msg = Yii::t( 'usuario', 'Error sending welcome message to "{email}". Please try again later.',