mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 06:27:34 +00:00
Registering existing and new users works, but is ephemeral.
This commit is contained in:
@@ -2,27 +2,50 @@ from django import forms
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from troggle.core.models.troggle import DataIssue, Person
|
||||
from troggle.parsers.users import register_user
|
||||
|
||||
"""
|
||||
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):
|
||||
|
||||
def register(request, username=None):
|
||||
"""To register a new user on the troggle system, similar to the "expo" user
|
||||
(with cavey:beery password) but specific to an individual
|
||||
"""
|
||||
current_user = request.user
|
||||
|
||||
if request.method == "POST":
|
||||
form = register_form(request.POST)
|
||||
if form.is_valid():
|
||||
# <process form cleaned data>
|
||||
un = form.cleaned_data["username"]
|
||||
pw= form.cleaned_data["password1"]
|
||||
|
||||
email = form.cleaned_data["email"]
|
||||
expoers = User.objects.filter(username=un)
|
||||
if len(expoers) != 0:
|
||||
# this is a password re-set, not a new registration. So we need to check it is the same person.
|
||||
form_user = expoers[0]
|
||||
if current_user != form_user:
|
||||
print(f"## UNAUTHORIZED Password reset ## {current_user} {form_user}")
|
||||
return render(request, "login/register.html", {"form": form, "unauthorized": True})
|
||||
# create User in the system and refresh stored encrypted user list and git commit it.
|
||||
register_user(un, email, password=pw, pwhash=None)
|
||||
return HttpResponseRedirect("/accounts/login/")
|
||||
else:
|
||||
form = register_form(initial={"visible": "True"})
|
||||
if current_user:
|
||||
form = register_form(initial={"visible": "True", "username": current_user.username})
|
||||
elif username:
|
||||
form = register_form(initial={"visible": "True", "username": username})
|
||||
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",
|
||||
@@ -33,7 +56,7 @@ class register_form(forms.Form): # not a model-form, just a form-form
|
||||
email = forms.CharField(strip=True, required=True,
|
||||
label="email",
|
||||
widget=forms.TextInput(
|
||||
attrs={"size": 35, "placeholder": "e.g. anathema@potatohut.exp",
|
||||
attrs={"size": 35, "placeholder": "e.g. anathema@potatohut.expo",
|
||||
"style": "vertical-align: text-top;"}
|
||||
))
|
||||
password1 = forms.CharField(strip=True, required=True,
|
||||
@@ -57,4 +80,20 @@ class register_form(forms.Form): # not a model-form, just a form-form
|
||||
if pw1 != pw2:
|
||||
raise ValidationError(
|
||||
"Retyped password does not match initial password: please fix this."
|
||||
)
|
||||
)
|
||||
un = cleaned_data.get("username")
|
||||
if un in ["expo", "expoadmin"]:
|
||||
raise ValidationError(
|
||||
"Sorry, please do not try to be clever. This username is hard-coded and you can't edit it here. We were students once, too."
|
||||
)
|
||||
|
||||
expoers = Person.objects.filter(slug=un)
|
||||
if len(expoers) == 0:
|
||||
raise ValidationError(
|
||||
"Sorry, we are not registering new people yet. Try again next week. We are still getting the bugs out of this.."
|
||||
)
|
||||
if len(expoers) != 1:
|
||||
raise ValidationError(
|
||||
"Sorry, that troggle identifier has duplicates. Contact a nerd on the Nerd email list, or (better) the Matrix website chat."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user