diff --git a/src/morphodict/frontend/views.py b/src/morphodict/frontend/views.py index b0a7c4c8e..0e9eb46ab 100644 --- a/src/morphodict/frontend/views.py +++ b/src/morphodict/frontend/views.py @@ -12,6 +12,7 @@ import morphodict.analysis from morphodict.search import presentation, search_with_affixes +from django.contrib.auth import logout from morphodict.frontend.forms import WordSearchForm from morphodict.paradigm.views import paradigm_context_for_lemma from morphodict.phrase_translate.fst import ( @@ -88,6 +89,15 @@ def index(request): # pragma: no cover :return: """ + if settings.MORPHODICT_REQUIRES_LOGIN_IN_GROUP: + if not request.user.is_authenticated: + return redirect("/accounts/login/?next=%s" % request.path) + else: + groupnames = [x["name"] for x in request.user.groupsvalues("name")] + if settings.MORPHODICT_REQUIRES_LOGIN_IN_GROUP not in groupnames: + logout(request) + return redirect("/accounts/login/?next=%s" % request.path) + user_query = request.GET.get("q", None) dict_source = get_dict_source(request) search_run = None diff --git a/src/morphodict/site/settings.py b/src/morphodict/site/settings.py index 8dfa67a12..f28c432f8 100644 --- a/src/morphodict/site/settings.py +++ b/src/morphodict/site/settings.py @@ -385,6 +385,11 @@ def defaultDatabasePath(): # a different style, with tags like `[VERB][TA]`. MORPHODICT_TAG_STYLE = "Plus" +# The basic password setup system. +MORPHODICT_REQUIRES_LOGIN_IN_GROUP = env( + "MORPHODICT_REQUIRES_LOGIN_IN_GROUP", default=False +) + # The name of the source language, written in the target language. Used in # default templates to describe what language the dictionary is for. MORPHODICT_SOURCE_LANGUAGE_NAME: RequiredString = _MORPHODICT_REQUIRED_SETTING_SENTINEL diff --git a/src/morphodict/urls.py b/src/morphodict/urls.py index c8af777b7..dc337c107 100644 --- a/src/morphodict/urls.py +++ b/src/morphodict/urls.py @@ -5,6 +5,7 @@ from django.conf import settings from django.contrib import admin from django.contrib.sitemaps.views import sitemap +from django.contrib.auth import views as auth_views from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.urls import include, path from django_js_reverse.views import urls_js @@ -58,6 +59,7 @@ ################################# Special URLS ################################# # Reverse URLs in JavaScript: https://github.com/ierror/django-js-reverse path("jsreverse", urls_js, name="js_reverse"), + path("accounts/login/", auth_views.LoginView.as_view(), name="user_login"), ] if hasattr(settings, "GOOGLE_SITE_VERIFICATION"):