summaryrefslogtreecommitdiffstats
path: root/virtualenv/pffedportal
diff options
context:
space:
mode:
authorThomas NOEL <tnoel@entrouvert.com>2012-06-29 13:32:04 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2012-06-29 13:32:04 (GMT)
commit4234547917d2e09f2b657cc2a9b951eeb71cf0c5 (patch)
tree745767868cec2106683c901d65acb2f2085b69db /virtualenv/pffedportal
parent72e32bdb2f7a1c87554d8c9f117ccdedbd8362ef (diff)
downloadunivnautes-old-4234547917d2e09f2b657cc2a9b951eeb71cf0c5.zip
univnautes-old-4234547917d2e09f2b657cc2a9b951eeb71cf0c5.tar.gz
univnautes-old-4234547917d2e09f2b657cc2a9b951eeb71cf0c5.tar.bz2
mail form: step 1 - python/django part
Diffstat (limited to 'virtualenv/pffedportal')
-rw-r--r--virtualenv/pffedportal/base/forms.py28
-rw-r--r--virtualenv/pffedportal/base/views.py47
-rw-r--r--virtualenv/pffedportal/media/bristol/style.css22
-rw-r--r--virtualenv/pffedportal/settings.py50
-rw-r--r--virtualenv/pffedportal/templates/mail.html36
-rw-r--r--virtualenv/pffedportal/urls.py3
6 files changed, 185 insertions, 1 deletions
diff --git a/virtualenv/pffedportal/base/forms.py b/virtualenv/pffedportal/base/forms.py
new file mode 100644
index 0000000..7b8ebf8
--- /dev/null
+++ b/virtualenv/pffedportal/base/forms.py
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+
+from django import forms
+from django.conf import settings
+from authentic2.saml.common import get_idp_list_sorted
+
+EMAIL_SUBJECTS_CHOICES = [ (u'%s' % i, settings.EMAIL_SUBJECTS[i]) for i in range(len(settings.EMAIL_SUBJECTS)) ]
+
+IDP_CHOICES = [ (idp['entity_id'], idp['name']) for idp in get_idp_list_sorted() ]
+IDP_CHOICES.insert(0, (None, "Sélectionner dans la liste"))
+
+class MailForm(forms.Form):
+ name = forms.CharField(label=u'Vos nom et prénom',
+ max_length=200, required=True)
+ from_email = forms.EmailField(label=u'Votre adresse électronique (mail)',
+ max_length=150, required=True)
+ idp = forms.ChoiceField(label=u"Votre établissement d'origine",
+ choices=IDP_CHOICES, required=True)
+ phone = forms.CharField(label=u'Un numéro de téléphone pour vous joindre (optionnel)',
+ max_length=30, required=False)
+ subject = forms.ChoiceField(label=u'Votre soucis',
+ choices=EMAIL_SUBJECTS_CHOICES, required=True)
+ body = forms.CharField(label=u'La description détaillée de votre soucis',
+ max_length=5000, widget=forms.Textarea, required=True,
+ help_text="""Précisez votre établissement d'origine, le type
+ d'appareil que vous utilisez pour vous connecter, votre logiciel de
+ navigation sur le web, etc.""")
+
diff --git a/virtualenv/pffedportal/base/views.py b/virtualenv/pffedportal/base/views.py
index 4815282..8ed742b 100644
--- a/virtualenv/pffedportal/base/views.py
+++ b/virtualenv/pffedportal/base/views.py
@@ -2,11 +2,12 @@ import subprocess
import urlparse
import syslog
-import settings
+from django.conf import settings
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import redirect
+from django.contrib import messages
import django.contrib.auth
from authentic2.saml.common import get_idp_list_sorted
@@ -16,6 +17,11 @@ import authentic2.saml.models as saml_models
import pfsense
+from forms import MailForm, EMAIL_SUBJECTS_CHOICES, IDP_CHOICES
+from django.core.mail import send_mail
+#from smtplib import SMTPException
+
+
def redirect302(request):
next_url = 'http://' + request.META['HTTP_HOST'] + request.META['REQUEST_URI']
return redirect('https://%s/login?next_url=%s' % (settings.HTTPS_HOSTNAME, next_url))
@@ -120,3 +126,42 @@ def logout(request):
stdout, stderr = p.communicate()
return redirect('/login')
+
+def mail(request):
+ # FIXME 3 access per hour (check cookie "lastmails")
+ if request.method == 'POST':
+ form = MailForm(request.POST)
+ if form.is_valid():
+ name = form.cleaned_data['name']
+ from_email = form.cleaned_data['from_email']
+ idp = form.cleaned_data['idp']
+ idp_name = dict(IDP_CHOICES).get(idp)
+ phone = form.cleaned_data.get('phone', '')
+ n_subject = form.cleaned_data['subject']
+ subject = dict(EMAIL_SUBJECTS_CHOICES).get(n_subject, 'unknown subject ?')
+ body = form.cleaned_data['body']
+ total_body = u'From: %(name)s <%(from_email)s>\nPhone: %(phone)s\n' \
+ 'IdP: %(idp_name)s <%(idp)s>\n\n' \
+ 'Message:\n%(body)s\n\n-- \nUnivNautes\n' % {
+ 'name': name, 'from_email': from_email,
+ 'idp': idp or None, 'idp_name': idp_name,
+ 'phone': phone,
+ 'body': body }
+ try:
+ send_mail(u'[Contact UnivNautes] %s' % subject,
+ total_body,
+ u'%s' % from_email,
+ [settings.EMAIL_RCPT],
+ fail_silently=False)
+ except Exception, e:
+ messages.add_message(request, messages.ERROR, 'send_mail error: %s' % e)
+ else:
+ # FIXME store cookie "lastmails"
+ response = redirect('.')
+ return response
+ else:
+ form = MailForm()
+ return render_to_response('mail.html',
+ { 'form': form, },
+ context_instance=RequestContext(request))
+
diff --git a/virtualenv/pffedportal/media/bristol/style.css b/virtualenv/pffedportal/media/bristol/style.css
index 5482000..8153347 100644
--- a/virtualenv/pffedportal/media/bristol/style.css
+++ b/virtualenv/pffedportal/media/bristol/style.css
@@ -255,4 +255,26 @@ div#popup a#close {
padding: 1ex;
}
+#mailform {
+ padding: 10px 100px 30px 100px;
+ font-size: 14px;
+ color: black;
+}
+
+#mailform .error {
+ color: red;
+}
+
+#mailform .help {
+ font-style: italic;
+}
+
+#mailform input, select, textarea {
+ width: 100%;
+}
+
+#mailform input#submit {
+ padding: 10px;
+}
+
diff --git a/virtualenv/pffedportal/settings.py b/virtualenv/pffedportal/settings.py
index cda9186..586a714 100644
--- a/virtualenv/pffedportal/settings.py
+++ b/virtualenv/pffedportal/settings.py
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
# Django settings for pffedportal project.
# if you wanna override them, use ./local_settings.py
@@ -84,6 +86,8 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
)
+MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
+
ROOT_URLCONF = 'pffedportal.urls'
# template from univnautes
@@ -252,6 +256,52 @@ except:
MOBILE_FORCE = False
+# /mail form
+
+try:
+ EMAIL_RCPT = root.find('installedpackages/univnautestexts/config/email_rcpt').text
+except:
+ EMAIL_RCPT = None
+
+try:
+ EMAIL_SUBJECTS = [ l for l in root.find('installedpackages/univnautestexts/config/email_subjects').text.splitlines() if not re.match('^\s*$', l) ]
+except:
+ EMAIL_SUBJECTS = (
+ u"Je ne trouve pas mon établissement dans la liste",
+ u"Quand je clique sur mon établissement, il ne se passe rien",
+ u"L'interface est peu lisible",
+ u"Autre (précisez dans la description)",
+ )
+
+try:
+ EMAIL_HOST = root.find('installedpackages/univnautestexts/config/email_host').text
+except:
+ EMAIL_HOST = None
+
+try:
+ EMAIL_PORT = int(root.find('installedpackages/univnautestexts/config/email_port').text)
+except:
+ EMAIL_PORT = 587
+
+try:
+ EMAIL_HOST_USER = root.find('installedpackages/univnautestexts/config/email_host_user').text
+except:
+ EMAIL_HOST_USER = None
+
+try:
+ EMAIL_HOST_PASSWORD = root.find('installedpackages/univnautestexts/config/email_host_password').text
+except:
+ EMAIL_HOST_PASSWORD = None
+
+try:
+ if root.find('installedpackages/univnautestexts/config/email_use_tls').text == None:
+ EMAIL_USE_TLS = False
+ else:
+ EMAIL_USE_TLS = True
+except:
+ EMAIL_USE_TLS = True
+
+
# local_settings.py can be used to override environment-specific settings
# like database and email that differ between development and production.
try:
diff --git a/virtualenv/pffedportal/templates/mail.html b/virtualenv/pffedportal/templates/mail.html
new file mode 100644
index 0000000..79f8592
--- /dev/null
+++ b/virtualenv/pffedportal/templates/mail.html
@@ -0,0 +1,36 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}Accès Internet :: Formulaire de contact{% endblock %}
+
+{% block content %}
+<div id="mailform">
+ <h2>Formulaire de contact</h2>
+ <p>Utilisez ce formulaire pour signaler les soucis que vous avez
+ rencontrés en utilisant ce système.</p>
+
+ {% if messages %}
+ <p class="messages"><strong>
+ {% for message in messages %}
+ <span{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</span><br />
+ {% endfor %}
+ </strong></p>
+ {% endif %}
+
+ <form action="/mail" method="POST">
+ {% csrf_token %}
+ {% for field in form %}
+ <p>
+ {{ field.label_tag }}<br />
+ {% for error in field.errors %}<span class="error">{{error}}</span><br />{% endfor %}
+ {{ field }}
+ <br/>
+ <span class="help">{{ field.help_text }}</span>
+ </p>
+ {% endfor %}
+ <br />
+ <input id="submit" type="submit" value="Envoyer le message" />
+ </form>
+</div>
+{% endblock %}
+
diff --git a/virtualenv/pffedportal/urls.py b/virtualenv/pffedportal/urls.py
index f630a87..7ffb26c 100644
--- a/virtualenv/pffedportal/urls.py
+++ b/virtualenv/pffedportal/urls.py
@@ -10,6 +10,9 @@ urlpatterns = patterns('',
(r'^authsaml2/', include('authentic2.authsaml2.urls')),
)
+if settings.EMAIL_RCPT and settings.EMAIL_HOST:
+ urlpatterns += patterns('', url(r'^mail$', 'base.views.mail'))
+
if settings.STATIC_SERVE:
urlpatterns += patterns('',
url(