dock DockQ update
[django_unres.git] / django_simple / authentication / views.py
index 26019ef..90dc326 100644 (file)
@@ -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})