Add optional to control wether a welcome mail should be send after a registration by social network

This commit is contained in:
Elias Luhr
2024-01-05 15:49:25 +01:00
parent e5d5ea426d
commit 8a81ad7c42
4 changed files with 16 additions and 3 deletions

View File

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

View File

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

View File

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

View File

@ -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.',