diff --git a/ietf/ietfauth/forms.py b/ietf/ietfauth/forms.py index feb618609..ae2cb3b63 100644 --- a/ietf/ietfauth/forms.py +++ b/ietf/ietfauth/forms.py @@ -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) diff --git a/ietf/ietfauth/urls.py b/ietf/ietfauth/urls.py index 74d4df244..3c5986d5b 100644 --- a/ietf/ietfauth/urls.py +++ b/ietf/ietfauth/urls.py @@ -9,6 +9,7 @@ urlpatterns = patterns('', (r'^loggedin/$', views.ietf_loggedin), (r'^profile/$', views.profile), # (r'^login/(?P[a-z0-9.@]+)/(?P.+)$', views.url_login), + (r'^testemail/$', views.test_email), ) urlpatterns += patterns('ietf.ietfauth.views', diff --git a/ietf/ietfauth/views.py b/ietf/ietfauth/views.py index ab7f9127f..808cd5e69 100644 --- a/ietf/ietfauth/views.py +++ b/ietf/ietfauth/views.py @@ -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 + diff --git a/ietf/templates/ietfauth/testemail.html b/ietf/templates/ietfauth/testemail.html new file mode 100644 index 000000000..4c9ba4dd8 --- /dev/null +++ b/ietf/templates/ietfauth/testemail.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block title %}Set up test email address{% endblock %} + +{% block content %} +

Set up test email address

+ +

Since this server is running in test mode, all email to be sent out +is intercepted and thrown away.

+ +

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 testmailcc +cookie in your browser. So make sure cookies are enabled.

+ +

Value of testmailcc: {{ cookie }}

+ +
+ + {{ form.as_table }} +
+
+ +
+
+{% endblock %}