diff --git a/templates/comments/list.html b/templates/comments/list.html index 685bd239c6..8388a00880 100644 --- a/templates/comments/list.html +++ b/templates/comments/list.html @@ -146,7 +146,7 @@

{{ _('New comment') }}

{{ _('You must solve at least one problem before your voice can be heard.') }} {% else %} -
+ {% csrf_token %} {% if comment_form.errors %}
diff --git a/templates/comments/media-js.html b/templates/comments/media-js.html index 200f339666..8bd96fd3d9 100644 --- a/templates/comments/media-js.html +++ b/templates/comments/media-js.html @@ -217,6 +217,16 @@ $comment.find('.comment-body').show(); $comment.find('.bad-comment-body').hide(); }; + + var code_regex = [/input\(/, /#include/, /void\s+main/, /fn\s+main/, /func\s+main/]; + $(document).on('click', 'form.comment-warn-code .button[type=submit]', function (e) { + var text = $(this).parents('form').find('#id_body').val(); + if (code_regex.some(function (regex) {return regex.test(text);})) { + if (!confirm({{ _('Looks like you\'re trying to post some source code!\n\nThe comment section is not for posting source code.\nIf you want to submit your solution, please use the "Submit solution" button.\n\nAre you sure you want to post this?')|htmltojs }})) { + e.preventDefault(); + } + } + }); }); {% endcompress %} diff --git a/templates/problem/problem.html b/templates/problem/problem.html index 7135717652..41f0cbefd1 100644 --- a/templates/problem/problem.html +++ b/templates/problem/problem.html @@ -343,7 +343,9 @@

{{ _('Clarifications') }}

{% endif %}
{% elif enable_comments %} - {% include "comments/list.html" %} + {% with comment_warn_code=true %} + {% include "comments/list.html" %} + {% endwith %} {% endif %} {% endblock %}