Confirmation e-mail sending disableable in config

This commit is contained in:
Marcin Kurczewski 2013-10-16 19:56:02 +02:00
parent 6dd6163833
commit 5d5440a8f1
3 changed files with 21 additions and 12 deletions

View file

@ -29,12 +29,13 @@ salt = "1A2/$_4xVa"
needEmailForRegistering = 1 needEmailForRegistering = 1
needEmailForCommenting = 0 needEmailForCommenting = 0
needEmailForUploading = 1 needEmailForUploading = 1
activationEmailSenderName = "{host} registration engine" confirmationEmailEnabled = 1
activationEmailSenderEmail = "noreply@{host}" confirmationEmailSenderName = "{host} registration engine"
activationEmailSubject = "{host} activation" confirmationEmailSenderEmail = "noreply@{host}"
activationEmailBody = "Hello, confirmationEmailSubject = "{host} activation"
confirmationEmailBody = "Hello,
You received this e-mail because someone registered an user with this address at {host}. If it's you, visit {link} to finish registration process, otherwise you may ignore and delete this e-mail. You received this e-mail because someone registered a user with this address at {host}. If it's you, visit {link} to finish registration process, otherwise you may ignore and delete this e-mail.
Kind regards, Kind regards,
{host} registration engine" {host} registration engine"

View file

@ -9,18 +9,26 @@ class UserController
return $user; return $user;
} }
private static function sendEmailConfirmation($user) private static function sendEmailConfirmation(&$user)
{ {
\Chibi\Registry::getContext()->mailSent = true;
$regConfig = \Chibi\Registry::getConfig()->registration; $regConfig = \Chibi\Registry::getConfig()->registration;
if (!$regConfig->confirmationEmailEnabled)
{
$user->email_confirmed = $user->email_unconfirmed;
$user->email_unconfirmed = null;
return;
}
\Chibi\Registry::getContext()->mailSent = true;
$tokens = []; $tokens = [];
$tokens['host'] = $_SERVER['HTTP_HOST']; $tokens['host'] = $_SERVER['HTTP_HOST'];
$tokens['link'] = \Chibi\UrlHelper::route('user', 'activation', ['token' => $user->email_token]); $tokens['link'] = \Chibi\UrlHelper::route('user', 'activation', ['token' => $user->email_token]);
$body = wordwrap(TextHelper::replaceTokens($regConfig->activationEmailBody, $tokens), 70); $body = wordwrap(TextHelper::replaceTokens($regConfig->confirmationEmailBody, $tokens), 70);
$subject = TextHelper::replaceTokens($regConfig->activationEmailSubject, $tokens); $subject = TextHelper::replaceTokens($regConfig->confirmationEmailSubject, $tokens);
$senderName = TextHelper::replaceTokens($regConfig->activationEmailSenderName, $tokens); $senderName = TextHelper::replaceTokens($regConfig->confirmationEmailSenderName, $tokens);
$senderEmail = $regConfig->activationEmailSenderEmail; $senderEmail = $regConfig->confirmationEmailSenderEmail;
$recipientEmail = $user->email_unconfirmed; $recipientEmail = $user->email_unconfirmed;
$headers = []; $headers = [];

View file

@ -27,7 +27,7 @@ function configFactory()
$configPaths = $configPaths =
[ [
__DIR__ . DS . '../config.ini', __DIR__ . DS . '../config.ini',
__DIR__ . DS . '../local.ini' __DIR__ . DS . '../local.ini',
]; ];
$configPaths = array_filter($configPaths, 'file_exists'); $configPaths = array_filter($configPaths, 'file_exists');