Add simple view for setting testemailcc cookie when server is in test mode
- Legacy-Id: 3716
This commit is contained in:
parent
8153a1c130
commit
b114e5e6cf
|
@ -124,3 +124,6 @@ class PasswordForm(forms.Form):
|
|||
debug.show('stdout')
|
||||
debug.show('stderr')
|
||||
return p.returncode
|
||||
|
||||
class TestEmailForm(forms.Form):
|
||||
email = forms.EmailField(required=False)
|
||||
|
|
|
@ -9,6 +9,7 @@ urlpatterns = patterns('',
|
|||
(r'^loggedin/$', views.ietf_loggedin),
|
||||
(r'^profile/$', views.profile),
|
||||
# (r'^login/(?P<user>[a-z0-9.@]+)/(?P<passwd>.+)$', views.url_login),
|
||||
(r'^testemail/$', views.test_email),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('ietf.ietfauth.views',
|
||||
|
|
|
@ -48,7 +48,7 @@ from django.contrib.auth.models import User
|
|||
from django.utils import simplejson as json
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from forms import (RegistrationForm, PasswordForm, RecoverPasswordForm)
|
||||
from forms import *
|
||||
|
||||
|
||||
def index(request):
|
||||
|
@ -181,3 +181,43 @@ def ajax_check_username(request):
|
|||
error = _('This email is already in use')
|
||||
return HttpResponse(json.dumps({'error': error}), mimetype='text/plain')
|
||||
|
||||
def test_email(request):
|
||||
if settings.SERVER_MODE == "production":
|
||||
raise Http404()
|
||||
|
||||
# note that the cookie set here is only used when running in
|
||||
# "test" mode, normally you run the server in "development" mode,
|
||||
# in which case email is sent out as usual; for development, put
|
||||
# this
|
||||
#
|
||||
# EMAIL_HOST = 'localhost'
|
||||
# EMAIL_PORT = 1025
|
||||
# EMAIL_HOST_USER = None
|
||||
# EMAIL_HOST_PASSWORD = None
|
||||
# EMAIL_COPY_TO = ""
|
||||
#
|
||||
# in your settings.py and start a little debug email server in a
|
||||
# console with the following (it receives and prints messages)
|
||||
#
|
||||
# python -m smtpd -n -c DebuggingServer localhost:1025
|
||||
|
||||
cookie = None
|
||||
|
||||
if request.method == "POST":
|
||||
form = TestEmailForm(request.POST)
|
||||
if form.is_valid():
|
||||
cookie = form.cleaned_data['email']
|
||||
else:
|
||||
form = TestEmailForm(initial=dict(email=request.COOKIES.get('testemailcc')))
|
||||
|
||||
r = render_to_response('ietfauth/testemail.html',
|
||||
dict(form=form,
|
||||
cookie=cookie if cookie != None else request.COOKIES.get("testemailcc", "")
|
||||
),
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
if cookie != None:
|
||||
r.set_cookie("testemailcc", cookie)
|
||||
|
||||
return r
|
||||
|
||||
|
|
25
ietf/templates/ietfauth/testemail.html
Normal file
25
ietf/templates/ietfauth/testemail.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Set up test email address{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Set up test email address</h1>
|
||||
|
||||
<p>Since this server is running in test mode, all email to be sent out
|
||||
is intercepted and thrown away.</p>
|
||||
|
||||
<p>To receive a copy of each message before it's thrown away, you can
|
||||
set an email address below. The address is stored in the <code>testmailcc</code>
|
||||
cookie in your browser. So make sure cookies are enabled.</p>
|
||||
|
||||
<p>Value of <code>testmailcc</code>: {{ cookie }}</p>
|
||||
|
||||
<form action="" method="post">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<div>
|
||||
<input type="submit" value="Set cookie" />
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
Loading…
Reference in a new issue