Commit 25b723e9 authored by Chris Reffett's avatar Chris Reffett
Browse files

Send emails to notify about registration requests instead of writing to a file

parent b89ba15b
{% extends 'base.html' %}
{% block title %}
Go - Registration Email Sent
{% endblock %}
{% block content %}
<p>
Your registration request has been sent! Please be patient, our
administrators will handle it as soon as they can.
</p>
{% endblock %}
...@@ -6,6 +6,7 @@ from django.http import Http404, HttpResponseServerError ...@@ -6,6 +6,7 @@ from django.http import Http404, HttpResponseServerError
from django.utils import timezone from django.utils import timezone
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.core.mail import send_mail
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
import os import os
...@@ -183,8 +184,6 @@ def signup(request): ...@@ -183,8 +184,6 @@ def signup(request):
This view presents the user with a registration form. You can register This view presents the user with a registration form. You can register
yourself, or another person. yourself, or another person.
TODO: Add email notification to sysadmin that a new registration has
occurred.
""" """
form = SignupForm() form = SignupForm()
...@@ -197,23 +196,13 @@ def signup(request): ...@@ -197,23 +196,13 @@ def signup(request):
description = form.cleaned_data.get('description') description = form.cleaned_data.get('description')
""" send_mail('Signup from %s' % (username), '%s signed up at %s\n'
This code simply writes out to a file the registration. 'Username: %s\nMessage: %s\nPlease attend to this request at '
Ideally, we will be sending an administrator an email instead. 'your earliest convenience.' % (str(full_name),
But we need an email account to do that. str(timezone.now()).strip(), str(username), str(description)),
""" settings.EMAIL_FROM, [settings.EMAIL_TO])
f = open(os.path.join(settings.MEDIA_ROOT, 'registrations.txt'), 'a')
f.write( str(timezone.now()) ) return redirect('registered')
f.write( str('\n') )
f.write( str(username) )
f.write( str('\n') )
f.write( str(full_name) )
f.write( str('\n') )
f.write( str(description) )
f.write( str('\n\n\n') )
f.close()
return redirect('index')
return render(request, 'signup.html', { return render(request, 'signup.html', {
'form': form, 'form': form,
...@@ -255,3 +244,7 @@ def about(request): ...@@ -255,3 +244,7 @@ def about(request):
}, },
) )
def registered(request):
return render(request, 'registered.html', {
},
)
...@@ -7,3 +7,11 @@ DB_HOST = "" ...@@ -7,3 +7,11 @@ DB_HOST = ""
PIWIK_SITE_ID = "" PIWIK_SITE_ID = ""
PIWIK_URL = "" PIWIK_URL = ""
# Do not include a final slash!
SERVERURL = ""
EMAIL_HOST = ""
EMAIL_PORT = ""
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
...@@ -147,3 +147,14 @@ AUTH_LDAP_ALWAYS_UPDATE_USER = True ...@@ -147,3 +147,14 @@ AUTH_LDAP_ALWAYS_UPDATE_USER = True
PIWIK_SITE_ID = secret.PIWIK_SITE_ID PIWIK_SITE_ID = secret.PIWIK_SITE_ID
PIWIK_URL = secret.PIWIK_URL PIWIK_URL = secret.PIWIK_URL
SERVERURL = secret.SERVERURL
# Mail settings
EMAIL_HOST = secret.EMAIL_HOST
EMAIL_PORT = secret.EMAIL_PORT
EMAIL_HOST_USER = secret.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = secret.EMAIL_HOST_PASSWORD
EMAIL_FROM = "example@example.com"
EMAIL_TO = "to@example.com"
...@@ -26,6 +26,9 @@ urlpatterns = patterns('go.views', ...@@ -26,6 +26,9 @@ urlpatterns = patterns('go.views',
# /delete/<short> - Delete a link, no content display. # /delete/<short> - Delete a link, no content display.
url(r'^delete/(?P<short>\w+)$', 'delete', name = 'delete'), url(r'^delete/(?P<short>\w+)$', 'delete', name = 'delete'),
# /registered - registration complete page
url(r'^registered/?$', 'registered', name = 'registered'),
# /admin - Administrator interface. # /admin - Administrator interface.
url(r'^admin/?', include(admin.site.urls)), url(r'^admin/?', include(admin.site.urls)),
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment