Add anti robot tip

This commit is contained in:
Grégory Soutadé 2012-11-08 21:36:21 +01:00
parent 85488e0838
commit 4e9737297f
3 changed files with 16 additions and 5 deletions

View File

@ -23,7 +23,7 @@
</dyn:comments>
<dyn:replace div_name="form" id="response_0" method="POST" action="http://dynastie.soutade.fr/comment/add/dyn:post_id/0" onsubmit="return validateComment(response_0');">
Auteur :<br/><input type="text" name="author"/><br/><br/>
e-mail* :<br/><input type="text" name="email"/><br/><br/>
e-mail* :<br/><input id="email" type="text" name="email"/><input type="text" name="mel"/><br/><br/>
Le commentaire :<br/><textarea name="the_comment" cols="80" rows="10"> </textarea><br/><br/>
<input type="submit" value="Commenter"/><br/><br/>
* Seulement pour être notifié d'une réponse à cet article

View File

@ -374,3 +374,8 @@ ul li
{
margin-left:10px;
}
#email
{
display:none;
}

View File

@ -561,6 +561,11 @@ def add_comment(request, post_id, parent_id):
ref = request.META['HTTP_REFERER']
# Anti robot !!
if request.POST['email'] != '':
print 'fucking robot'
return HttpResponseRedirect(ref)
post = Post.objects.get(pk=post_id)
if post is None:
print 'no post'
@ -576,6 +581,7 @@ def add_comment(request, post_id, parent_id):
if parent_id != 0:
parentComment = Comment.objects.get(pk=parent_id)
if parentComment is None:
print 'no parent'
return HttpResponseRedirect(ref)
else:
parentComment = None
@ -597,7 +603,7 @@ def add_comment(request, post_id, parent_id):
the_comment = the_comment.replace('>', '&gt;')
comment = Comment(post=post, parent=parentComment, date=datetime.now(), author=request.POST['author'].strip(),\
email=request.POST['email'].strip(), the_comment=the_comment, ip=ip)
email=request.POST['mel'].strip(), the_comment=the_comment, ip=ip)
comment.save()
engine = globals()['post']
@ -617,7 +623,7 @@ def add_comment(request, post_id, parent_id):
comment_index = str(len(comments))
for comment in comments:
email = comment.email
if email != '' and email != request.POST['email'] and not email in emails:
if email != '' and email != request.POST['mel'] and not email in emails:
emails[email] = comment.author
@ -656,8 +662,8 @@ def add_comment(request, post_id, parent_id):
response['Expires'] = 'Thu, 01 Jan 1970 00:00:00 GMT'
response.set_cookie('author', request.POST['author'], domain=blog.name, secure=True, httponly=False);
if request.POST['email'] != '':
response.set_cookie('email', request.POST['email'], domain=blog.name, secure=True, httponly=False);
if request.POST['mel'] != '':
response.set_cookie('email', request.POST['mel'], domain=blog.name, secure=True, httponly=False);
return response