Commit 60bd86cb authored by okhin's avatar okhin 🚴

Adding a captchas to the comment form

parent ce19fb6b
......@@ -131,6 +131,8 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.staticfiles',
'django_comments',
# Reduce the spam in comments
'spamlesscomment',
'tinymce',
'bt',
'captcha',
......@@ -149,6 +151,7 @@ INSTALLED_APPS = (
'bootstrap3',
)
COMMENTS_APP = 'spamlesscomment'
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
......
......@@ -741,6 +741,8 @@ input[type="text"], input[type="textarea"] {
clear: both;
}
div.honeypot {display: none;}
@media screen and (max-width: 700px) {
h1{font-size:30px}
h2{font-size:24px}
......@@ -763,3 +765,4 @@ input[type="text"], input[type="textarea"] {
width:100px;
}
}
......@@ -130,13 +130,13 @@ $("#btn_dismiss").click(function(event) {
<div class="well collapse" id="info-{{ violation.pk }}">
<form method="post" class="metoo" action="/confirm/{{ violation.pk }}" id="{{ violation.pk }}">
<div class="form-group form-inline">
<label for"email-{{ violation.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
<label for="email-{{ violation.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
{% csrf_token %}
<input type="email" id="email-{{ violation.pk }}" class="form-control" name="email" placeholder="Email"/>
<input type="hidden" id="id-{{ violation.pk }}" value="{{ violation.pk }}" />
<div class="btn-group" role="group" aria-label="confirm-deny">
<button class="btn btn-success">{% trans "OK" %}</ button>
<button data-toggle="collapse" data-target="#info-{{ violation.pk}}" aria-expanded="false" aria-controls="info-{{ volation.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
<button data-toggle="collapse" data-target="#info-{{ violation.pk}}" aria-expanded="false" aria-controls="info-{{ volation.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
</div>
</div>
</form>
......
......@@ -11,129 +11,120 @@
{% block scripts %}
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
function bindPostCommentHandler() {
$('.toggle').click(function(){
$(this).hide();
$(this).next().show();
});
$('#comment_form form input.submit-preview').remove();
$('#comment_form form').submit(function() {
var postdata=$('#comment_form form').serialize()+'&csrftoken={{csrf_token}}';
$.ajax({
type: "POST",
data: postdata,
url: "{% comment_form_target %}",
cache: false,
dataType: "html",
success: function(html, textStatus) {
$('#comment_form form').replaceWith(html+" "+"{% trans 'It will appear here after moderation.' %}");
bindPostCommentHandler();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$('#comment_form form').replaceWith("{% trans 'Your comment was unable to be posted at this time. We apologise for the inconvenience.' %}");
}
});
return false;
});
}
$(document).ready(function() {
bindPostCommentHandler();
$('.confirm_form').submit(function() {
var self=this;
var email=$(this).children('input:first').attr('value');
if( email.length>0) {
$.ajax({url: '/confirm/'+$(this).attr('id')+'/'+email, success: function(data) { $(self).html(data); }});
} else {
console.log($(this).find('[type=submit]'));
$(this).find('[type=text]').focus();
}
return false;
});
$('span').hover(function(){$('span#'+this.id+'_tooltip').fadeIn();}, function(){$('span#'+this.id+'_tooltip').hide();});
$('.metoo').submit(function(event) {
event.preventDefault();
var form = $(this);
var pk = $(form).attr("id")
var email = $(form).find("#email-" + pk).val();
$.ajax({
url: "/confirm/" + pk + "/" + email,
success: function(data) {
form.find("div").html(data);
}
});
});
});
</script>
{% endblock %}
{%block content%}
<div id='global'>
<h2>{{v.operator}} ({{v.country}}) {{v.contract}}</h2>
<div id="report">
<div id="icons">
<span id="verified_tooltip" class="tooltip">{% trans "This case was verified by the management team" %}</span>
<span class="tooltip_on">{%if v.confirmations == 0 %} {% trans "Nobody has yet confirmed the case. Feel free to do it" %} {%else%} {{v.confirmations}} {%if v.confirmations == 1 %} {% trans "person has confirmed this case" %} {%else%} {% trans "persons have confirmed this case" %} {%endif%} {%endif%}</span>
{% if v.state == 'verified' %}<span id="verified"></span> |{% endif %}
<span id="confirmations">{{v.confirmations}}</span> |
</div>
<h2>{{v.operator}} ({{v.country}}) {{v.contract}}</h2>
<div id="report">
<div id="icons">
<span id="verified_tooltip" class="tooltip">{% trans "This case was verified by the management team" %}</span>
<span class="tooltip_on">{%if v.confirmations == 0 %} {% trans "Nobody has yet confirmed the case. Feel free to do it" %} {%else%} {{v.confirmations}} {%if v.confirmations == 1 %} {% trans "person has confirmed this case" %} {%else%} {% trans "people have confirmed this case" %} {%endif%} {%endif%}</span>
{% if v.state == 'verified' %}<span id="verified"></span> |{% endif %}
<span id="confirmations">{{v.confirmations}}</span> |
</div>
<dl>{%if v.resource_name%}<dt>{% trans "Affected resource" %}</dt><dd>{{v.resource_name}}</dd>{%endif%}
{%if v.type%}<dt>{% trans "Type" %}</dt><dd>{{v.type|type}}</dd>{%endif%}
{%if v.media%}<dt>{% trans "Media" %}</dt><dd>{{v.media|media}}</dd>{%endif%}
{%if v.state%}<dt>{% trans "Status" %}</dt><dd>{{v.state|status}}</dd>{%endif%}
{%if v.temporary%}<dt>{% trans "Temporary restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.loophole%}<dt>{% trans "Another offer provided by the same operator removes this restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.contractual%}<dt>{% trans "Contractual restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.contract_excerpt%}<dt>{% trans "Contract excerpt" %}</dt><dd class='text'>{{v.contract_excerpt|safe}}</dd>{%endif%}
{%if v.comment_set.all%}</dl>
</div>
<dl>{%if v.resource_name%}<dt>{% trans "Affected resource" %}</dt><dd>{{v.resource_name}}</dd>{%endif%}
{%if v.type%}<dt>{% trans "Type" %}</dt><dd>{{v.type|type}}</dd>{%endif%}
{%if v.media%}<dt>{% trans "Media" %}</dt><dd>{{v.media|media}}</dd>{%endif%}
{%if v.state%}<dt>{% trans "Status" %}</dt><dd>{{v.state|status}}</dd>{%endif%}
{%if v.temporary%}<dt>{% trans "Temporary restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.loophole%}<dt>{% trans "Another offer provided by the same operator removes this restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.contractual%}<dt>{% trans "Contractual restriction" %}</dt><dd>{% trans "yes" %}</dd>{%endif%}
{%if v.contract_excerpt%}<dt>{% trans "Contract excerpt" %}</dt><dd class='text'>{{v.contract_excerpt|safe}}</dd>{%endif%}
{%if v.comment_set.all%}</dl>
</div>
{% if v.editorial %}
<div id="editorial" class='round-box'>
<h3>{% trans "RespectMyNet note" %}</h3>
{{v.editorial|safe}}
</div>
{% endif %}
{% if v.editorial %}
<div id="editorial" class='round-box'>
<h3>{% trans "RespectMyNet note" %}</h3>
{{v.editorial|safe}}
</div>
{% endif %}
<div id="description" class='round-box'>
<h3>{%trans "Description" %}</h3>
{%for c in v.comment_set.all%}
<div class="description-node">
{%if c.attachment_set.all%}
<div class="attachs">
<h4>{% trans "Attachments" %}</h4>
<ul>
{%for a in c.attachment_set.all%}
<li><a href="{% url 'attach' a.id %}">{{a.name}}</a></li>
{%endfor%}
</ul>
</div>
{%endif%}
<div class="description">{{c.comment|safe}}</div>
<span class="submitter">{%if c.submitter_name%}{{c.submitter_name}}{%else%}{{c.submitter_email}}{%endif%}</span> - <span class="comment_date">{{c.timestamp|date:"SHORT_DATE_FORMAT" }}</span>
</div>
{%endfor%}
</div>
<div id="description" class='round-box'>
<h3>{%trans "Description" %}</h3>
{%for c in v.comment_set.all%}
<div class="description-node">
{%if c.attachment_set.all%}
<div class="attachs">
<h4>{% trans "Attachments" %}</h4>
<ul>
{%for a in c.attachment_set.all%}
<li><a href="{% url 'attach' a.id %}">{{a.name}}</a></li>
{%endfor%}
</ul>
</div>
{%endif%}
<div class="description">{{c.comment|safe}}</div>
<span class="submitter">{%if c.submitter_name%}{{c.submitter_name}}{%else%}{{c.submitter_email}}{%endif%}</span> - <span class="comment_date">{{c.timestamp|date:"SHORT_DATE_FORMAT" }}</span>
</div>
{%endfor%}
</div>
<h3>{%trans "This restriction affects me too" %}</h3>
<div class="info-validate" style="display: inline-block;">
<form method="get" id="{{ v.pk }}" class="confirm_form" >
<label>{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
<input type="text" name="email" />
<input type="hidden" value="{{ v.pk }}" />
<input type="submit" value="{% trans "Me too!" %}" />
</form>
</div>
{%endif%}
{% if not key %}
<div id="comments">
<h3>{% trans "Comments" %}</h3>
{% get_comment_list for v as cmt_list %}
{% for comment in cmt_list %}
<div class="comment">
<p>{{ comment.user_name }} - {{ comment.submit_date }}</p>
<p>{{ comment.comment|striptags|urlize|linebreaks }}</p>
</div>
{% endfor %}
<div class="toggle button">{% trans "Add comment" %}</div>
<div id="comment_form" style="display: none;">
{% render_comment_form for v %}
</div>
{% else %}
<br />
<a class="button" href='/moderate/?key={{key}}&action=approve'>{% trans "Approve Submission" %}</a>
<a class="button" href='/moderate/?key={{key}}&action=delete'>{% trans "Delete Submission" %}</a>
</div>
{% endif %}
</div>
<div>
<button type="button" class="btn btn-link" data-toggle="collapse" data-target="#info-{{ v.pk }}">
<h3>{%trans "This restriction affects me too" %}</h3>
</button>
</div>
<div class="well collapse" id="info-{{ v.pk }}">
<form method="post" id="{{ v.pk }}" class="metoo" action="/confirm/{{ v.pk }}">
<div class="form-group">
<label for="email-{{ v.pk }}">{% trans "In order to <strong>confirm</strong> this report, please enter your email address" %}</label>
{% csrf_token %}
<input type="email" id="email-{{ v.pk }}" name="email" placeholder="Email" />
<input type="hidden" id="id-{{ v.pk }}" value="{{ v.pk }}" />
</div>
<div class="btn-group" role="group" aria-label="confirm-deny">
<button class="btn btn-success">{% trans "OK" %}</button>
<button data-toggle="collapse" data-target="#info-{{ v.pk}}" aria-expanded="false" aria-controls="info-{{ v.pk }}" type="button" class="btn btn-danger" >{% trans "Cancel" %}</button>
</div>
</form>
</div>
{%endif%}
{% if not key %}
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">{% trans "Comments" %}</h1>
</div>
{% get_comment_list for v as cmt_list %}
<div class="panel-body">
<ul class="list-group">
{% for comment in cmt_list %}
<li class="list-group-item">
<p>{{ comment.user_name }} - {{ comment.submit_date }}</p>
<p>{{ comment.comment|striptags|urlize|linebreaks }}</p>
</li>
{% endfor %}
</ul>
</div>
<div class="panel-footer">
<div id="comment_form">
{% render_comment_form for v %}
</div>
</div>
{% else %}
<br />
<a class="btn btn-success" href='/moderate/?key={{key}}&action=approve'>{% trans "Approve Submission" %}</a>
<a class="btn btn-error" href='/moderate/?key={{key}}&action=delete'>{% trans "Delete Submission" %}</a>
</div>
{% endif %}
</div>
{%endblock%}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment