add token login
This commit is contained in:
parent
bb81f69cb3
commit
5b98daba9a
|
@ -1,5 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
import secrets
|
import secrets
|
||||||
|
from django.shortcuts import reverse
|
||||||
|
|
||||||
class Room(models.Model):
|
class Room(models.Model):
|
||||||
name = models.CharField(max_length=200, primary_key=True)
|
name = models.CharField(max_length=200, primary_key=True)
|
||||||
|
@ -43,4 +44,6 @@ def gen_token():
|
||||||
|
|
||||||
class LoginToken(models.Model):
|
class LoginToken(models.Model):
|
||||||
id = models.CharField(max_length=20, primary_key=True, default=gen_token, editable=False)
|
id = models.CharField(max_length=20, primary_key=True, default=gen_token, editable=False)
|
||||||
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('token_login', kwargs={'token':self.id})
|
|
@ -5,6 +5,9 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
{% if helper%}
|
||||||
|
Hallo {{helper.name}}
|
||||||
|
{%endif%}
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,4 +4,5 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
|
path('login/<slug:token>', views.login, name='token_login'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from .models import Shift
|
from .models import Shift, LoginToken, Helper
|
||||||
import datetime
|
import datetime
|
||||||
from django.db.models import F, Count
|
from django.db.models import F, Count
|
||||||
|
|
||||||
|
@ -9,4 +9,14 @@ def index(request):
|
||||||
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
|
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
|
||||||
room__required_helpers__gt=F('reg_count')).order_by('start_at')
|
room__required_helpers__gt=F('reg_count')).order_by('start_at')
|
||||||
context = {'free_shifts': free_shifts}
|
context = {'free_shifts': free_shifts}
|
||||||
|
if request.session.get('token'):
|
||||||
|
context['helper'] = LoginToken.objects.get(pk=request.session['token']).helper
|
||||||
return render(request, 'shiftlist.html', context)
|
return render(request, 'shiftlist.html', context)
|
||||||
|
|
||||||
|
def login(request, token):
|
||||||
|
tk = get_object_or_404(LoginToken,pk=token)
|
||||||
|
if not tk.helper.number_validated:
|
||||||
|
tk.helper.number_validated=True
|
||||||
|
tk.helper.save()
|
||||||
|
request.session['token'] = token
|
||||||
|
return redirect('index')
|
Loading…
Reference in New Issue