Commit 50970738 authored by Gabriel Detraz's avatar Gabriel Detraz

Création d'une vue pour l'ajout d'alias

parent db0b48f3
......@@ -14,10 +14,9 @@ class CompteForm(forms.Form):
etabetudes = forms.CharField(label=u'Etablissement', max_length=100, required=False)
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)
contourneGreylist = forms.CharField(label=u'Contournement du greylisting', max_length=10, widget= widgets.CheckboxInput, required=False)
class RedirectionForm(forms.Form):
class MailForm(forms.Form):
mailredirect = forms.CharField(label=u'Redirection des mails', max_length=40, required=False)
def clean_mailredirect(self):
mailredirect = self.cleaned_data['mailredirect']
......@@ -30,6 +29,9 @@ class RedirectionForm(forms.Form):
raise forms.ValidationError("Ce champ doit être une adresse mail ou l'execution d'un programme type procmail")
return mailredirect
class AliasForm(forms.Form):
mailAlias = forms.EmailField(label=u'Nouvel alias Mail', max_length=40, 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)
......
......@@ -6,5 +6,6 @@ import views
urlpatterns = patterns('',
url('^$', views.afficher, name='afficher'),
url('chgpass', views.chgpass, name='chgpass'),
url('redirection', views.redirection, name='redirection')
url('redirection', views.redirection, name='redirection'),
url('newalias', views.newalias, name='newalias')
)
......@@ -24,7 +24,8 @@ from gestion import config
from forms import CompteForm
from forms import PassForm
from forms import RedirectionForm
from forms import MailForm
from forms import AliasForm
from django.forms.util import ErrorList
# Vue d'affichage seulement des infos pour l'adh
......@@ -98,16 +99,6 @@ def afficher(request):
luser['etudes'][2] = unicode(form.cleaned_data['dometudes']) or config.etudes_defaults[2]
_ = form.changed_data.remove('dometudes')
# Pour les Alias mail, on ne permet que l'ajout, pas la suppression
if 'mailAlias' in form.changed_data:
try:
luser['mailAlias'].append(form.cleaned_data['mailAlias'])
except ValueError as e:
# Le message d'une ValueError est directement dans e
elist = form._errors.setdefault('mailAlias', ErrorList())
elist.append(e)
_ = form.changed_data.remove('mailAlias')
# Le greylisting est un peu particulier.
if 'contourneGreylist' in form.changed_data:
if form.cleaned_data['contourneGreylist']=="True":
......@@ -185,7 +176,7 @@ def redirection(request):
'mailredirect': mailredirect,
}
if request.method == "POST":
form = RedirectionForm(request.POST, initial=initial_data)
form = MailForm(request.POST, initial=initial_data)
if form.is_valid():
# La redirection n'est pas un champ ldap
if 'mailredirect' in form.changed_data:
......@@ -194,6 +185,27 @@ def redirection(request):
messages.success(request, u"""Votre redirection a bien été changée""")
return redirect("/compte/")
else:
form = RedirectionForm(initial=initial_data)
form = MailForm(initial=initial_data)
return render(request, "compte/redirection.html", {'form': form})
@login_required
def newalias(request):
luser = conn_pool.get_user(request.user, mode='w')
if request.method == "POST":
form = AliasForm(request.POST)
if form.is_valid():
# Pour les Alias mail, on ne permet que l'ajout, pas la suppression
if 'mailAlias' in form.changed_data:
try:
luser['mailAlias'].append(form.cleaned_data['mailAlias'])
luser.history_gen()
luser.save()
messages.success(request, u"""L'alias a été ajouté avec succès""")
return redirect("/compte/")
except ValueError as e:
# Le message d'une ValueError est directement dans e
elist = form._errors.setdefault('mailAlias', ErrorList())
elist.append(e)
else:
form = AliasForm()
return render(request, "compte/alias.html", {'form': form})
......@@ -112,12 +112,6 @@
</div>
<div class="row">
<div class="six columns">
{{ form.mailAlias.label_tag}}
{{ form.mailAlias }}
{{ form.mailAlias.errors }}
Afin d'éviter les abus, la destruction d'un alias nécessite une demande via la mailing-list respbats@crans.org
</div>
<div class="six columns">
{{ form.contourneGreylist.label_tag}}
{{ form.contourneGreylist }}
......@@ -129,6 +123,10 @@
<a class="button" href="{% url 'compte:redirection' %}">Changer la redirection mail</a>
</div>
<div class="row">
<a class="button" href="{% url 'compte:newalias' %}">Ajouter un alias mail</a>
</div>
<footer>
<div class="row">
......
{% extends "template.html" %}
{% block title %} Alias Mail {% endblock %}
{% block h1 %} Ajouter un Alias Mail {% 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.mailAlias.errors %} error{% endif %}">
{{ form.mailAlias.label_tag}}
{{ form.mailAlias }}
{{ form.mailAlias.errors }}
Afin d'éviter les abus, la destruction d'un alias nécessite une demande via la mailing-list respbats@crans.org
</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