Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth import authenticate, login
- from django import forms
- from django.http import HttpResponseRedirect, HttpResponse
- from django.shortcuts import render_to_response
- from django.template import RequestContext
- class ContactForm(forms.Form):
- username = forms.CharField(max_length=100)
- password = forms.CharField(widget=forms.PasswordInput(render_value=False))
- def clean(self):
- if self.user is None:
- raise forms.ValidationError("Username and password do not match")
- return self.cleaned_data
- @property
- def user(self):
- user = authenticate(
- username=self.cleaned_data.get("username"),
- password=self.cleaned_data.get("password"))
- if user and user.is_active:
- return user
- def login(request):
- if request.method == 'POST':
- form = ContactForm(request.POST)
- if form.is_valid():
- login(request, form.user)
- return HttpResponseRedirect ('/main/')
- else:
- form = ContactForm()
- return render_to_response (
- "login.html", {'form' : form}, context_instance=RequestContext(request))
- def main_page(request):
- # dude, this shouldn't be in login.py, why bother creating separate files for your views
- # if you're just going to poo them anywhere at random? ;-p
- return HttpResponse("WOOHOO")
Add Comment
Please, Sign In to add comment