Skip to content

Commit

Permalink
Added (extremely) basic login
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Jan 20, 2025
1 parent 5794a89 commit 724dc3e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/morphodict/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/morphodict/site/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/morphodict/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 724dc3e

Please sign in to comment.