initial registration draft

pull/1/head
parent 4125256601
commit 0566125299

@ -0,0 +1,8 @@
from django import forms
from .models import Helper
class RegisterForm(forms.Form):
name = forms.CharField(max_length=Helper.name.field.max_length, label="Name")
# actually verify phone number, lol
phone = forms.CharField(max_length=Helper.phone.field.max_length, label='Handynummer fuer Benarchrichtigungen')
okf = forms.BooleanField(label='Ich moechte SMS erhalten')

@ -24,6 +24,12 @@ class Helper(models.Model):
number_validated = models.BooleanField(default=False) number_validated = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return self.name return self.name
def send_confirmation(self):
(token, created) = LoginToken.objects.get_or_create(helper=self)
text = f"Hallo {self.name}, hier ist dein Registrierungslink zum Kontaktfestival http://short.url{token.get_absolute_url()}"
msg = Message(to=self, text=text)
msg.save()
return token
class ShiftRegistration(models.Model): class ShiftRegistration(models.Model):
class Meta: class Meta:
@ -37,7 +43,7 @@ class Message(models.Model):
text = models.CharField(max_length=160) text = models.CharField(max_length=160)
to = models.ForeignKey(Helper, on_delete=models.CASCADE) to = models.ForeignKey(Helper, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return f"{to.name}: {text}" return f"{self.to.name}: {self.text}"
def gen_token(): def gen_token():
return secrets.token_urlsafe(20) return secrets.token_urlsafe(20)

@ -7,6 +7,8 @@
<body> <body>
{% if helper%} {% if helper%}
Hallo {{helper.name}} Hallo {{helper.name}}
{%else%}
<a href="{%url 'register'%}">Anmelden</a>
{%endif%} {%endif%}
<div id="content"> <div id="content">
{% block content %}{% endblock %} {% block content %}{% endblock %}

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block title %}Registrierung{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{form.as_p}}
<p>Wir nutzen deine Handynummer um dir Benachrictigungen zu deinen Schichten zu schicken. Wir loeschen alle Daten 7 Tage nach dem Festival.</p>
<input type="submit" value="Anmelden">
</form>
{% endblock %}

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block title %}Registrierung{% endblock %}
{% block content %}
Hallo {{helper.name}},<br>
wir haben dir eine SMS an {{helper.phone}} mit einem Bestaetigunslink geschickt. Sobald du diesen anklickst kann es losgehen!
{% endblock %}

@ -6,4 +6,6 @@ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('login/<slug:token>', views.login, name='token_login'), path('login/<slug:token>', views.login, name='token_login'),
path('logout', views.logout, name='token_logout'), path('logout', views.logout, name='token_logout'),
path('register', views.register, name='register'),
] ]

@ -2,6 +2,7 @@ from django.shortcuts import render, redirect, get_object_or_404
from .models import Shift, LoginToken, Helper from .models import Shift, LoginToken, Helper
import datetime import datetime
from django.db.models import F, Count from django.db.models import F, Count
from .forms import RegisterForm
def index(request): def index(request):
# dont show shifts starting in <60 minutes? # dont show shifts starting in <60 minutes?
@ -24,3 +25,22 @@ def login(request, token):
def logout(request): def logout(request):
del request.session['token'] del request.session['token']
return redirect('index') return redirect('index')
def register(request):
# handle number already being registered(resend message?)
if request.session.get('token'):
return redirect('index')
context = {}
if request.method == 'POST':
form = RegisterForm(request.POST)
if not form.is_valid():
context['form']=form
return render(request, 'register.html', context)
helper = Helper(name = form.cleaned_data['name'], phone=form.cleaned_data['phone'])
helper.save()
token = helper.send_confirmation()
request.session['token'] = token.pk
return render(request, 'wait_confirmation.html', {'helper':helper})
context['form']=RegisterForm()
return render(request, 'register.html', context)
Loading…
Cancel
Save