X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=django_simple%2Fauthentication%2Fviews.py;h=90dc326de2e2484cefc1b3d05ae7a4af7ada09f7;hb=c2827ea193aef2b1b7afb4c67ff9aa5751291fb2;hp=26019efc3fba0e5f14c32246dd598db0cc85a411;hpb=591ac48194b207c02ffd7cda59c1c9709a114498;p=django_unres.git diff --git a/django_simple/authentication/views.py b/django_simple/authentication/views.py index 26019ef..90dc326 100644 --- a/django_simple/authentication/views.py +++ b/django_simple/authentication/views.py @@ -1,7 +1,38 @@ -from django.contrib.auth import logout -from django.shortcuts import redirect - +from django.contrib.auth import authenticate, login, logout +from django.shortcuts import redirect, render +from django.contrib.auth.forms import AuthenticationForm +from django_simple.todo.models import Task +from lazysignup.decorators import allow_lazy_user +from .forms import * def logout_view(request): logout(request) - return redirect('/') \ No newline at end of file + return redirect('/') + +def login_view(request,authentication_form=AuthenticationForm): + username = password = '' + if request.POST: + username = request.POST['username'] + password = request.POST['password'] + + user = authenticate(username=username, password=password) + if user is not None: + if user.is_active: + login(request, user) + return redirect('/') + form = authentication_form(request) + return render(request, 'registration/login.html', {'form':form}) + +@allow_lazy_user +def add1(request,authentication_form=AuthenticationForm): + if request.method == 'POST': + form = TaskForm(request.POST) + if form.is_valid(): + name = form.cleaned_data["name"] + user = request.user + task = Task(name=name,owner=user,ready=False) + task.save() + return redirect('add_min',task_id=task.id) + form = authentication_form(request) + return render(request, 'registration/login.html', {'form':form}) +