mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
+23
-11
@@ -9,12 +9,33 @@ from django.utils.translation import ugettext as _
|
||||
from django.views.decorators.cache import never_cache
|
||||
|
||||
from modoboa.core.forms import LoginForm
|
||||
from modoboa.lib import events
|
||||
from modoboa.lib import events, parameters
|
||||
from modoboa.lib.web_utils import _render_to_string
|
||||
|
||||
from ..extensions import exts_pool
|
||||
|
||||
logger = logging.getLogger("modoboa.auth")
|
||||
|
||||
|
||||
def find_nextlocation(request, user):
|
||||
"""Find next location for given user after login."""
|
||||
if not user.last_login:
|
||||
# Redirect to profile on first login
|
||||
return reverse("core:user_index")
|
||||
nextlocation = request.POST.get("next", None)
|
||||
if nextlocation is None or nextlocation == "None":
|
||||
if request.user.role == "SimpleUsers":
|
||||
topredir = parameters.get_admin("DEFAULT_TOP_REDIRECTION")
|
||||
if topredir != "user":
|
||||
infos = exts_pool.get_extension_infos(topredir)
|
||||
nextlocation = infos["url"] if infos["url"] else infos["name"]
|
||||
else:
|
||||
nextlocation = reverse("core:user_index")
|
||||
else:
|
||||
nextlocation = reverse("core:dashboard")
|
||||
return nextlocation
|
||||
|
||||
|
||||
def dologin(request):
|
||||
"""Try to authenticate."""
|
||||
error = None
|
||||
@@ -25,10 +46,6 @@ def dologin(request):
|
||||
user = authenticate(username=form.cleaned_data["username"],
|
||||
password=form.cleaned_data["password"])
|
||||
if user and user.is_active:
|
||||
nextlocation = None
|
||||
if not user.last_login:
|
||||
# Redirect to profile on first login
|
||||
nextlocation = reverse("core:user_index")
|
||||
login(request, user)
|
||||
if not form.cleaned_data["rememberme"]:
|
||||
request.session.set_expiry(0)
|
||||
@@ -43,12 +60,7 @@ def dologin(request):
|
||||
events.raiseEvent("UserLogin", request,
|
||||
form.cleaned_data["username"],
|
||||
form.cleaned_data["password"])
|
||||
|
||||
if nextlocation is None:
|
||||
nextlocation = request.POST.get("next", None)
|
||||
if nextlocation is None or nextlocation == "None":
|
||||
nextlocation = reverse("topredirection")
|
||||
return HttpResponseRedirect(nextlocation)
|
||||
return HttpResponseRedirect(find_nextlocation(request, user))
|
||||
error = _(
|
||||
"Your username and password didn't match. Please try again.")
|
||||
logger.warning(
|
||||
|
||||
@@ -10,9 +10,7 @@ import sys
|
||||
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import render
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
@@ -138,34 +136,6 @@ def size2integer(value):
|
||||
return 0
|
||||
|
||||
|
||||
@login_required
|
||||
def topredirection(request):
|
||||
"""Simple view to redirect the request when no application is specified.
|
||||
|
||||
The default "top redirection" can be specified in the *Admin >
|
||||
Settings* panel. It is the application that will be
|
||||
launched. Those not allowed to access the application will be
|
||||
redirected to their preferences page.
|
||||
|
||||
This feature only applies to simple users.
|
||||
|
||||
:param request: a Request object
|
||||
"""
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.core.extensions import exts_pool
|
||||
|
||||
if request.user.role == "SimpleUsers":
|
||||
topredir = parameters.get_admin("DEFAULT_TOP_REDIRECTION", app="core")
|
||||
if topredir != "user":
|
||||
infos = exts_pool.get_extension_infos(topredir)
|
||||
path = infos["url"] if infos["url"] else infos["name"]
|
||||
else:
|
||||
path = reverse("core:user_index")
|
||||
else:
|
||||
path = reverse("core:dashboard")
|
||||
return HttpResponseRedirect(path)
|
||||
|
||||
|
||||
class NavigationParameters(object):
|
||||
"""
|
||||
Just a simple object to manipulate navigation parameters.
|
||||
|
||||
@@ -7,7 +7,6 @@ from modoboa.lib import events
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^$', 'modoboa.lib.web_utils.topredirection', name="topredirection"),
|
||||
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
|
||||
{'packages': ('modoboa', ), }),
|
||||
('', include('modoboa.core.urls', namespace="core")),
|
||||
|
||||
Reference in New Issue
Block a user