Am trying to build an application that user can login to register using pin and serial number from a scratch card, a valid pin and serial number should take a user to the registration page to create an account, here are codes i have writen
view.py
def index(request, template_name="index.html"):
errors=[]
if request.method == "POST":
form = PinForm()
if form.is_valid():
#form.save()
#form.cleaned_data
pin1 = request.POST.get('pin', '')
serial_no1 = request.POST.get('serial_no', '')
accept = auth.authenticate(pin=pin1, serial_no=serial_no1)
if accept is not None and accept.is_active:
# Correct password, and the user is marked "active"
auth.login(request, accept)
# Redirect to a success page.
return HttpResponseRedirect('/acceptance/')
else:
form = PinForm()
#accept = authenticate(pin != pin, serial_no !=serial_no, is_valid = False )
#errors.append('This card Does Not Exist')
# form = PinForm()
return render_to_response(template_name, locals(),context_instance = RequestContext(request))
def acceptance(request, template_name = "acceptance.html"):
return render_to_response(template_name, locals(),context_instance = RequestContext(request))
form.py
from django import forms
from you.models import Pin
class PinForm(forms.ModelForm):
class Meta:
model = Pin
exclude = ('is_active',)
urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('you.views',
(r'^$','index', {'template_name': 'index.html'}, 'home_page'),
#(r'^acceptance/$',{'template_name': 'acceptance.html'}, 'acceptance'),
(r'^acceptance/$', 'acceptance', {'template_name': 'acceptance.html'}, 'acceptance'),
and
models.py
from django.db import models
from django.forms import ModelForm
class Pin(models.Model):
pin = models.CharField(max_length=12)
serial_no = models.CharField(max_length=12)
is_active = models.BooleanField(default=True)
class Meta:
db_table = 'db_Pin'
ordering = ['pin']
def __unicode__(self):
return self.pin
In the model i have actually stored the pin and serial no, but each time i entered a valid pin and serial number it does not redirect to the next page which for now
is the acceptance page, this i intend to change to the registration page. pls what have i not done right, pls help me fix this. thanks