mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
When the demo application is enabled, we disable the ''password change'' action for default super administrator.
see #187
This commit is contained in:
@@ -35,6 +35,10 @@ def announcement(**kwargs):
|
||||
return [txt]
|
||||
return ""
|
||||
|
||||
def password_change(user):
|
||||
return [user.id == 1]
|
||||
|
||||
if 'modoboa.demo' in settings.INSTALLED_APPS:
|
||||
events.register("UserMenuDisplay", menu)
|
||||
events.register("GetAnnouncement", announcement)
|
||||
events.register("PasswordChange", password_change)
|
||||
|
||||
@@ -256,6 +256,17 @@ callbacks and indicates the place where the announcement will appear:
|
||||
|
||||
Callbacks listening to this event must return a list of string.
|
||||
|
||||
PasswordChange
|
||||
--------------
|
||||
|
||||
Raised just before a *password change* action. The associated ``User``
|
||||
object is provided inside the ``user`` keyword argument.
|
||||
|
||||
Callbacks listening to this event must return a list containing either
|
||||
``True`` or ``False``. If at least one ``True`` is returned, the
|
||||
*password change* will be cancelled (ie. changing the password for
|
||||
this user is disabled).
|
||||
|
||||
Parameters
|
||||
==========
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ events = ["CreateDomain",
|
||||
"DeleteMailbox",
|
||||
"ModifyMailbox",
|
||||
|
||||
"PasswordChange",
|
||||
|
||||
"UserMenuDisplay",
|
||||
"AdminMenuDisplay",
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{% extends "layout_simple.html" %}
|
||||
{% block content %}
|
||||
<div class="error"><p>{{ error }}</p></div>
|
||||
{% endblock %}
|
||||
+10
-3
@@ -3,9 +3,10 @@ from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib.auth.decorators \
|
||||
import login_required, user_passes_test
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib.webutils import _render, ajax_response
|
||||
from modoboa.lib import parameters, events
|
||||
from modoboa.lib.webutils import _render, _render_error, ajax_response
|
||||
from forms import *
|
||||
from modoboa.admin.models import Mailbox, Alias
|
||||
from modoboa.admin.lib import is_domain_admin
|
||||
@@ -21,6 +22,11 @@ def changepassword(request, tplname="userprefs/chpassword.html"):
|
||||
target = request.user
|
||||
else:
|
||||
target = Mailbox.objects.get(user=request.user.id)
|
||||
res = events.raiseQueryEvent("PasswordChange", user=request.user)
|
||||
if True in res:
|
||||
ctx = dict(error=_("Password change is disabled for this user"))
|
||||
return _render_error(request, errortpl="error_simple", user_context=ctx)
|
||||
|
||||
error = None
|
||||
if request.method == "POST":
|
||||
form = ChangePasswordForm(target, request.POST)
|
||||
@@ -32,7 +38,8 @@ def changepassword(request, tplname="userprefs/chpassword.html"):
|
||||
request.session["password"] = encrypt(request.POST["confirmation"])
|
||||
target.save()
|
||||
return ajax_response(request, respmsg=_("Password changed"))
|
||||
return ajax_response(request, status="ko", template=tplname, form=form, error=error)
|
||||
return ajax_response(request, status="ko", template=tplname,
|
||||
form=form, error=error)
|
||||
|
||||
form = ChangePasswordForm(target)
|
||||
return _render(request, 'userprefs/chpassword.html', {
|
||||
|
||||
Reference in New Issue
Block a user