mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 22:47:03 +00:00
user registration pages
This commit is contained in:
42
core/views/user_registration.py
Normal file
42
core/views/user_registration.py
Normal file
@@ -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;"}
|
||||||
|
) )
|
||||||
|
|
||||||
|
# )
|
||||||
@@ -43,15 +43,16 @@ def load_users():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
with open(jsonfile, 'r', encoding='utf-8') as json_f:
|
with open(jsonfile, 'r', encoding='utf-8') as json_f:
|
||||||
|
message = ""
|
||||||
try:
|
try:
|
||||||
registered_users_dict = json.load(json_f)
|
registered_users_dict = json.load(json_f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("File not found!")
|
message = f"File {jsonfile} not found!"
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
print("Invalid JSON format! - JSONDecodeError")
|
message = f"Invalid JSON format! - JSONDecodeError for {jsonfile}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An exception occurred: {str(e)}")
|
message = f"! Troggle USERs. Failed to load {jsonfile} JSON file. Exception <{e}>"
|
||||||
message = f"! Troggle USERs. Failed to load {jsonfile} JSON file"
|
if message:
|
||||||
print(message)
|
print(message)
|
||||||
DataIssue.objects.update_or_create(parser=PARSER_USERS, message=message, url=jsonurl)
|
DataIssue.objects.update_or_create(parser=PARSER_USERS, message=message, url=jsonurl)
|
||||||
return None
|
return None
|
||||||
@@ -86,11 +87,6 @@ def load_users():
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print(f" - user: BAD username for {userdata} ")
|
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 = []
|
ru = []
|
||||||
for u in User.objects.all():
|
for u in User.objects.all():
|
||||||
@@ -106,7 +102,8 @@ def load_users():
|
|||||||
|
|
||||||
jsondict = { "registered_users": ru }
|
jsondict = { "registered_users": ru }
|
||||||
encryptedfile = settings.EXPOWEB / ENCRYPTED_DIR / "encrypt.json"
|
encryptedfile = settings.EXPOWEB / ENCRYPTED_DIR / "encrypt.json"
|
||||||
# with open(encryptedfile, 'w', encoding='utf-8') as json_f:
|
if settings.DEVSERVER:
|
||||||
# json.dump(jsondict, json_f, indent=1)
|
with open(encryptedfile, 'w', encoding='utf-8') as json_f:
|
||||||
|
json.dump(jsondict, json_f, indent=1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -50,4 +50,6 @@ This is because Django is Opinionated and does lots of Invisible Defaults
|
|||||||
<p><input type="submit" value="Login →"></p>
|
<p><input type="submit" value="Login →"></p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<hr><hr>
|
||||||
|
{{form}}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Note that we need to have TWO DIFFERENT logout templates to make this work,
|
|||||||
the other one is in
|
the other one is in
|
||||||
troggle/templates/registration/
|
troggle/templates/registration/
|
||||||
That one is for logging out of the Django Admin system.
|
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
|
Not forgetting the template in
|
||||||
troggle/templates/login/index
|
troggle/templates/login/index
|
||||||
|
|||||||
51
templates/login/register.html
Normal file
51
templates/login/register.html
Normal file
@@ -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 %}
|
||||||
@@ -33,10 +33,10 @@ This file is actually identical to troggle/templates/login/index.html
|
|||||||
<div class='space'></div>
|
<div class='space'></div>
|
||||||
{% if invalid %}
|
{% if invalid %}
|
||||||
<p class='error'>The username and password you provided don't match. Please try again.</p>
|
<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/>
|
<p>Have you <a href='/accounts/password_reset/'>forgotten your password - reset it</a>?<br/>
|
||||||
Or perhaps <a href='/accounts/forgottenusername/'>your username</a>?</p>
|
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>
|
<div class='space'></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -51,5 +51,8 @@ This file is actually identical to troggle/templates/login/index.html
|
|||||||
<br/>
|
<br/>
|
||||||
<p><input type="submit" value="Login →"></p>
|
<p><input type="submit" value="Login →"></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
{{form}}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
16
urls.py
16
urls.py
@@ -47,16 +47,20 @@ from troggle.core.views.logbooks import (
|
|||||||
logentrydelete,
|
logentrydelete,
|
||||||
logreport,
|
logreport,
|
||||||
notablepersons,
|
notablepersons,
|
||||||
|
people_ids,
|
||||||
person,
|
person,
|
||||||
personexpedition,
|
personexpedition,
|
||||||
)
|
)
|
||||||
from troggle.core.views.other import controlpanel, exportlogbook, frontpage, todos
|
from troggle.core.views.other import controlpanel, exportlogbook, frontpage, todos
|
||||||
from troggle.core.views.prospect import prospecting
|
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.scans import allscans, cavewallets, scansingle, walletslistperson, walletslistyear
|
||||||
from troggle.core.views.signup import signup
|
from troggle.core.views.signup import signup
|
||||||
from troggle.core.views.uploads import dwgupload, expofilerename, gpxupload, photoupload
|
from troggle.core.views.uploads import dwgupload, expofilerename, gpxupload, photoupload
|
||||||
from troggle.core.views.wallets_edit import walletedit
|
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
|
"""This sets the actualurlpatterns[] and urlpatterns[] lists which django uses
|
||||||
to resolve urls - in both directions as these are declarative.
|
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'^caves$', caveindex, name="caveindex"),
|
||||||
re_path(r'^indxal.htm$', caveindex, name="caveindex"), # ~420 hrefs to this url in expoweb files
|
re_path(r'^indxal.htm$', caveindex, name="caveindex"), # ~420 hrefs to this url in expoweb files
|
||||||
re_path(r'^people/?$', notablepersons, name="notablepersons"),
|
re_path(r'^people/?$', notablepersons, name="notablepersons"),
|
||||||
|
path('people_ids', people_ids, name="people_ids"),
|
||||||
path('caveslist', caveslist, name="caveslist"),
|
path('caveslist', caveslist, name="caveslist"),
|
||||||
|
|
||||||
path('entrances', entranceindex, name="entranceindex"),
|
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/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
|
# Uploads - uploading a file
|
||||||
path('walletedit/', walletedit, name='walletedit'),
|
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
|
# 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/logout/', expologout, name='expologout'), # same as in django.contrib.auth.urls
|
||||||
path('accounts/login/', expologin, name='expologin'), # 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'^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"),
|
#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"),
|
path('personexpedition/<slug:slug>/<int:year>', personexpedition, name="personexpedition"),
|
||||||
|
|||||||
Reference in New Issue
Block a user