Skip to content

Commit

Permalink
User emails for New, User Info, Password Request now use Templates an…
Browse files Browse the repository at this point in the history
…d is also sent as HTML

For feature #1003

Removed unused USER_sendActivationEmail function
  • Loading branch information
eSilverStrike committed Apr 5, 2022
1 parent b8570aa commit c5794de
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 103 deletions.
9 changes: 5 additions & 4 deletions language/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@
85 => 'Total number of comments:',
86 => 'Find all postings by',
87 => 'Your login name',
88 => "Someone (possibly you) has requested a new password for your account \"%s\" on {$_CONF['site_name']}, {$_CONF['site_url']}.\n\nIf you really want this action to be taken, please click on the following link:\n\n",
89 => "If you do not want this action to be taken, simply ignore this message and the request will be disregarded (your password will remain unchanged).\n\n",
88 => "Someone (possibly you) has requested a new password for your account \"%s\" on {$_CONF['site_name']}, {$_CONF['site_url']}.",
'user_password_action_msg' => 'If you really want this action to be taken, please click on the following link:',
89 => "If you do not want this action to be taken, simply ignore this message and the request will be disregarded (your password will remain unchanged).",
90 => 'You can enter a new password for your account below. Please note that your old password is still valid until you submit this form.',
91 => 'Set New Password',
92 => 'Enter New Password',
Expand Down Expand Up @@ -399,8 +400,8 @@
115 => 'Your account has been disabled, you may not login. Please contact an Administrator.',
116 => 'Account Awaiting Activation',
117 => 'Your account is currently awaiting activation by an administrator. You will not be able to login until your account has been approved.',
118 => "Your {$_CONF['site_name']} account has now been activated by an administrator. You may now login to the site at the url below using your username (<username>) and password as previously emailed to you.",
119 => 'If you have forgotten your password, you may request a new one at this url:',
118 => '',
119 => '',
120 => 'Account Activated',
121 => 'Service',
122 => 'Sorry, new user registration is disabled',
Expand Down
9 changes: 5 additions & 4 deletions language/english_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@
85 => 'Total number of comments:',
86 => 'Find all postings by',
87 => 'Your login name',
88 => "Someone (possibly you) has requested a new password for your account \"%s\" on {$_CONF['site_name']}, {$_CONF['site_url']}.\n\nIf you really want this action to be taken, please click on the following link:\n\n",
89 => "If you do not want this action to be taken, simply ignore this message and the request will be disregarded (your password will remain unchanged).\n\n",
88 => "Someone (possibly you) has requested a new password for your account \"%s\" on {$_CONF['site_name']}, {$_CONF['site_url']}.",
'user_password_action_msg' => 'If you really want this action to be taken, please click on the following link:',
89 => "If you do not want this action to be taken, simply ignore this message and the request will be disregarded (your password will remain unchanged).",
90 => 'You can enter a new password for your account below. Please note that your old password is still valid until you submit this form.',
91 => 'Set New Password',
92 => 'Enter New Password',
Expand Down Expand Up @@ -399,8 +400,8 @@
115 => 'Your account has been disabled, you may not login. Please contact an Administrator.',
116 => 'Account Awaiting Activation',
117 => 'Your account is currently awaiting activation by an administrator. You will not be able to login until your account has been approved.',
118 => "Your {$_CONF['site_name']} account has now been activated by an administrator. You may now login to the site at the url below using your username (<username>) and password as previously emailed to you.",
119 => 'If you have forgotten your password, you may request a new one at this url:',
118 => '',
119 => '',
120 => 'Account Activated',
121 => 'Service',
122 => 'Sorry, new user registration is disabled',
Expand Down
9 changes: 5 additions & 4 deletions language/japanese_utf-8.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
115 => '-',
116 => 'トラックバック',
117 => '記事一覧',
118 => '続きのページへ:',
119 => "<a href=\"{$_CONF['site_url']}/users.php?mode=getpassword\" rel=\"nofollow\">パスワード再設定</a>",
118 => '',
119 => '',
120 => 'このコメントへのパーマリンク',
121 => 'コメント (%d件)',
122 => 'トラックバック (%d件)',
Expand Down Expand Up @@ -378,8 +378,9 @@
85 => 'コメントの総数:',
86 => 'すべての投稿を検索:',
87 => 'あなたのログイン名',
88 => "%s さん、こんにちは。\n\n{$_CONF['site_name']}よりお知らせします。\n\n以下のページよりパスワード再設定の手続きを行って、そのパスワードで\n今後はログインするようにしてください。\n\nなお、このメールに覚えがない場合、他の方がメールアドレスを間違えて\n入力した可能性があります。パスワードを変更することはありませんので\n安心してください。\n\n",
89 => "パスワードを変えたくない場合はこのメッセージを無視してください。\n(パスワードは変わりません。)\n\n",
88 => "Someone (possibly you) has requested a new password for your account \"%s\" on {$_CONF['site_name']}, {$_CONF['site_url']}.",
'user_password_action_msg' => "If you really want this action to be taken, please click on the following link:",
89 => "パスワードを変えたくない場合はこのメッセージを無視してください。\n(パスワードは変わりません。)",
90 => '新しいパスワードを入力して「再設定」ボタンを押してください。',
91 => '再設定',
92 => 'パスワードの再設定',
Expand Down
9 changes: 9 additions & 0 deletions public_html/layout/denim/emails/user_info-html.thtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>{lang_user_info_msg}</p>

