Модель:
class User(models.Model):
username = models.CharField(maxlength=30)
password = models.CharField(maxlength=300)
mail = models.EmailField()
datereg = models.DateField()
# Avatar
def __str__(self):
return "%s %s %s %s" % (self.username, self.password, self.mail, self.datereg)
class Admin:
list_display = ('username', 'password', 'mail', 'datereg')
class Login(newforms.Form):
username = newforms.CharField(label=u'Имя')
password = newforms.CharField(label=u'Пароль', max_length=30)
def Index(request):
if request.method == 'POST':
form = Login(request.POST)
if form.is_valid():
usr = form.clean_data['username']
pwd = form.clean_data['password']
userbd = User.objects.filter(username=usr, password=pwd)
if userbd is not None:
user = auth.authenticate(username=usr, password=pwd)
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect('/%s/' % (usr))
else:
# пользователь не существует
pass
else:
form = Login()
return render_to_response('index.html', locals())