Commit e5ba7081 authored by Gabriel Detraz's avatar Gabriel Detraz

Vue séparée pour la redirection mail

parent 05f1b1d0
......@@ -15,6 +15,8 @@ class CompteForm(forms.Form):
annetudes = forms.CharField(label=u"Année d'étude", max_length=100, required=False)
dometudes = forms.CharField(label=u'Domaine', max_length=100, required=False)
mailAlias = forms.EmailField(label=u'Nouvel alias Mail', max_length=40, required=False)
class RedirectionForm(forms.Form):
mailredirect = forms.CharField(label=u'Redirection des mails', max_length=40, required=False)
def clean_mailredirect(self):
......@@ -24,7 +26,7 @@ class CompteForm(forms.Form):
try:
validate_email(mailredirect)
except forms.ValidationError:
if not mailredirect.strip('"').strip()[0]=='|':
if not mailredirect.strip('"').strip().startswith('|'):
raise forms.ValidationError("Ce champ doit être une adresse mail ou l'execution d'un programme type procmail")
return mailredirect
......
......@@ -5,5 +5,6 @@ import views
urlpatterns = patterns('',
url('^$', views.afficher, name='afficher'),
url('chgpass', views.chgpass, name='chgpass')
url('chgpass', views.chgpass, name='chgpass'),
url('redirection', views.redirection, name='redirection')
)
......@@ -24,6 +24,7 @@ from gestion import config
from forms import CompteForm
from forms import PassForm
from forms import RedirectionForm
from django.forms.util import ErrorList
# Vue d'affichage seulement des infos pour l'adh
......@@ -54,8 +55,8 @@ def afficher(request):
dometudes = _etudes[2]
# On récupère la redirection
redirect = subprocess.Popen(["sudo", "/usr/scripts/utils/forward.py", "--read", "--name=%s" % luser['uid'][0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mailredirect = redirect.stdout.readlines()[0]
redirection_mail = subprocess.Popen(["sudo", "/usr/scripts/utils/forward.py", "--read", "--name=%s" % luser['uid'][0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mailredirect = redirection_mail.stdout.readlines()[0]
initial_data = {
'nom': luser['nom'][0],
......@@ -65,7 +66,6 @@ def afficher(request):
'annetudes': annetudes,
'etabetudes': etabetudes,
'dometudes': dometudes,
'mailredirect': mailredirect,
}
else:
......@@ -77,12 +77,6 @@ def afficher(request):
if request.method == "POST":
form = CompteForm(request.POST, initial=initial_data)
if form.is_valid():
# La redirection n'est pas un champ ldap
if 'mailredirect' in form.changed_data:
mailredirect = unicode(form.cleaned_data['mailredirect'])
redirect = subprocess.Popen(["sudo", "/usr/scripts/utils/forward.py", "--write", "--mail=%s" % mailredirect, "--name=%s" % luser['uid'][0]])
_ = form.changed_data.remove('mailredirect')
# On ouvre une connexion
luserconn = conn_pool.get_user(request.user, mode='w')
with luserconn as luser:
......@@ -145,6 +139,7 @@ def afficher(request):
'now': datetime.datetime.now(),
'adher': adher,
'luser': luser,
'mailredirect': mailredirect,
}
return render(request, "compte/affichage.html", context)
......@@ -185,3 +180,25 @@ def chgpass(request):
else:
form = PassForm()
return render(request, "compte/chgpass.html", {'form': form})
@login_required
def redirection(request):
luser = conn_pool.get_user(request.user)
redirection_mail = subprocess.Popen(["sudo", "/usr/scripts/utils/forward.py", "--read", "--name=%s" % luser['uid'][0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mailredirect = redirection_mail.stdout.readlines()[0]
initial_data = {
'mailredirect': mailredirect,
}
if request.method == "POST":
form = RedirectionForm(request.POST, initial=initial_data)
if form.is_valid():
# La redirection n'est pas un champ ldap
if 'mailredirect' in form.changed_data:
mailredirect = unicode(form.cleaned_data['mailredirect'])
redirection_mail = subprocess.Popen(["sudo", "/usr/scripts/utils/forward.py", "--write", "--mail=%s" % mailredirect, "--name=%s" % luser['uid'][0]])
messages.success(request, u"""Votre redirection a bien été changée""")
return redirect("/compte/")
else:
form = RedirectionForm(initial=initial_data)
return render(request, "compte/redirection.html", {'form': form})
......@@ -95,20 +95,17 @@
</div>
<h2>Mail</h2>
<div class="row">
<div class="four columns{% if form.mailredirect.errors %} error{% endif %}">
{{ form.mailredirect.label_tag}}
{{ form.mailredirect }}
{{ form.mailredirect.errors }}
</div>
</div>
<div class="row">
<div class="six columns">
<div class="four columns">
<label>Mail de contact :</label>
{{ luser.mail.0 }}
</div>
<div class="six columns">
<div class="four columns">
<label>Redirection des emails vers:</label>
{{ mailredirect }}
</div>
<div class="four columns">
<label>Aliases mail :</label>
<ul>
<li>{{ luser.canonicalAlias.0 }}</li>
......@@ -133,6 +130,10 @@
</div>
</div>
<div class="row">
<a class="button" href="{% url 'compte:redirection' %}">Changer la redirection mail</a>
</div>
<footer>
<div class="row">
<div class="six columns">
......
{% extends "template.html" %}
{% block title %} Redirection {% endblock %}
{% block h1 %} Changement de la redirection de mes emails Cr@ns {% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<div class="row">
<div class="six columns{% if form.mailredirect.errors %} error{% endif %}">
{{ form.mailredirect.label_tag}}
{{ form.mailredirect }}
{{ form.mailredirect.errors }}
</div>
</div>
<footer>
<a href="{% url 'compte:afficher' %}" class="button-cancel">Retour à mon compte</a>
<input type="submit" value="Enregistrer">
</footer>
</form>
{% endblock %}
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