<p>{lang_username}: {username}<br{XHTML}>
{lang_password}: {password}</p>

<p>{lang_password_msg}</p>

<p>{site_name}{!if site_slogan} - {site_slogan}{!endif}<br{XHTML}>
<a href="{site_url}">{site_url}</a></p>
14 changes: 14 additions & 0 deletions public_html/layout/denim/emails/user_info-plaintext.thtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{lang_user_info_msg}


{lang_username}: {username}

{lang_password}: {password}


{lang_password_msg}


{site_name}{!if site_slogan} - {site_slogan}{!endif}

{site_url}
7 changes: 7 additions & 0 deletions public_html/layout/denim/emails/user_new-html.thtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>{lang_username}: {username}<br{XHTML}>
{lang_email}: {email}<br{XHTML}>
{lang_date}: {date}</p>

{email_divider_html}

<p>{lang_profile_url_label}: {profile_url}</p>
10 changes: 10 additions & 0 deletions public_html/layout/denim/emails/user_new-plaintext.thtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{lang_username}: {username}

{lang_email}: {email}

{lang_date}: {date}


{email_divider}

{lang_profile_url_label}: {profile_url}
10 changes: 10 additions & 0 deletions public_html/layout/denim/emails/user_password-html.thtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>{lang_user_request_msg}</p>

<p>{lang_user_action_msg}</p>

<p><a href="{new_password_url}">{new_password_url}</a></p>

<p>{lang_ignore_request_msg}</p>

<p>{site_name}{!if site_slogan} - {site_slogan}{!endif}<br{XHTML}>
<a href="{site_url}">{site_url}</a></p>
15 changes: 15 additions & 0 deletions public_html/layout/denim/emails/user_password-plaintext.thtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{lang_user_request_msg}


{lang_user_action_msg}


{new_password_url}


{lang_ignore_request_msg}


{site_name}{!if site_slogan} - {site_slogan}{!endif}

{site_url}
42 changes: 31 additions & 11 deletions public_html/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function USER_emailPassword($username, $msg = 0)
*/
function USER_requestPassword($username)
{
global $_CONF, $_TABLES, $LANG04;
global $_CONF, $_TABLES, $LANG04, $LANG31;

$retval = '';

Expand All @@ -123,20 +123,40 @@ function USER_requestPassword($username)
$reqid = substr(md5(uniqid(rand(), 1)), 1, 16);
DB_change($_TABLES['users'], 'pwrequestid', "$reqid",
'uid', $A['uid']);

$mailtext = sprintf($LANG04[88], $username);
$mailtext .= $_CONF['site_url'] . '/users.php?mode=newpwd&uid=' . $A['uid'] . '&rid=' . $reqid . "\n\n";
$mailtext .= $LANG04[89];
$mailtext .= "{$_CONF['site_name']}\n";
$mailtext .= "{$_CONF['site_url']}\n";

$subject = $_CONF['site_name'] . ': ' . $LANG04[16];
if (COM_mail($A['email'], $subject, $mailtext)) {




// Create HTML and plaintext version of email
$t = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'emails/'));

$t->set_file(array('email_html' => 'user_password-html.thtml'));
$t->set_file(array('email_plaintext' => 'user_password-plaintext.thtml'));

$t->set_var('email_divider', $LANG31['email_divider']);
$t->set_var('email_divider_html', $LANG31['email_divider_html']);
$t->set_var('LB', LB);

$t->set_var('lang_user_request_msg', sprintf($LANG04[88], $username));
$t->set_var('lang_user_action_msg', $LANG04['user_password_action_msg']);
$t->set_var('new_password_url', $_CONF['site_url'] . '/users.php?mode=newpwd&uid=' . $A['uid'] . '&rid=' . $reqid);
$t->set_var('lang_ignore_request_msg', $LANG04[89]);
$t->set_var('site_name', $_CONF['site_name']);
$t->set_var('site_url', $_CONF['site_url']);
$t->set_var('site_slogan', $_CONF['site_slogan']);

// Output final content
$message[] = $t->parse('output', 'email_html');
$message[] = $t->parse('output', 'email_plaintext');

$mailSubject = $_CONF['site_name'] . ': ' . $LANG04[16];

if (COM_mail($A['email'], $mailSubject, $message, '', true)) {
$msg = 55; // message sent
} else {
$msg = 85; // problem sending the email
}

$redirect = $_CONF['site_url'] . "/index.php?msg=$msg";
COM_updateSpeedlimit('password');
COM_redirect($redirect);
Expand Down
2 changes: 0 additions & 2 deletions public_html/usersettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,6 @@ function notifyAdminOfUserUpdate(array $A)
global $_CONF, $LANG04, $LANG08, $LANG29, $LANG31;

if (in_array('user_update', $_CONF['notification'])) {


// Create HTML and plaintext version of submission email
$t = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'emails/'));

Expand Down
138 changes: 60 additions & 78 deletions system/lib-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,75 +139,43 @@ function USER_deleteAccount($uid)
*/
function USER_createAndSendPassword($username, $useremail, $uid, $email_type = '')
{
global $_CONF, $LANG04;
global $_CONF, $LANG04, $LANG31;

$passwd = null;
SEC_updateUserPassword($passwd, $uid);

if ($email_type == '' && file_exists($_CONF['path_data'] . 'welcome_email.txt')) {
$template = COM_newTemplate(CTL_core_templatePath($_CONF['path_data']));
$template->set_file(array('mail' => 'welcome_email.txt'));
$template->set_var('auth_info',
"$LANG04[2]: $username\n$LANG04[4]: $passwd");
$template->set_var('site_name', $_CONF['site_name']);
$template->set_var('site_slogan', $_CONF['site_slogan']);
$template->set_var('lang_text1', $LANG04[15]);
$template->set_var('lang_text2', $LANG04[14]);
$template->set_var('lang_username', $LANG04[2]);
$template->set_var('lang_password', $LANG04[4]);
$template->set_var('username', $username);
$template->set_var('password', $passwd);
$template->set_var('name', COM_getDisplayName($uid));
$template->parse('output', 'mail');
$mailtext = $template->get_var('output');
} else {
if ($email_type == 'convert_remote') {
$mailtext = $LANG04['email_convert_remote'] . "\n\n";
} else {
$mailtext = $LANG04[15] . "\n\n";
}
$mailtext .= $LANG04[2] . ": $username\n";
$mailtext .= $LANG04[4] . ": $passwd\n\n";
$mailtext .= $LANG04[14] . "\n\n";
$mailtext .= $_CONF['site_name'] . "\n";
$mailtext .= $_CONF['site_url'] . "\n";
}
$subject = $_CONF['site_name'] . ': ' . $LANG04[16];

return COM_mail($useremail, $subject, $mailtext);
}

/**
* Inform a user their account has been activated.
*
* @param string $userName user's login name
* @param string $userEmail user's email address
* @return boolean true = success, false = an error occurred
*/
function USER_sendActivationEmail($userName, $userEmail)
{
global $_CONF, $LANG04;

if (file_exists($_CONF['path_data'] . 'activation_email.txt')) {
$template = COM_newTemplate(CTL_core_templatePath($_CONF['path_data']));
$template->set_file(array('mail' => 'activation_email.txt'));
$template->set_var('site_name', $_CONF['site_name']);
$template->set_var('site_slogan', $_CONF['site_slogan']);
$template->set_var('lang_text1', $LANG04[15]);
$template->set_var('lang_text2', $LANG04[14]);
$template->parse('output', 'mail');
$mailText = $template->get_var('output');
} else {
$mailText = str_replace("<username>", $userName, $LANG04[118]) . "\n\n";
$mailText .= $_CONF['site_url'] . "\n\n";
$mailText .= $LANG04[119] . "\n\n";
$mailText .= $_CONF['site_url'] . "/users.php?mode=getpassword\n\n";
$mailText .= $_CONF['site_name'] . "\n";
$mailText .= $_CONF['site_url'] . "\n";
}
$subject = $_CONF['site_name'] . ': ' . $LANG04[120];
// Create HTML and plaintext version of email
$t = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'emails/'));

