From ef514bc4bd13fc5a05303f4cb065abddd078250e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 9 Oct 2019 09:04:51 +0300 Subject: [PATCH] add notifications for mail and password changes update and shorten some other message templates --- classes/digest.php | 2 ++ classes/handler/public.php | 1 + classes/pref/prefs.php | 36 ++++++++++++++++++++++++++ plugins/auth_internal/init.php | 26 +++++++++++++++++++ templates/digest_template.txt | 1 + templates/digest_template_html.txt | 4 ++- templates/email_article_template.txt | 2 +- templates/mail_change_template.txt | 10 +++++++ templates/password_change_template.txt | 10 +++++++ templates/resetpass_link_template.txt | 3 ++- templates/resetpass_template.txt | 9 ------- 11 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 templates/mail_change_template.txt create mode 100644 templates/password_change_template.txt delete mode 100644 templates/resetpass_template.txt diff --git a/classes/digest.php b/classes/digest.php index f2533d160..c9e9f24e7 100644 --- a/classes/digest.php +++ b/classes/digest.php @@ -103,9 +103,11 @@ class Digest $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); $tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); + $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH); $affected_ids = array(); diff --git a/classes/handler/public.php b/classes/handler/public.php index e2082ff1e..b81fb03b8 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -996,6 +996,7 @@ class Handler_Public extends Handler { $tpl->setVariable('LOGIN', $login); $tpl->setVariable('RESETPASS_LINK', $resetpass_link); + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); $tpl->addBlock('message'); diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index e7e7a365e..dd9c2868b 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -122,6 +122,11 @@ class Pref_Prefs extends Handler_Protected { $new_pw = clean($_POST["new_password"]); $con_pw = clean($_POST["confirm_password"]); + if ($old_pw == $new_pw) { + print "ERROR: ".format_error("New password must be different from the old one."); + return; + } + if ($old_pw == "") { print "ERROR: ".format_error("Old password cannot be blank."); return; @@ -194,6 +199,37 @@ class Pref_Prefs extends Handler_Protected { $full_name = clean($_POST["full_name"]); $active_uid = $_SESSION["uid"]; + $sth = $this->pdo->prepare("SELECT email, login, full_name FROM ttrss_users WHERE id = ?"); + $sth->execute([$active_uid]); + + if ($row = $sth->fetch()) { + $old_email = $row["email"]; + + if ($old_email != $email) { + $mailer = new Mailer(); + + require_once "lib/MiniTemplator.class.php"; + + $tpl = new MiniTemplator; + + $tpl->readTemplateFromFile("templates/mail_change_template.txt"); + + $tpl->setVariable('LOGIN', $row["login"]); + $tpl->setVariable('NEWMAIL', $email); + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + + $tpl->addBlock('message'); + + $tpl->generateOutputToString($message); + + $mailer->mail(["to_name" => $row["login"], + "to_address" => $row["email"], + "subject" => "[tt-rss] Mail address change notification", + "message" => $message]); + + } + } + $sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ?, full_name = ? WHERE id = ?"); $sth->execute([$email, $full_name, $active_uid]); diff --git a/plugins/auth_internal/init.php b/plugins/auth_internal/init.php index 8200ddc02..b9c26b3c2 100644 --- a/plugins/auth_internal/init.php +++ b/plugins/auth_internal/init.php @@ -211,6 +211,32 @@ class Auth_Internal extends Plugin implements IAuthModule { $_SESSION["pwd_hash"] = $new_password_hash; + $sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?"); + $sth->execute([$owner_uid]); + + if ($row = $sth->fetch()) { + $mailer = new Mailer(); + + require_once "lib/MiniTemplator.class.php"; + + $tpl = new MiniTemplator; + + $tpl->readTemplateFromFile("templates/password_change_template.txt"); + + $tpl->setVariable('LOGIN', $row["login"]); + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + + $tpl->addBlock('message'); + + $tpl->generateOutputToString($message); + + $mailer->mail(["to_name" => $row["login"], + "to_address" => $row["email"], + "subject" => "[tt-rss] Password change notification", + "message" => $message]); + + } + return __("Password has been changed."); } else { return "ERROR: ".__('Old password is incorrect.'); diff --git a/templates/digest_template.txt b/templates/digest_template.txt index aa56fb3ae..841f8ee98 100644 --- a/templates/digest_template.txt +++ b/templates/digest_template.txt @@ -11,4 +11,5 @@ ${FEED_TITLE} -- To unsubscribe, visit your configuration options or contact instance owner. +Sent by tt-rss mailer daemon at ${TTRSS_HOST}. diff --git a/templates/digest_template_html.txt b/templates/digest_template_html.txt index ede93d917..f38d98a21 100644 --- a/templates/digest_template_html.txt +++ b/templates/digest_template_html.txt @@ -14,5 +14,7 @@
-To unsubscribe, visit your configuration options or contact instance owner. + +To unsubscribe, visit your configuration options or contact instance owner.
+Sent by tt-rss mailer daemon at ${TTRSS_HOST}. diff --git a/templates/email_article_template.txt b/templates/email_article_template.txt index b6bc63921..c955100a0 100644 --- a/templates/email_article_template.txt +++ b/templates/email_article_template.txt @@ -12,5 +12,5 @@ Thought I'd share the following with you: -- -This message has been sent by Tiny Tiny RSS installation at ${TTRSS_HOST}. +Sent by Tiny Tiny RSS mailer daemon at ${TTRSS_HOST}. diff --git a/templates/mail_change_template.txt b/templates/mail_change_template.txt new file mode 100644 index 000000000..1f7b2a60e --- /dev/null +++ b/templates/mail_change_template.txt @@ -0,0 +1,10 @@ + +Hello, ${LOGIN}. + +Your mail address for this Tiny Tiny RSS instance has been changed to ${NEWMAIL}. + +If you haven't requested this change, consider contacting your instance owner or resetting your password. + +-- +Sent by tt-rss mailer daemon at ${TTRSS_HOST}. + diff --git a/templates/password_change_template.txt b/templates/password_change_template.txt new file mode 100644 index 000000000..a5fa9c761 --- /dev/null +++ b/templates/password_change_template.txt @@ -0,0 +1,10 @@ + +Hello, ${LOGIN}. + +Your password for this Tiny Tiny RSS instance has been changed. + +If you haven't requested this change, consider contacting your instance owner. + +-- +Sent by tt-rss mailer daemon at ${TTRSS_HOST}. + diff --git a/templates/resetpass_link_template.txt b/templates/resetpass_link_template.txt index d238c8616..c5c5d5f3a 100644 --- a/templates/resetpass_link_template.txt +++ b/templates/resetpass_link_template.txt @@ -10,5 +10,6 @@ Please note that the above link will only be valid for the next 15 minutes. If you don't want to reset your password, ignore this message. -Sincerely, Tiny Tiny RSS Mail Daemon. +-- +Sent by tt-rss mailer daemon at ${TTRSS_HOST}. diff --git a/templates/resetpass_template.txt b/templates/resetpass_template.txt deleted file mode 100644 index c262f9a77..000000000 --- a/templates/resetpass_template.txt +++ /dev/null @@ -1,9 +0,0 @@ - -Hello, ${LOGIN}. - -Your password for this Tiny Tiny RSS installation has been reset. - -Your new password is ${NEWPASS}, please remember it for later reference. - -Sincerely, Tiny Tiny RSS Mail Daemon. -