dock DockQ update 2
[django_unres.git] / django_simple / authentication / views.py
1 from django.contrib.auth import authenticate, login, logout
2 from django.shortcuts import redirect, render
3 from django.contrib.auth.forms import AuthenticationForm
4 from django_simple.todo.models import Task
5 from lazysignup.decorators import allow_lazy_user
6 from .forms import *
7
8 def logout_view(request):
9     logout(request)
10     return redirect('/')
11     
12 def login_view(request,authentication_form=AuthenticationForm):
13     username = password = ''
14     if request.POST:
15         username = request.POST['username']
16         password = request.POST['password']
17
18         user = authenticate(username=username, password=password)
19         if user is not None:
20             if user.is_active:
21                 login(request, user)
22                 return redirect('/')
23     form = authentication_form(request)
24     return render(request, 'registration/login.html', {'form':form})
25     
26 @allow_lazy_user
27 def add1(request,authentication_form=AuthenticationForm):
28     if request.method == 'POST':
29         form = TaskForm(request.POST)
30         if form.is_valid():
31             name = form.cleaned_data["name"]
32             user = request.user
33             task = Task(name=name,owner=user,ready=False)
34             task.save()
35             return redirect('add_min',task_id=task.id)
36     form = authentication_form(request)
37     return render(request, 'registration/login.html', {'form':form})
38