From ae8a100d98440ee5ddcf644bccd3db023523bc53 Mon Sep 17 00:00:00 2001 From: Ricky Ramirez Date: Wed, 19 Jun 2013 16:45:31 -0700 Subject: [PATCH] Send notification when a user's email is changed. --- r2/r2/controllers/api.py | 2 ++ r2/r2/lib/emailer.py | 8 ++++++++ r2/r2/lib/pages/pages.py | 4 ++++ r2/r2/models/mail_queue.py | 2 ++ r2/r2/templates/emailchangeemail.email | 27 ++++++++++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 r2/r2/templates/emailchangeemail.email diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index a55983590..c136fbe75 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -927,6 +927,8 @@ class ApiController(RedditController, OAuth2ResourceController): if (not form.has_errors("email", errors.BAD_EMAILS) and email): if (not hasattr(c.user,'email') or c.user.email != email): + if c.user.email_verified: + emailer.email_change_email(c.user) c.user.email = email # unverified email for now c.user.email_verified = None diff --git a/r2/r2/lib/emailer.py b/r2/r2/lib/emailer.py index 4545d75cb..87b6766a2 100644 --- a/r2/r2/lib/emailer.py +++ b/r2/r2/lib/emailer.py @@ -113,6 +113,14 @@ def password_change_email(user): PasswordChangeEmail(user=user).render(style='email'), Email.Kind.PASSWORD_CHANGE) +def email_change_email(user): + """Queues a system email for a email change notification.""" + from r2.lib.pages import EmailChangeEmail + + return _system_email(user.email, + EmailChangeEmail(user=user).render(style='email'), + Email.Kind.EMAIL_CHANGE) + def feedback_email(email, body, name='', reply_to = ''): """Queues a feedback email to the feedback account.""" return _feedback_email(email, body, Email.Kind.FEEDBACK, name = name, diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 054b2367a..44c3d0bac 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -2064,6 +2064,10 @@ class PasswordChangeEmail(Templated): """Notification e-mail that a user's password has changed.""" pass +class EmailChangeEmail(Templated): + """Notification e-mail that a user's e-mail has changed.""" + pass + class VerifyEmail(Templated): pass diff --git a/r2/r2/models/mail_queue.py b/r2/r2/models/mail_queue.py index 26abf072d..47160ec14 100644 --- a/r2/r2/models/mail_queue.py +++ b/r2/r2/models/mail_queue.py @@ -302,6 +302,7 @@ class Email(object): "NERDMAIL", "GOLDMAIL", "PASSWORD_CHANGE", + "EMAIL_CHANGE", ) subjects = { @@ -322,6 +323,7 @@ class Email(object): Kind.NERDMAIL : _("[reddit] hey, nerd!"), Kind.GOLDMAIL : _("[reddit] reddit gold activation link"), Kind.PASSWORD_CHANGE : _("[reddit] your password has been changed"), + Kind.EMAIL_CHANGE : _("[reddit] your email address has been changed"), } def __init__(self, user, thing, email, from_name, date, ip, banned_ip, diff --git a/r2/r2/templates/emailchangeemail.email b/r2/r2/templates/emailchangeemail.email new file mode 100644 index 000000000..7f25e3a63 --- /dev/null +++ b/r2/r2/templates/emailchangeemail.email @@ -0,0 +1,27 @@ +## The contents of this file are subject to the Common Public Attribution +## License Version 1.0. (the "License"); you may not use this file except in +## compliance with the License. You may obtain a copy of the License at +## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public +## License Version 1.1, but Sections 14 and 15 have been added to cover use of +## software over a computer network and provide for limited attribution for the +## Original Developer. In addition, Exhibit A has been modified to be +## consistent with Exhibit B. +## +## Software distributed under the License is distributed on an "AS IS" basis, +## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +## the specific language governing rights and limitations under the License. +## +## The Original Code is reddit. +## +## The Original Developer is the Initial Developer. The Initial Developer of +## the Original Code is reddit Inc. +## +## All portions of the code written by reddit are Copyright (c) 2006-2013 +## reddit Inc. All Rights Reserved. +############################################################################### + +The e-mail address for /u/${thing.user.name} has been changed. This message is +being sent to your old e-mail address only. + +If you did not change your e-mail, please respond to this e-mail +immediately.