Login required on modals

* adds new login_required_modal decorator
    * can be used before regular login_required decorator to return a proper session-timed-out message
This commit is contained in:
2022-08-25 11:34:09 +02:00
parent 3f907c2b44
commit 9283c12162
36 changed files with 761 additions and 623 deletions

View File

@@ -8,12 +8,12 @@ Created on: 16.11.20
from functools import wraps
from bootstrap_modal_forms.utils import is_ajax
from django.contrib import messages
from django.shortcuts import redirect, get_object_or_404
from django.shortcuts import redirect, get_object_or_404, render
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from konova.settings import DEFAULT_GROUP, ETS_GROUP, ZB_GROUP
from konova.utils.message_templates import MISSING_GROUP_PERMISSION, DATA_UNSHARED
@@ -146,4 +146,28 @@ def shared_access_required(obj_class, id_key):
return redirect("home")
return function(request, *args, **kwargs)
return wrap
return decorator
return decorator
def login_required_modal(function):
""" Checks on modal requests whether the user is authenticated or not
If not, the user will not be redirected but informed about the need to relogin.
"""
@wraps(function)
def wrap(request, *args, **kwargs):
is_modal_request = is_ajax(request.META)
is_user_not_logged_in = not request.user.is_authenticated
if is_modal_request and is_user_not_logged_in:
template = "modal/modal_generic.html"
body_template = "modal/modal_session_timed_out.html"
context = {
"modal_body_template": body_template,
"modal_title": _("Session timed out"),
}
return render(request, template, context)
return function(request, *args, **kwargs)
return wrap