mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -1,3 +1,5 @@
|
||||
"""Core urls."""
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from . import views
|
||||
@@ -5,8 +7,8 @@ from . import views
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
||||
url(r'^dashboard/$', views.DashboardView.as_view(),
|
||||
name="dashboard"),
|
||||
url(r'^$', views.RootDispatchView.as_view(), name="root"),
|
||||
url(r'^dashboard/$', views.DashboardView.as_view(), name="dashboard"),
|
||||
|
||||
url(r'^accounts/login/$', 'modoboa.core.views.auth.dologin',
|
||||
name="login"),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"""Core views."""
|
||||
|
||||
from .base import RootDispatchView
|
||||
from .dashboard import DashboardView
|
||||
|
||||
__all__ = [
|
||||
"DashboardView",
|
||||
"RootDispatchView",
|
||||
]
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# coding: utf-8
|
||||
"""Core authentication views."""
|
||||
|
||||
import logging
|
||||
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
@@ -9,33 +11,14 @@ 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, parameters
|
||||
from modoboa.lib import events
|
||||
from modoboa.lib.web_utils import _render_to_string
|
||||
|
||||
from ..extensions import exts_pool
|
||||
from .base import find_nextlocation
|
||||
|
||||
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
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Base core views."""
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views import generic
|
||||
|
||||
from django.contrib.auth import mixins as auth_mixins
|
||||
|
||||
from modoboa.lib import parameters
|
||||
|
||||
from ..extensions import exts_pool
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
class RootDispatchView(auth_mixins.LoginRequiredMixin, generic.RedirectView):
|
||||
"""Handle root dispatching based on role."""
|
||||
|
||||
def get_redirect_url(self):
|
||||
"""Find proper next hop."""
|
||||
return find_nextlocation(self.request, self.request.user)
|
||||
Reference in New Issue
Block a user