Skip to content

Commit b114e5e

Browse files
committed
Add simple view for setting testemailcc cookie when server is in test mode
- Legacy-Id: 3716
1 parent 8153a1c commit b114e5e

4 files changed

Lines changed: 70 additions & 1 deletion

File tree

ietf/ietfauth/forms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,6 @@ def save(self):
124124
debug.show('stdout')
125125
debug.show('stderr')
126126
return p.returncode
127+
128+
class TestEmailForm(forms.Form):
129+
email = forms.EmailField(required=False)

ietf/ietfauth/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
(r'^loggedin/$', views.ietf_loggedin),
1010
(r'^profile/$', views.profile),
1111
# (r'^login/(?P<user>[a-z0-9.@]+)/(?P<passwd>.+)$', views.url_login),
12+
(r'^testemail/$', views.test_email),
1213
)
1314

1415
urlpatterns += patterns('ietf.ietfauth.views',

ietf/ietfauth/views.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from django.utils import simplejson as json
4949
from django.utils.translation import ugettext as _
5050

51-
from forms import (RegistrationForm, PasswordForm, RecoverPasswordForm)
51+
from forms import *
5252

5353

5454
def index(request):
@@ -181,3 +181,43 @@ def ajax_check_username(request):
181181
error = _('This email is already in use')
182182
return HttpResponse(json.dumps({'error': error}), mimetype='text/plain')
183183

184+
def test_email(request):
185+
if settings.SERVER_MODE == "production":
186+
raise Http404()
187+
188+
# note that the cookie set here is only used when running in
189+
# "test" mode, normally you run the server in "development" mode,
190+
# in which case email is sent out as usual; for development, put
191+
# this
192+
#
193+
# EMAIL_HOST = 'localhost'
194+
# EMAIL_PORT = 1025
195+
# EMAIL_HOST_USER = None
196+
# EMAIL_HOST_PASSWORD = None
197+
# EMAIL_COPY_TO = ""
198+
#
199+
# in your settings.py and start a little debug email server in a
200+
# console with the following (it receives and prints messages)
201+
#
202+
# python -m smtpd -n -c DebuggingServer localhost:1025
203+
204+
cookie = None
205+
206+
if request.method == "POST":
207+
form = TestEmailForm(request.POST)
208+
if form.is_valid():
209+
cookie = form.cleaned_data['email']
210+
else:
211+
form = TestEmailForm(initial=dict(email=request.COOKIES.get('testemailcc')))
212+
213+
r = render_to_response('ietfauth/testemail.html',
214+
dict(form=form,
215+
cookie=cookie if cookie != None else request.COOKIES.get("testemailcc", "")
216+
),
217+
context_instance=RequestContext(request))
218+
219+
if cookie != None:
220+
r.set_cookie("testemailcc", cookie)
221+
222+
return r
223+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends "base.html" %}
2+
3+
{% block title %}Set up test email address{% endblock %}
4+
5+
{% block content %}
6+
<h1>Set up test email address</h1>
7+
8+
<p>Since this server is running in test mode, all email to be sent out
9+
is intercepted and thrown away.</p>
10+
11+
<p>To receive a copy of each message before it's thrown away, you can
12+
set an email address below. The address is stored in the <code>testmailcc</code>
13+
cookie in your browser. So make sure cookies are enabled.</p>
14+
15+
<p>Value of <code>testmailcc</code>: {{ cookie }}</p>
16+
17+
<form action="" method="post">
18+
<table>
19+
{{ form.as_table }}
20+
</table>
21+
<div>
22+
<input type="submit" value="Set cookie" />
23+
</div>
24+
</form>
25+
{% endblock %}

0 commit comments

Comments
 (0)