Commit db0b48f3 authored by Gabriel Detraz's avatar Gabriel Detraz

Création d'une vue à part pour la redirection

parent 1949f042
......@@ -15,8 +15,10 @@ 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)
mailredirect = forms.CharField(label=u'Redirection des mails', max_length=40, required=False)
contourneGreylist = forms.CharField(label=u'Contournement du greylisting', max_length=10, widget= widgets.CheckboxInput, required=False)
class RedirectionForm(forms.Form):
mailredirect = forms.CharField(label=u'Redirection des mails', max_length=40, required=False)
def clean_mailredirect(self):
mailredirect = self.cleaned_data['mailredirect']
if "@crans.org" in mailredirect:
......@@ -28,9 +30,6 @@ class CompteForm(forms.Form):
raise forms.ValidationError("Ce champ doit être une adresse mail ou l'execution d'un programme type procmail")
return mailredirect
contourneGreylist = forms.CharField(label=u'Contournement du greylisting', max_length=10, widget= widgets.CheckboxInput, required=False)
class PassForm(forms.Form):
passwdexists = forms.CharField(label=u'Ancien mot de passe', max_length=255, widget= widgets.PasswordInput, required=False)
newpasswd1 = forms.CharField(label=u'Nouveau mot de passe', max_length=255, widget= widgets.PasswordInput, required=False)
......
......@@ -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
......@@ -53,10 +54,6 @@ def afficher(request):
annetudes = _etudes[1]
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]
initial_data = {
'nom': luser['nom'][0],
'prenom': luser['prenom'][0],
......@@ -65,7 +62,6 @@ def afficher(request):
'annetudes': annetudes,
'etabetudes': etabetudes,
'dometudes': dometudes,
'mailredirect': mailredirect,
}
else:
......@@ -77,12 +73,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:
......@@ -185,3 +175,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,14 +95,6 @@
</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">
<label>Mail de contact :</label>
......@@ -133,6 +125,11 @@
</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