diff --git a/admin/views.py b/admin/views.py index 7787ecb7d..146a3e0f7 100644 --- a/admin/views.py +++ b/admin/views.py @@ -13,13 +13,7 @@ from mailng import admin from mailng.admin.models import Domain, Mailbox, Alias from forms import MailboxForm, DomainForm, AliasForm, PermissionForm from mailng.lib.authbackends import crypt_password -from mailng.lib import _render - -def _ctx_ok(url): - return {"status" : "ok", "url" : url} - -def _ctx_ko(tpl, ctx): - return {"status" : "ko", "content" : render_to_string(tpl, ctx)} +from mailng.lib import _render, _ctx_ok, _ctx_ko def is_superuser(user): if not user.is_superuser: diff --git a/lib/__init__.py b/lib/__init__.py index 7a0ea9e3a..d760e6b9e 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -5,6 +5,7 @@ import time from django.conf import settings from django.template import RequestContext from django.shortcuts import render_to_response +from django.template.loader import render_to_string def exec_pipe(cmd): """Exécute une commande et récupère la sortie générée @@ -55,3 +56,9 @@ def exec_as_vuser(cmd): os.system("echo '%s' >> /tmp/vmail.log" % output) return False return True + +def _ctx_ok(url): + return {"status" : "ok", "url" : url} + +def _ctx_ko(tpl, ctx): + return {"status" : "ko", "content" : render_to_string(tpl, ctx)} diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index eca425104..fcce0bcba 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-04-08 17:57+0200\n" +"POT-Creation-Date: 2009-06-17 10:13+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Antoine Nguyen \n" "Language-Team: LANGUAGE \n" @@ -16,81 +16,81 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: admin/forms.py:11 templates/admin/domains.html:20 -#: templates/admin/mailboxes.html:27 +#: admin/forms.py:16 templates/admin/domains.html:20 +#: templates/admin/mailboxes.html:28 msgid "Quota" msgstr "" -#: admin/forms.py:12 +#: admin/forms.py:17 msgid "Password" msgstr "Mot de passe" -#: admin/forms.py:13 +#: admin/forms.py:18 msgid "Confirmation" msgstr "" -#: admin/forms.py:22 +#: admin/forms.py:32 msgid "Passwords mismatch" msgstr "Les mots de passe diffèrent" -#: admin/forms.py:40 templates/admin/domain_header.html:8 +#: admin/forms.py:51 templates/admin/domain_header.html:8 #: templates/admin/editdomain.html:7 templates/admin/permissions.html:39 msgid "Domain" msgstr "Domaine" -#: admin/forms.py:42 +#: admin/forms.py:53 msgid "User" msgstr "Utilisateur" -#: admin/forms.py:43 +#: admin/forms.py:54 msgid "Role" msgstr "Rôle" -#: admin/forms.py:44 +#: admin/forms.py:55 msgid "Super administrator" msgstr "Super administrateur" -#: admin/forms.py:45 +#: admin/forms.py:56 msgid "Domain administrator" msgstr "Admin. de domaine" -#: admin/models.py:9 admin/models.py:52 +#: admin/models.py:9 admin/models.py:48 msgid "name" msgstr "Nom" -#: admin/models.py:11 admin/models.py:105 +#: admin/models.py:11 admin/models.py:112 main/models.py:9 msgid "enabled" msgstr "Activé" -#: admin/models.py:53 admin/models.py:102 +#: admin/models.py:49 admin/models.py:109 msgid "address" msgstr "Adresse" -#: admin/models.py:55 +#: admin/models.py:51 msgid "password" msgstr "Mot de passe" -#: admin/models.py:104 +#: admin/models.py:111 msgid "mailbox" msgstr "Boite aux lettres" -#: admin/views.py:29 +#: admin/views.py:26 msgid "Permission denied." msgstr "Permission refusée." -#: admin/views.py:57 admin/views.py:88 +#: admin/views.py:54 admin/views.py:85 msgid "Domain with this name already defined" msgstr "Un domaine avec ce nom existe déjà" -#: admin/views.py:65 +#: admin/views.py:62 msgid "Failed to initialise domain, check permissions" msgstr "Impossible d'initialiser le domaine, vérifier les permissions" -#: admin/views.py:91 +#: admin/views.py:88 msgid "Failed to rename domain, check permissions" msgstr "Impossible de renommer le domaine, vérifier les permissions" -#: admin/views.py:143 admin/views.py:191 +#: admin/views.py:138 admin/views.py:191 msgid "Mailbox with this address already exists" msgstr "Une boite aux lettres pour cette adresse existe déjà" @@ -115,6 +115,42 @@ msgstr "Activé" msgid "enabled_f" msgstr "Activée" +#: main/models.py:7 +msgid "subject" +msgstr "sujet" + +#: main/models.py:8 +msgid "content" +msgstr "contenu" + +#: main/views.py:34 +msgid "Auto reply message updated successfully." +msgstr "Message de réponse auto. mis à jour." + +#: templates/layout.html:40 +msgid "Admin" +msgstr "" + +#: templates/layout.html:47 +msgid "Preferences" +msgstr "Préférences" + +#: templates/layout.html:53 +msgid "Logout" +msgstr "Déconnexion" + +#: templates/layout.html:66 templates/admin/newdomain.html:7 +msgid "New domain" +msgstr "Nouveau domaine" + +#: templates/layout.html:73 +msgid "Domains" +msgstr "Domaines" + +#: templates/layout.html:80 templates/admin/settings_header.html:8 +msgid "Settings" +msgstr "Paramètres" + #: templates/admin/addpermission.html:24 templates/admin/settings_menu.html:15 msgid "Add permission" msgstr "Ajouter une permission" @@ -129,12 +165,12 @@ msgid "No alias defined." msgstr "Aucun alias défini." #: templates/admin/aliases.html:14 templates/admin/domains.html:17 -#: templates/admin/mailboxes.html:24 templates/admin/permissions.html:14 +#: templates/admin/mailboxes.html:25 templates/admin/permissions.html:14 #: templates/admin/permissions.html:38 msgid "Actions" msgstr "" -#: templates/admin/aliases.html:15 templates/admin/mailboxes.html:26 +#: templates/admin/aliases.html:15 templates/admin/mailboxes.html:27 msgid "Address" msgstr "Adresse" @@ -179,7 +215,7 @@ msgstr "Domaines disponibles" msgid "No domain defined." msgstr "Aucun domaine défini." -#: templates/admin/domains.html:18 templates/admin/mailboxes.html:25 +#: templates/admin/domains.html:18 templates/admin/mailboxes.html:26 #: templates/admin/permissions.html:40 msgid "Name" msgstr "Nom" @@ -192,52 +228,36 @@ msgstr "Editer le domaine" msgid "Delete domain" msgstr "Supprimer le domaine" -#: templates/admin/domains.html:39 templates/admin/mailboxes.html:55 +#: templates/admin/domains.html:39 templates/admin/mailboxes.html:56 msgid "MB" msgstr "Mo" -#: templates/admin/domains.html:40 templates/admin/mailboxes.html:56 +#: templates/admin/domains.html:40 templates/admin/mailboxes.html:57 msgid "yes,no" msgstr "oui,non" #: templates/admin/editalias.html:14 templates/admin/editdomain.html:15 -#: templates/admin/editmailbox.html:16 +#: templates/admin/editmailbox.html:16 templates/main/autoreply.html:16 msgid "Update" msgstr "Mettre à jour" -#: templates/admin/layout.html:16 -msgid "Logout" -msgstr "Déconnexion" - -#: templates/admin/layout.html:29 templates/admin/newdomain.html:7 -msgid "New domain" -msgstr "Nouveau domaine" - -#: templates/admin/layout.html:36 -msgid "Domains" -msgstr "Domaines" - -#: templates/admin/layout.html:43 templates/admin/settings_header.html:8 -msgid "Settings" -msgstr "Paramètres" - -#: templates/admin/mailboxes.html:20 +#: templates/admin/mailboxes.html:21 msgid "No mailbox defined." msgstr "Aucune boite aux lettres définie." -#: templates/admin/mailboxes.html:36 +#: templates/admin/mailboxes.html:37 msgid "Edit mailbox" msgstr "Editer la boite aux lettres" -#: templates/admin/mailboxes.html:41 +#: templates/admin/mailboxes.html:42 msgid "Delete mailbox" msgstr "Supprimer la boite aux lettres" -#: templates/admin/mailboxes.html:46 +#: templates/admin/mailboxes.html:47 msgid "Add new alias" msgstr "Ajouter un alias" -#: templates/admin/mailboxes.html:50 +#: templates/admin/mailboxes.html:51 msgid "Mailbox aliases" msgstr "Alias de cette boite aux lettres" @@ -261,7 +281,7 @@ msgstr "Nom complet" msgid "User name" msgstr "Nom d'utilisateur" -#: templates/admin/permissions.html:22 templates/admin/permissions.html:46 +#: templates/admin/permissions.html:22 templates/admin/permissions.html:49 msgid "Remove permission" msgstr "Supprimer la permission" @@ -277,6 +297,18 @@ msgstr "Aucun admin de domaine défini." msgid "Permissions" msgstr "" +#: templates/main/header.html:5 +msgid "General" +msgstr "Général" + +#: templates/main/menu.html:5 +msgid "Change password" +msgstr "Changer de mot de passe" + +#: templates/main/menu.html:10 +msgid "Auto-reply message" +msgstr "Message de réponse automatique" + #: templates/registration/login.html:8 msgid "Welcome" msgstr "Bienvenue" diff --git a/main/forms.py b/main/forms.py index d3614f582..f267eb72e 100644 --- a/main/forms.py +++ b/main/forms.py @@ -1,5 +1,6 @@ from django import forms from mailng.main.models import ARmessage +from mailng.lib.authbackends import check_password from django.utils.translation import ugettext as _ class ARmessageForm(forms.ModelForm): @@ -11,3 +12,26 @@ class ARmessageForm(forms.ModelForm): super(ARmessageForm, self).__init__(*args, **kwargs) self.fields['subject'].widget.attrs['size'] = 40 self.fields['content'].widget.attrs['cols'] = 50 + +class ChangePasswordForm(forms.Form): + oldpassword = forms.CharField(label=_("Old password"), + widget=forms.PasswordInput) + newpassword = forms.CharField(label=_("New password"), + widget=forms.PasswordInput) + confirmation = forms.CharField(label=_("Confirmation"), + widget=forms.PasswordInput) + + def __init__(self, mb, *args, **kwargs): + super(ChangePasswordForm, self).__init__(*args, **kwargs) + self.mbox = mb + + def clean_oldpassword(self): + if not check_password(self.cleaned_data["oldpassword"], + self.mbox.password): + raise forms.ValidationError(_("Old password mismatchs")) + return self.cleaned_data["oldpassword"] + + def clean_confirmation(self): + if self.cleaned_data["newpassword"] != self.cleaned_data["confirmation"]: + raise forms.ValidationError(_("Passwords mismatch")) + return self.cleaned_data["confirmation"] diff --git a/main/models.py b/main/models.py index 054c814e4..4f4348057 100644 --- a/main/models.py +++ b/main/models.py @@ -1,11 +1,12 @@ from django.db import models +from django.utils.translation import ugettext_lazy as _ from mailng.admin.models import Mailbox class ARmessage(models.Model): mbox = models.ForeignKey(Mailbox) - subject = models.CharField(max_length=255) - content = models.TextField() - enabled = models.BooleanField() + subject = models.CharField(_('subject'), max_length=255) + content = models.TextField(_('content')) + enabled = models.BooleanField(_('enabled')) class ARhistoric(models.Model): armessage = models.ForeignKey(ARmessage) diff --git a/main/urls.py b/main/urls.py index df66bc332..dc68c16c5 100644 --- a/main/urls.py +++ b/main/urls.py @@ -2,5 +2,6 @@ from django.conf.urls.defaults import * urlpatterns = patterns('mailng.main.views', url(r'^$', 'index'), - url(r'^autoreply/$', 'autoreply') + url(r'^autoreply/$', 'autoreply'), + (r'^changepassword/$', 'changepassword'), ) diff --git a/main/views.py b/main/views.py index 73219ac82..617294aa7 100644 --- a/main/views.py +++ b/main/views.py @@ -1,10 +1,17 @@ from django.shortcuts import get_object_or_404, render_to_response from django.template.loader import render_to_string from django.template import RequestContext +from django.core.urlresolvers import reverse +from django.http import HttpResponse, HttpResponseRedirect +from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.decorators \ import login_required -from mailng.lib import _render -from forms import ARmessageForm +from django.utils import simplejson +from django.utils.translation import ugettext as _ +from mailng import main +from mailng.lib import _render, _ctx_ok, _ctx_ko +from mailng.lib.authbackends import crypt_password +from forms import ARmessageForm, ChangePasswordForm from models import ARmessage from admin.models import Mailbox @@ -30,7 +37,7 @@ def autoreply(request): arm.mbox = mb arm.save() request.user.message_set.create( - message="Auto reply message updated successfully." + message=_("Auto reply message updated successfully.") ) form = ARmessageForm(instance=arm) @@ -38,3 +45,25 @@ def autoreply(request): "form" : form }) +@login_required +def changepassword(request): + mb = Mailbox.objects.get(user=request.user.id) + error = None + if request.method == "POST": + form = ChangePasswordForm(mb, request.POST) + if form.is_valid(): + mb.password = crypt_password(request.POST["confirmation"]) + mb.save() + ctx = _ctx_ok("") + return HttpResponse(simplejson.dumps(ctx), + mimetype="application/json") + ctx = _ctx_ko("main/chpassword.html", { + "form" : form, "error" : error + }) + return HttpResponse(simplejson.dumps(ctx), mimetype="application/json") + + form = ChangePasswordForm(mb) + return render_to_response('main/chpassword.html', { + "form" : form + }) + diff --git a/static/js/form.js b/static/js/form.js index 891e581a2..d04c7dbd0 100644 --- a/static/js/form.js +++ b/static/js/form.js @@ -8,7 +8,8 @@ window.addEvent("domready", function() { $(id).addEvent("submit", callback); } else { parent.SqueezeBox.close(); - parent.location.href = response.url; + if (response.url != "") + parent.location.href = response.url; } } }); @@ -31,6 +32,9 @@ window.addEvent("domready", function() { permission_submit = function(event) { generic_submit(this, event, "permform", permission_submit); } + chpassword_submit = function(event) { + generic_submit(this, event, "chpwdform", chpassword_submit); + } if ($("domform")) $("domform").addEvent("submit", domain_submit); @@ -44,4 +48,6 @@ window.addEvent("domready", function() { if ($("permform")) $("permform").addEvent("submit", permission_submit); + if ($("chpwdform")) + $("chpwdform").addEvent("submit", chpassword_submit); }); diff --git a/templates/admin/newdomain.html b/templates/admin/newdomain.html index 00b618811..4a06830ae 100644 --- a/templates/admin/newdomain.html +++ b/templates/admin/newdomain.html @@ -1,4 +1,4 @@ -{% extends "admin/layout_simple.html" %} +{% extends "layout_simple.html" %} {% block html_head %} {% endblock %} diff --git a/templates/layout_simple.html b/templates/layout_simple.html new file mode 100644 index 000000000..47431d742 --- /dev/null +++ b/templates/layout_simple.html @@ -0,0 +1,18 @@ + + + + + + + + + {%block html_head %}{% endblock %} + + + +
+ {%block content %}{% endblock %} +
+ + diff --git a/templates/main/autoreply.html b/templates/main/autoreply.html index a59d1096a..512235191 100644 --- a/templates/main/autoreply.html +++ b/templates/main/autoreply.html @@ -1,6 +1,7 @@ {% extends "main/header.html" %} {% load i18n %} {% block html_head %} + {% endblock %} {% block menu %} diff --git a/templates/main/chpassword.html b/templates/main/chpassword.html new file mode 100644 index 000000000..93aeac38b --- /dev/null +++ b/templates/main/chpassword.html @@ -0,0 +1,18 @@ +{% extends "layout_simple.html" %} +{% block html_head %} + +{% endblock %} +{% block content %} +{% load i18n %} +

{% trans "Change password" %}

+ +{% if error %}
{{ error }}
{% endif %} +{% url main.views.changepassword as action_url %} +
+ {% include "genericform.html" %} + +
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/main/header.html b/templates/main/header.html index 30c497ac5..85b2b15bd 100644 --- a/templates/main/header.html +++ b/templates/main/header.html @@ -1,4 +1,7 @@ {% extends "layout.html" %} +{% block html_head %} + +{% endblock %} {% block content %} {% load i18n %}
diff --git a/templates/main/menu.html b/templates/main/menu.html index 90424997f..ff15fad03 100644 --- a/templates/main/menu.html +++ b/templates/main/menu.html @@ -1,6 +1,8 @@ {% load i18n %}