sdi/views.py
branchanoop
changeset 67 b9690fbf78af
parent 65 0ca63c964237
child 70 58cafee2ee89
--- a/sdi/views.py	Mon Jun 07 15:30:03 2010 +0530
+++ b/sdi/views.py	Mon Jun 07 15:39:33 2010 +0530
@@ -2,8 +2,10 @@
 from django.http import HttpResponse
 from django.contrib.auth.decorators import login_required
 
+from django.contrib.auth import authenticate, login, logout
+
 from sage_days.sdi.models import Registrant
-from sage_days.sdi.forms import RegisterForm, SearchForm, EmailForm
+from sage_days.sdi.forms import RegisterForm, SearchForm, EmailForm, LoginForm
 from sage_days.sdi.events import send_reg_complete_mail, mail_invi
 
 def register(request):
@@ -99,7 +101,33 @@
         form = EmailForm()
         return render_to_response("send_invi.html", {"form":form})
 
+def admin_login(request):
+    """ basic login.
+    """
 
+    if request.method == "POST":
+        form = LoginForm(request.POST)
+        if form.is_valid():
+            data = form.cleaned_data()
+
+            username = data['username']
+            password = data['password']
+
+            user = authenticate(username=username, password=password)
+            login(request, user)
+            return redirect("/registration/stats")
+        else:
+            return render_to_response("login.html", {"form":form})
+    else:
+        form = LoginForm()
+        return render_to_response("login.html", {"form":form})
+
+def admin_logout(request):
+    """ simply logout.
+    """
+
+    logout(request)
+    return render_to_response("logout.html")
 
 def homepage(request):
         return render_to_response("index.html")