Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 5dfce0a

Browse files
committed
send real confirmation email for user registration regardless (bug 777662)
1 parent 15a844a commit 5dfce0a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

apps/amo/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def paginate(request, queryset, per_page=20, count=None):
139139

140140
def send_mail(subject, message, from_email=None, recipient_list=None,
141141
fail_silently=False, use_blacklist=True, perm_setting=None,
142-
manage_url=None, headers=None, cc=None):
142+
manage_url=None, headers=None, cc=None, real_email=False):
143143
"""
144144
A wrapper around django.core.mail.EmailMessage.
145145
@@ -150,7 +150,7 @@ def send_mail(subject, message, from_email=None, recipient_list=None,
150150
if not recipient_list:
151151
return True
152152

153-
connection = get_email_backend()
153+
connection = get_email_backend(real_email)
154154

155155
if not from_email:
156156
from_email = settings.DEFAULT_FROM_EMAIL
@@ -716,12 +716,15 @@ def pop(cls, key, data=True):
716716
return False
717717

718718

719-
def get_email_backend():
719+
def get_email_backend(real_email=False):
720720
"""Get a connection to an email backend.
721721
722722
If settings.SEND_REAL_EMAIL is False, a debugging backend is returned.
723723
"""
724-
backend = None if settings.SEND_REAL_EMAIL else 'amo.mail.FakeEmailBackend'
724+
if real_email or settings.SEND_REAL_EMAIL:
725+
backend = None
726+
else:
727+
backend = 'amo.mail.FakeEmailBackend'
725728
return django.core.mail.get_connection(backend)
726729

727730

apps/users/tests/test_views.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,31 @@ def test_password_short(self):
163163
def test_email_change_mail_sent(self):
164164
data = {'username': 'jbalogh',
165165
'email': 'jbalogh.changed@mozilla.com',
166-
'display_name': 'DJ SurfNTurf', }
166+
'display_name': 'DJ SurfNTurf'}
167167

168168
r = self.client.post(self.url, data, follow=True)
169169
self.assertRedirects(r, self.url)
170-
self.assertContains(r, "An email has been sent to %s" % data['email'])
170+
self.assertContains(r, 'An email has been sent to %s' % data['email'])
171171

172172
# The email shouldn't change until they confirm, but the name should
173173
u = User.objects.get(id='4043307').get_profile()
174174
self.assertEquals(u.name, 'DJ SurfNTurf')
175175
self.assertEquals(u.email, 'jbalogh@mozilla.com')
176176

177177
eq_(len(mail.outbox), 1)
178-
assert mail.outbox[0].subject.find('Please confirm your email') == 0
178+
eq_(mail.outbox[0].subject.find('Please confirm your email'), 0)
179179
assert mail.outbox[0].body.find('%s/emailchange/' % self.user.id) > 0
180180

181+
@patch.object(settings, 'SEND_REAL_EMAIL', False)
182+
def test_email_change_mail_send_even_with_fake_email(self):
183+
data = {'username': 'jbalogh',
184+
'email': 'jbalogh.changed@mozilla.com',
185+
'display_name': 'DJ SurfNTurf'}
186+
187+
self.client.post(self.url, data, follow=True)
188+
eq_(len(mail.outbox), 1)
189+
eq_(mail.outbox[0].subject.find('Please confirm your email'), 0)
190+
181191
@patch.object(settings, 'APP_PREVIEW', True)
182192
def test_email_cant_change(self):
183193
data = {'username': 'jbalogh',

apps/users/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def edit(request):
220220
send_mail(_('Please confirm your email address '
221221
'change at %s' % domain),
222222
t.render(Context(c)), None, [amouser.email],
223-
use_blacklist=False)
223+
use_blacklist=False, real_email=True)
224224

225225
# Reset the original email back. We aren't changing their
226226
# address until they confirm the new one

0 commit comments

Comments
 (0)