$t->set_file(array('email_html' => 'user_info-html.thtml'));
$t->set_file(array('email_plaintext' => 'user_info-plaintext.thtml'));

return COM_mail($userEmail, $subject, $mailText);
$t->set_var('email_divider', $LANG31['email_divider']);
$t->set_var('email_divider_html', $LANG31['email_divider_html']);
$t->set_var('LB', LB);

if ($email_type == 'convert_remote') {
$t->set_var('lang_user_info_msg', $LANG04['email_convert_remote']);
} else {
$t->set_var('lang_user_info_msg', $LANG04[15]);
}
$t->set_var('lang_username', $LANG04[2]);
$t->set_var('username', $username);
$t->set_var('name', COM_getDisplayName($uid));
$t->set_var('lang_password', $LANG04[4]);
$t->set_var('password', $passwd);
$t->set_var('lang_password_msg', $LANG04[14]);
$t->set_var('site_name', $_CONF['site_name']);
$t->set_var('site_url', $_CONF['site_url']);
$t->set_var('site_slogan', $_CONF['site_slogan']);

// Output final content
$message[] = $t->parse('output', 'email_html');
$message[] = $t->parse('output', 'email_plaintext');

$mailSubject = $_CONF['site_name'] . ': ' . $LANG04[16];

return COM_mail($useremail, $mailSubject, $message, '', true);
}

/**
Expand Down Expand Up @@ -338,28 +306,42 @@ function USER_createAccount($username, $email, $passwd = '', $fullname = '', $ho
*/
function USER_sendNotification($userName, $email, $uid, $mode = 'inactive')
{
global $_CONF, $LANG01, $LANG04, $LANG08, $LANG28, $LANG29;
global $_CONF, $LANG01, $LANG04, $LANG08, $LANG28, $LANG29, $LANG31;

$mailBody = "$LANG04[2]: $userName\n"
. "$LANG04[5]: $email\n"
. "$LANG28[14]: " . COM_strftime($_CONF['date']) . "\n\n";
// Create HTML and plaintext version of submission email
$t = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout'] . 'emails/'));

$t->set_file(array('email_html' => 'user_new-html.thtml'));
$t->set_file(array('email_plaintext' => 'user_new-plaintext.thtml'));

$t->set_var('email_divider', $LANG31['email_divider']);
$t->set_var('email_divider_html', $LANG31['email_divider_html']);
$t->set_var('LB', LB);

$t->set_var('lang_username', $LANG04[2]);
$t->set_var('username', $userName);
$t->set_var('lang_email', $LANG04[5]);
$t->set_var('email', $email);
$t->set_var('lang_date', $LANG28[14]);
$t->set_var('date', COM_strftime($_CONF['date']));

if ($mode === 'inactive') {
// user needs admin approval
$mailBody .= "{$LANG01[10]}: {$_CONF['site_admin_url']}/moderation.php\n";
$t->set_var('lang_profile_url_label', $LANG01[10]);
$t->set_var('profile_url', "{$_CONF['site_admin_url']}/moderation.php");
} else {
// user has been created, or has activated themselves:
$mailBody .= "{$LANG29[4]}: {$_CONF['site_url']}/users.php?mode=profile&uid={$uid}\n";
$t->set_var('lang_profile_url_label', $LANG29[4]);
$t->set_var('profile_url', "{$_CONF['site_url']}/users.php?mode=profile&uid={$uid}");
}

$mailBody .= "IP: " . \Geeklog\IP::getIPAddress() . "\n\n";
$mailBody .= "\n------------------------------\n";
$mailBody .= "\n{$LANG08[34]}\n";
$mailBody .= "\n------------------------------\n";

$mailSubject = $_CONF['site_name'] . ' ' . $LANG29[40];

return COM_mail($_CONF['site_mail'], $mailSubject, $mailBody);
// Output final content
$message[] = $t->parse('output', 'email_html');
$message[] = $t->parse('output', 'email_plaintext');

$mailSubject = $_CONF['site_name'] . ' ' . $LANG29[40];

return COM_mail($_CONF['site_mail'], $mailSubject, $message, '', true);
}

/**
Expand Down

0 comments on commit c5794de

Please sign in to comment.