Partial implementation of ticket #4

This commit is contained in:
tonio
2009-06-17 11:50:21 +02:00
parent ae68c14396
commit d2d092dd8f
14 changed files with 202 additions and 66 deletions
+1 -7
View File
@@ -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:
+7
View File
@@ -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)}
+81 -49
View File
@@ -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 <tonio@ngyn.org>\n"
"Language-Team: LANGUAGE <LL@li.org>\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"
+24
View File
@@ -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"]
+4 -3
View File
@@ -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)
+2 -1
View File
@@ -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'),
)
+32 -3
View File
@@ -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
})
+7 -1
View File
@@ -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);
});
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends "admin/layout_simple.html" %}
{% extends "layout_simple.html" %}
{% block html_head %}
<script src="/static/js/form.js" type="text/javascript"></script>
{% endblock %}
+18
View File
@@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/static/stylesheets/SqueezeBox.css" />
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
<script src="/static/js/mootools.js" type="text/javascript"></script>
<script src="/static/js/SqueezeBox.js" type="text/javascript"></script>
{%block html_head %}{% endblock %}
</head>
<body>
<div id="content">
{%block content %}{% endblock %}
</div>
</body>
</html>
+1
View File
@@ -1,6 +1,7 @@
{% extends "main/header.html" %}
{% load i18n %}
{% block html_head %}
<script src="/static/js/main.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
{% endblock %}
{% block menu %}
+18
View File
@@ -0,0 +1,18 @@
{% extends "layout_simple.html" %}
{% block html_head %}
<script src="/static/js/form.js" type="text/javascript"></script>
{% endblock %}
{% block content %}
{% load i18n %}
<div class="title"><h1>{% trans "Change password" %}</h1></div>
{% if error %}<div class="error">{{ error }}</div>{% endif %}
{% url main.views.changepassword as action_url %}
<form action="{{ action_url }}" method="post" name="chpwdform" id="chpwdform">
{% include "genericform.html" %}
<div class="lastrow" align="center">
<input type="submit" class="button" name="submit" value="{% trans 'Update' %}" />
</div>
</form>
{% endblock %}
+3
View File
@@ -1,4 +1,7 @@
{% extends "layout.html" %}
{% block html_head %}
<script src="/static/js/main.js" type="text/javascript"></script>
{% endblock %}
{% block content %}
{% load i18n %}
<div class="header">
+3 -1
View File
@@ -1,6 +1,8 @@
{% load i18n %}
<ul>
<li><a href="">
{% url main.views.changepassword as chpwd_url %}
<li><a href="{{ chpwd_url }}"
class="boxed" rel="{handler:'iframe',size:{x:350,y:220}}">
<img src="/static/pics/edit.png" border="0"/>
{% trans "Change password" %}</a>
</li>