Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.http import HttpResponse, HttpResponseRedirect, Http404
- from django.shortcuts import render_to_response
- from django.template import RequestContext
- from django.contrib import auth
- def index(request):
- return render_to_response('index.html', {}, context_instance = RequestContext(request))
- def login(request):
- if request.method == "POST":
- post = request.POST.copy()
- if post.has_key('username') and post.has_key('password'):
- usr = post['username']
- pwd = post['password']
- user = auth.authenticate(username=usr, password=pwd)
- if user is not None and user.is_active:
- auth.login(request, user)
- if user.get_profile().is_teacher:
- return HttpResponseRedirect('/teachers/'+user.username+'/')
- else:
- return HttpResponseRedirect('/students/'+user.username+'/')
- else:
- return render_to_response('index.html', {'msg': 'You don't belong here.'}, context_instance = RequestContext(request))
- return render_to_response('login.html', {}, context_instance = RequestContext(request))
- def logout(request):
- auth.logout(request)
- return render_to_response('index.html', {}, context_instance = RequestContext(request))
Add Comment
Please, Sign In to add comment