Layout modifications (mostly menus).

Admin can now change his password correctly.
This commit is contained in:
tonio
2010-06-09 17:41:32 +02:00
parent 1c35ce5757
commit 2c6511e8e4
13 changed files with 45 additions and 51 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ def domains(request):
mb = Mailbox.objects.get(user=request.user.id)
return mailboxes(request, dom_id=mb.domain.id)
return HttpResponseRedirect(reverse(userprefs.views.index))
return HttpResponseRedirect(reverse(userprefs.views.preferences))
domains = Domain.objects.all()
counters = {}
+1 -1
View File
@@ -42,7 +42,7 @@ def urls():
def menu(**kwargs):
import views
if kwargs["target"] == "user_menu_box":
if kwargs["target"] == "top_menu":
return [
{"name" : "quarantine",
"label" : _("Quarantine"),
+1 -1
View File
@@ -48,7 +48,7 @@ def urls():
def menu(**kwargs):
import views
if kwargs["target"] != "user_menu_bar":
if kwargs["target"] != "uprefs_menu":
return []
return [
{"name" : "autoreply",
@@ -1,6 +1,7 @@
{% extends "nlayout.html" %}
{% load i18n %}
{% load admin_extras %}
{% load stats_extra %}
{% block html_head %}
<style type="text/css">
#graphcontent {
+1 -1
View File
@@ -52,7 +52,7 @@ def urls():
def menu(**kwargs):
import views
if kwargs["target"] != "user_menu_box":
if kwargs["target"] != "top_menu":
return []
return [
{"name" : "webmail",
+2 -2
View File
@@ -16,7 +16,7 @@ class SimpleBackend:
mb = Mailbox.objects.get(full_address=username)
except Exception:
return None
if not check_password(password, mb.password):
if not _check_password(password, mb.password):
return None
return user
@@ -26,7 +26,7 @@ class SimpleBackend:
except User.DoesNotExist:
return None
def check_password(password, crypted):
def _check_password(password, crypted):
scheme = parameters.get_admin("admin", "PASSWORD_SCHEME")
if scheme == "crypt":
return crypt.crypt(password, crypted) == crypted
+1 -1
View File
@@ -25,7 +25,7 @@
<div class="left" style="width: 50%">
<ul>
{% loadextmenu user %}
{% uprefs_menu user %}
{% options_menu user %}
{% if user.is_superuser or perms.admin.view_domain %}
<li class="dropdown topdropdown">
-13
View File
@@ -1,13 +0,0 @@
{% extends "nlayout.html" %}
{% load i18n %}
{% block html_head %}
<script src="/static/js/calendar.js" type="text/javascript"></script>
<script src="/static/js/preferences.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/static/stylesheets/calendar.css" />
{% endblock %}
{% block middletitle %}{% trans "General" %}{% endblock %}
{% block content %}
<div id="subcontent">
{% block subcontent %}{% endblock %}
</div>
{% endblock %}
-16
View File
@@ -1,16 +0,0 @@
{% extends "userprefs/header.html" %}
{% load i18n %}
{% block menu %}
{% load uprefs_extras %}
{% endblock %}
{% block subcontent %}
<div class="info">
<img src="/static/pics/info.png" border="0" />
{% if arm %}
{% trans "Your auto-reply message is activated." %}
{% else %}
{% trans "Your auto-reply message is not activated." %}
{% endif %}
</div>
{% endblock %}
+2
View File
@@ -1,9 +1,11 @@
{% extends "nlayout.html" %}
{% load i18n %}
{% load uprefs_extras %}
{% block html_head %}
<script src="/static/js/preferences.js" type="text/javascript"></script>
{% endblock %}
{% block middletitle %}{% trans "Preferences" %}{% endblock %}
{% block menu %}{% uprefs_menu user %}{% endblock %}
{% block content %}
<form method="POST" action="{% url userprefs.views.savepreferences %}">
{% include "common/parameters.html" %}
+11 -5
View File
@@ -1,5 +1,7 @@
from django import forms
from mailng.lib.authbackends import check_password
from mailng.admin.models import Mailbox
from mailng.lib.authbackends import _check_password
from django.contrib.auth.models import check_password
from django.utils.translation import ugettext as _
class ChangePasswordForm(forms.Form):
@@ -10,13 +12,17 @@ class ChangePasswordForm(forms.Form):
confirmation = forms.CharField(label=_("Confirmation"),
widget=forms.PasswordInput)
def __init__(self, mb, *args, **kwargs):
def __init__(self, target, *args, **kwargs):
super(ChangePasswordForm, self).__init__(*args, **kwargs)
self.mbox = mb
self.target = target
def clean_oldpassword(self):
if not check_password(self.cleaned_data["oldpassword"],
self.mbox.password):
if not isinstance(self.target, Mailbox):
func = check_password
else:
func = _check_password
if not func(self.cleaned_data["oldpassword"],
self.target.password):
raise forms.ValidationError(_("Old password mismatchs"))
return self.cleaned_data["oldpassword"]
+12 -3
View File
@@ -8,7 +8,7 @@ from mailng.lib import events
register = template.Library()
@register.simple_tag
def uprefs_menu(user):
def options_menu(user):
entries = [
{"name" : "userprefs",
"img" : "/static/pics/user.png",
@@ -30,14 +30,23 @@ def uprefs_menu(user):
},
]
entries[0]["menu"] += events.raiseQueryEvent("UserMenuDisplay",
target="user_menu_bar")
target="options_menu")
return render_to_string('common/menulist.html',
{"entries" : entries, "user" : user})
@register.simple_tag
def uprefs_menu(user):
entries = []
entries += events.raiseQueryEvent("UserMenuDisplay",
target="uprefs_menu")
return render_to_string('common/menulist.html',
{"entries" : entries, "user" : user})
@register.simple_tag
def loadextmenu(user):
menu = events.raiseQueryEvent("UserMenuDisplay", target="user_menu_box",
menu = events.raiseQueryEvent("UserMenuDisplay", target="top_menu",
user=user)
return render_to_string('common/menulist.html',
{"entries" : menu, "user" : user})
+12 -7
View File
@@ -15,18 +15,23 @@ from mailng.admin.models import Mailbox
@login_required
def index(request):
mb = Mailbox.objects.get(user=request.user.id)
return _render(request, "userprefs/index.html", {})
return HttpResponseRedirect(reverse(preferences))
@login_required
def changepassword(request):
mb = Mailbox.objects.get(user=request.user.id)
if request.user.id == 1:
target = request.user
else:
target = Mailbox.objects.get(user=request.user.id)
error = None
if request.method == "POST":
form = ChangePasswordForm(mb, request.POST)
form = ChangePasswordForm(target, request.POST)
if form.is_valid():
mb.password = crypt_password(request.POST["confirmation"])
mb.save()
if request.user.id != 1:
target.password = crypt_password(request.POST["confirmation"])
else:
target.set_password(request.POST["confirmation"])
target.save()
ctx = _ctx_ok("")
return HttpResponse(simplejson.dumps(ctx),
mimetype="application/json")
@@ -35,7 +40,7 @@ def changepassword(request):
})
return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
form = ChangePasswordForm(mb)
form = ChangePasswordForm(target)
return render_to_response('userprefs/chpassword.html', {
"form" : form
})