summaryrefslogtreecommitdiffstats
path: root/core/views/user_registration.py
blob: d4ce58e41685ef609691e8025ae447fd111376e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from django import forms
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.core.exceptions import ValidationError

"""
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>
            un = form.cleaned_data["username"]
            pw= form.cleaned_data["password1"]

            return HttpResponseRedirect("/accounts/login/")
    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;"}
        ))
    email = forms.CharField(strip=True, required=True, 
        label="email",
        widget=forms.TextInput(
            attrs={"size":  35, "placeholder": "e.g. anathema@potatohut.exp", 
            "style": "vertical-align: text-top;"}
        ))
    password1 = forms.CharField(strip=True, required=True,         
        label="Troggle 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 troggle password",
        widget=forms.TextInput(
            attrs={"size":  30, "placeholder": "same as the password above", 
            "style": "vertical-align: text-top;"}
        ) )

    def clean(self):
        cleaned_data = super().clean()
        pw1 = cleaned_data.get("password1")
        pw2 = cleaned_data.get("password2")

        if pw1 != pw2:
            raise ValidationError(
                "Retyped password does not match initial password: please fix this."
            )