diff options
-rw-r--r-- | core/views/user_registration.py | 42 | ||||
-rw-r--r-- | parsers/users.py | 21 | ||||
-rw-r--r-- | templates/login/index.html | 2 | ||||
-rw-r--r-- | templates/login/logout.html | 2 | ||||
-rw-r--r-- | templates/login/register.html | 51 | ||||
-rw-r--r-- | templates/registration/login.html | 9 | ||||
-rw-r--r-- | urls.py | 16 |
7 files changed, 122 insertions, 21 deletions
diff --git a/core/views/user_registration.py b/core/views/user_registration.py new file mode 100644 index 0000000..df00ed9 --- /dev/null +++ b/core/views/user_registration.py @@ -0,0 +1,42 @@ +from django import forms
+from django.http import HttpResponseRedirect
+from django.shortcuts import render
+
+"""
+This is the new individual user login registration, instead of everyone signing
+in as "expo". This will be useful for the kanban expo organisation tool.
+"""
+
+
+def register(request):
+ if request.method == "POST":
+ form = register_form(request.POST)
+ if form.is_valid():
+ # <process form cleaned data>
+ return HttpResponseRedirect("/success/")
+ else:
+ form = register_form(initial={"visible": "True"})
+
+ return render(request, "login/register.html", {"form": form})
+
+class register_form(forms.Form): # not a model-form, just a form-form
+ username = forms.CharField(strip=True, required=True,
+ label="Username",
+ widget=forms.TextInput(
+ attrs={"size": 35, "placeholder": "e.g. anathema-device",
+ "style": "vertical-align: text-top;"}
+ ))
+ password1 = forms.CharField(strip=True, required=True,
+ label="Password",
+ widget=forms.TextInput(
+ attrs={"size": 30, "placeholder": "your new login password",
+ "style": "vertical-align: text-top;"}
+ ))
+ password2 = forms.CharField(strip=True, required=True,
+ label="Re-type your password",
+ widget=forms.TextInput(
+ attrs={"size": 30, "placeholder": "same as the password above",
+ "style": "vertical-align: text-top;"}
+ ) )
+
+ # )
\ No newline at end of file diff --git a/parsers/users.py b/parsers/users.py index 6a14f5b..de0ce38 100644 --- a/parsers/users.py +++ b/parsers/users.py @@ -31,7 +31,7 @@ def load_users(): DataIssue.objects.filter(parser=PARSER_USERS).delete() key = settings.LONGTERM_SECRET_KEY # Django generated - k = base64.urlsafe_b64encode(key.encode("utf8")[:32]) # make Fernet compatible + k = base64.urlsafe_b64encode(key.encode("utf8")[:32]) # make Fernet compatible f = Fernet(k) jsonfile = settings.EXPOWEB / ENCRYPTED_DIR / USERS_FILE @@ -43,15 +43,16 @@ def load_users(): return None with open(jsonfile, 'r', encoding='utf-8') as json_f: + message = "" try: registered_users_dict = json.load(json_f) except FileNotFoundError: - print("File not found!") + message = f"File {jsonfile} not found!" except json.JSONDecodeError: - print("Invalid JSON format! - JSONDecodeError") + message = f"Invalid JSON format! - JSONDecodeError for {jsonfile}" except Exception as e: - print(f"An exception occurred: {str(e)}") - message = f"! Troggle USERs. Failed to load {jsonfile} JSON file" + message = f"! Troggle USERs. Failed to load {jsonfile} JSON file. Exception <{e}>" + if message: print(message) DataIssue.objects.update_or_create(parser=PARSER_USERS, message=message, url=jsonurl) return None @@ -86,11 +87,6 @@ def load_users(): return None else: print(f" - user: BAD username for {userdata} ") - # if userdata["date"] != "" or userdata["date"] != "None": - # message = f"! {str(self.walletname)} Date format not ISO {userdata['date']}. Failed to load from {jsonfile} JSON file" - # from troggle.core.models.troggle import DataIssue - # DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl) - ru = [] for u in User.objects.all(): @@ -106,7 +102,8 @@ def load_users(): jsondict = { "registered_users": ru } encryptedfile = settings.EXPOWEB / ENCRYPTED_DIR / "encrypt.json" - # with open(encryptedfile, 'w', encoding='utf-8') as json_f: - # json.dump(jsondict, json_f, indent=1) + if settings.DEVSERVER: + with open(encryptedfile, 'w', encoding='utf-8') as json_f: + json.dump(jsondict, json_f, indent=1) return True diff --git a/templates/login/index.html b/templates/login/index.html index 6db786e..889149d 100644 --- a/templates/login/index.html +++ b/templates/login/index.html @@ -50,4 +50,6 @@ This is because Django is Opinionated and does lots of Invisible Defaults <p><input type="submit" value="Login →"></p> </form> </div> +<hr><hr> +{{form}} {% endblock %} diff --git a/templates/login/logout.html b/templates/login/logout.html index ccbc200..6bbe65b 100644 --- a/templates/login/logout.html +++ b/templates/login/logout.html @@ -10,7 +10,7 @@ Note that we need to have TWO DIFFERENT logout templates to make this work, the other one is in troggle/templates/registration/ That one is for logging out of the Django Admin system. -This one is for logging out of the normal system whereas this one +This one is for logging out of the normal system whereas this one is for troggle Not forgetting the template in troggle/templates/login/index diff --git a/templates/login/register.html b/templates/login/register.html new file mode 100644 index 0000000..9c1527f --- /dev/null +++ b/templates/login/register.html @@ -0,0 +1,51 @@ +{% extends 'base.html' %} + +{% block content %} +<!-- this overrides the django.contrib.auth default form +and it must be placed in +troggle/templates/login/register.html +because magic + +This is because Django is Opinionated and does lots of Invisible Defaults +see +https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project +--> +<script> +function myFunction() { + var x = document.getElementById("id_password1"); + if (x.type === "password") { + x.type = "text"; + } else { + x.type = "password"; + } + var x = document.getElementById("id_password2"); + if (x.type === "password") { + x.type = "text"; + } else { + x.type = "password"; + } +} +</script> +<div class='middle'> +<h2>User registration - for a personal login to Troggle</h2> +</div> +<h3>Register a password and your email</h3> +<!--using template login/register.html --> +<p>For previous expoers, your username must be your id as listed on the <a href='/people'>past expoers list</a> +<div style='width: 40%' align="right"> + <form method="post" accept-charset="utf-8">{% csrf_token %} + {{form.as_p}} + +<div class='align-right'> + <input type="checkbox" checked name="visible" onclick="myFunction()">Make Passwords visible + +<br /><br /><input type="submit" value="Register →"> +</div> +</form> + + + + + + +{% endblock %} diff --git a/templates/registration/login.html b/templates/registration/login.html index ac1d15c..88732fd 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -33,10 +33,10 @@ This file is actually identical to troggle/templates/login/index.html <div class='space'></div> {% if invalid %} <p class='error'>The username and password you provided don't match. Please try again.</p> - <p>Have you <a href='/accounts/forgottenpassword/'>forgotten your password</a>?<br/> - Or perhaps <a href='/accounts/forgottenusername/'>your username</a>?</p> + <p>Have you <a href='/accounts/password_reset/'>forgotten your password - reset it</a>?<br/> + Or perhaps <a href='/accounts/password_change/'>change your password</a>?</p> - <p>Neither of those links work yet, by the way, I'm only trying to *appear* helpful. + <p>Neither of those links work properly yet, by the way, I'm only trying to *appear* helpful. <div class='space'></div> {% endif %} @@ -51,5 +51,8 @@ This file is actually identical to troggle/templates/login/index.html <br/> <p><input type="submit" value="Login →"></p> </form> + + <hr/> + {{form}} </div> {% endblock %} @@ -47,16 +47,20 @@ from troggle.core.views.logbooks import ( logentrydelete, logreport, notablepersons, + people_ids, person, personexpedition, ) from troggle.core.views.other import controlpanel, exportlogbook, frontpage, todos from troggle.core.views.prospect import prospecting +from troggle.core.views.user_registration import register from troggle.core.views.scans import allscans, cavewallets, scansingle, walletslistperson, walletslistyear from troggle.core.views.signup import signup from troggle.core.views.uploads import dwgupload, expofilerename, gpxupload, photoupload from troggle.core.views.wallets_edit import walletedit +# from troggle.core.views.user_registration import SignUpView # Warning: a Class-based View + """This sets the actualurlpatterns[] and urlpatterns[] lists which django uses to resolve urls - in both directions as these are declarative. @@ -134,12 +138,13 @@ trogglepatterns = [ re_path(r'^caves$', caveindex, name="caveindex"), re_path(r'^indxal.htm$', caveindex, name="caveindex"), # ~420 hrefs to this url in expoweb files re_path(r'^people/?$', notablepersons, name="notablepersons"), + path('people_ids', people_ids, name="people_ids"), path('caveslist', caveslist, name="caveslist"), path('entrances', entranceindex, name="entranceindex"), re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')), # needs docutils Python module (http://docutils.sf.net/). - re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls & /admin/jsi18n/ + path('admin/', admin.site.urls), # includes admin login & logout urls & /admin/jsi18n/ # Uploads - uploading a file path('walletedit/', walletedit, name='walletedit'), @@ -163,11 +168,12 @@ trogglepatterns = [ # NB setting url pattern name to 'login' instea dof 'expologin' with override Django, see https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns path('accounts/logout/', expologout, name='expologout'), # same as in django.contrib.auth.urls path('accounts/login/', expologin, name='expologin'), # same as in django.contrib.auth.urls - #re_path(r'^accounts/', include('django.contrib.auth.urls')), # see site-packages\registration\auth_urls_classes.py + path("accounts/register", register, name="register"), + #path("accounts/register", SignUpView.as_view(), name="signup"), + path('accounts/', include('django.contrib.auth.urls')), # see site-packages\registration\auth_urls_classes.py + -# Persons - nasty surname recognition logic fails for 19 people! See also Wallets by person below. - # path('person/<str:name>', person, name="person"), # This is much more complex than it looks.. - path('person/<slug:slug>', person, name="person"), + path('person/<slug:slug>', person, name="person"), #re_path(r'^person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[\-]*[A-Z]*[a-zA-Z\-&;]*)/?', person, name="person"), #re_path(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', personexpedition, name="personexpedition"), path('personexpedition/<slug:slug>/<int:year>', personexpedition, name="personexpedition"), |