initial registration draft
This commit is contained in:
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)
|
||||
def __str__(self):
|
||||
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 Meta:
|
||||
|
@ -37,7 +43,7 @@ class Message(models.Model):
|
|||
text = models.CharField(max_length=160)
|
||||
to = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
||||
def __str__(self):
|
||||
return f"{to.name}: {text}"
|
||||
return f"{self.to.name}: {self.text}"
|
||||
|
||||
def gen_token():
|
||||
return secrets.token_urlsafe(20)
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
<body>
|
||||
{% if helper%}
|
||||
Hallo {{helper.name}}
|
||||
{%else%}
|
||||
<a href="{%url 'register'%}">Anmelden</a>
|
||||
{%endif%}
|
||||
<div id="content">
|
||||
{% 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('login/<slug:token>', views.login, name='token_login'),
|
||||
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
|
||||
import datetime
|
||||
from django.db.models import F, Count
|
||||
from .forms import RegisterForm
|
||||
|
||||
def index(request):
|
||||
# dont show shifts starting in <60 minutes?
|
||||
|
@ -23,4 +24,23 @@ def login(request, token):
|
|||
|
||||
def logout(request):
|
||||
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…
Reference in New Issue