Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth import authenticate, login
- from django.core.urlresolvers import reverse
- from django import forms
- from django.http import HttpResponseRedirect, HttpResponse
- from django.shortcuts import render_to_response
- from django.template import RequestContext
- def login(request):
- if request.method == 'POST':
- form = ContactForm(request.POST)
- if form.is_valid():
- login(request, form.user)
- return HttpResponseRedirect ('/main/') # redirect after post
- else:
- form = ContactForm() # unbound form
- return render_to_response (
- "login.html", {'form' : form, }, context_instance=RequestContext(request))
- def main_page(request):
- return HttpResponse("WOOHOO")
- class ContactForm(forms.Form):
- username = forms.CharField(max_length=100)
- password = forms.CharField(widget=forms.PasswordInput(render_value=False))
- def clean(self):
- user = self.user
- if user and user.is_active:
- return self.cleaned_data
- raise forms.ValidationError("Username and password do not match")
- @property
- def user(self):
- return authenticate(
- username=self.cleaned_data.get("username"),
- password=self.cleaned_data.get("password"))
Add Comment
Please, Sign In to add comment