From ce508b0eb28551efbb9d7aaf18f1e76994e7c38b Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 26 Jan 2025 19:04:56 +0000 Subject: Use logon not cookie when editing pages --- core/views/expo.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'core/views/expo.py') diff --git a/core/views/expo.py b/core/views/expo.py index 89215a4..63f1d33 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -19,7 +19,9 @@ from troggle.core.utils import ( current_expo, get_cookie, git_string, + get_git_string, write_and_commit, + is_identified_user ) from troggle.core.views.editor_helpers import HTMLarea from troggle.core.views.uploads import edittxtpage @@ -455,15 +457,17 @@ def editexpopage(request, path): print("### File not found ### ", filepath) filefound = False - editor = get_cookie(request) - + current_user = request.user + if identified_login := is_identified_user(current_user): + editor = get_git_string(current_user) + else: + editor = get_cookie(request) + if request.method == "POST": # If the form has been submitted... pageform = ExpoPageForm(request.POST) # A form bound to the POST data if pageform.is_valid(): # Form valid therefore write file editor = pageform.cleaned_data["who_are_you"] editor = git_string(editor) - # print("### \n", str(pageform)[0:300]) - # print("### \n csrfmiddlewaretoken: ",request.POST['csrfmiddlewaretoken']) if filefound: headmatch = re.match(r"(.*).*(.*)", head, re.DOTALL + re.IGNORECASE) if headmatch: @@ -490,7 +494,7 @@ def editexpopage(request, path): if not filefound or result != html: # Check if content changed at all edit_response = HttpResponseRedirect(reverse("expopage", args=[path])) # Redirect after POST edit_response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # cookie expires after COOKIE_MAX_AGE seconds - print(f"Cookie set: {editor} for {COOKIE_MAX_AGE/3600} hours") + print(f"Cookie set: {editor} for {COOKIE_MAX_AGE/(24*3600)} days") try: change_message = pageform.cleaned_data["change_message"] editor = pageform.cleaned_data["who_are_you"] @@ -507,9 +511,9 @@ def editexpopage(request, path): (title,) = m.groups() else: title = "" - pageform = ExpoPageForm(initial={"who_are_you":editor, "html": body, "title": title}) + pageform = ExpoPageForm(initial={"identified_login": identified_login, "who_are_you":editor, "html": body, "title": title}) else: - pageform = ExpoPageForm(initial={"who_are_you":editor}) + pageform = ExpoPageForm(initial={"identified_login": identified_login, "who_are_you":editor}) return render( @@ -540,6 +544,8 @@ class ExpoPageForm(forms.Form): "style": "vertical-align: text-top;"} ) ) + identified_login = forms.BooleanField(widget=forms.CheckboxInput(attrs={"onclick":"return false"})) # make it readonly + who_are_you = forms.CharField( widget=forms.Textarea( attrs={"cols": 90, "rows": 1, "placeholder": "You have edited this page, who are you ? e.g. 'Animal '", -- cgit v1.2.3