Commit bad2d9fee69d536dab5d1bcd9e9ea96e8dec861f
1 parent
fc7e02f2
Exists in
master
and in
29 other branches
Captcha for comment reply and title is not mandatory for comment anymore
Showing
6 changed files
with
49 additions
and
35 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -119,7 +119,7 @@ class ContentViewerController < ApplicationController | @@ -119,7 +119,7 @@ class ContentViewerController < ApplicationController | ||
119 | def add_comment | 119 | def add_comment |
120 | @comment.author = user if logged_in? | 120 | @comment.author = user if logged_in? |
121 | @comment.article = @page | 121 | @comment.article = @page |
122 | - if (logged_in? || @comment.reply_of_id || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save | 122 | + if (logged_in? || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save |
123 | @page.touch | 123 | @page.touch |
124 | @comment = nil # clear the comment form | 124 | @comment = nil # clear the comment form |
125 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] | 125 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] |
app/models/comment.rb
@@ -2,7 +2,7 @@ class Comment < ActiveRecord::Base | @@ -2,7 +2,7 @@ class Comment < ActiveRecord::Base | ||
2 | 2 | ||
3 | track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"], :custom_target => :action_tracker_target | 3 | track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"], :custom_target => :action_tracker_target |
4 | 4 | ||
5 | - validates_presence_of :title, :body | 5 | + validates_presence_of :body |
6 | belongs_to :article, :counter_cache => true | 6 | belongs_to :article, :counter_cache => true |
7 | belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' | 7 | belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' |
8 | has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy | 8 | has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy |
app/views/content_viewer/_comment_form.rhtml
1 | +<script type="text/javascript"> | ||
2 | +function submit_comment_form(button) { | ||
3 | + <% if logged_in? %> | ||
4 | + button.form.confirm.value = 'true'; | ||
5 | + button.disabled = true; | ||
6 | + button.form.submit(); | ||
7 | + return true; | ||
8 | + <% else %> | ||
9 | + jQuery('#recaptcha-container').show(); | ||
10 | + jQuery.colorbox({ inline : true, href : '#recaptcha-container', maxWidth : '600px', maxHeight : '300px' }); | ||
11 | + jQuery('#confirm-captcha').unbind('click'); | ||
12 | + jQuery('#confirm-captcha').bind('click', function() { | ||
13 | + jQuery.colorbox.close(); | ||
14 | + button.form.recaptcha_response_field.value = jQuery('#recaptcha_response_field').val(); | ||
15 | + button.form.recaptcha_challenge_field.value = jQuery('#recaptcha_challenge_field').val(); | ||
16 | + button.form.confirm.value = 'true'; | ||
17 | + button.disabled = true; | ||
18 | + button.form.submit(); | ||
19 | + }); | ||
20 | + <% end %> | ||
21 | +} | ||
22 | +</script> | ||
23 | + | ||
1 | <% focus_on = logged_in? ? 'title' : 'name' %> | 24 | <% focus_on = logged_in? ? 'title' : 'name' %> |
2 | 25 | ||
3 | <% if @comment && @comment.errors.any? && @comment.reply_of_id.blank? %> | 26 | <% if @comment && @comment.errors.any? && @comment.reply_of_id.blank? %> |
@@ -19,6 +42,23 @@ | @@ -19,6 +42,23 @@ | ||
19 | <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> | 42 | <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> |
20 | </h4> | 43 | </h4> |
21 | 44 | ||
45 | +<% unless logged_in? %> | ||
46 | + <div id="recaptcha-container" style="display: none"> | ||
47 | + <h3><%= _('Please type the two words below') %></h3> | ||
48 | + <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) %> | ||
49 | + <% button_bar do %> | ||
50 | + <%= button_to_function :add, _('Confirm'), "return false", :id => "confirm-captcha" %> | ||
51 | + <%= button_to_function :cancel, _('Cancel'), "jQuery.colorbox.close()" %> | ||
52 | + <% end %> | ||
53 | + </div> | ||
54 | + | ||
55 | + <script type="text/javascript"> | ||
56 | + jQuery(document).bind('cbox_cleanup', function() { | ||
57 | + jQuery('#recaptcha-container').hide(); | ||
58 | + }); | ||
59 | + </script> | ||
60 | +<% end %> | ||
61 | + | ||
22 | <% form_tag( url_for(@page.view_url.merge({:only_path => true})), { :class => 'comment_form' } ) do %> | 62 | <% form_tag( url_for(@page.view_url.merge({:only_path => true})), { :class => 'comment_form' } ) do %> |
23 | <%= hidden_field_tag(:confirm, 'false') %> | 63 | <%= hidden_field_tag(:confirm, 'false') %> |
24 | 64 | ||
@@ -32,15 +72,16 @@ | @@ -32,15 +72,16 @@ | ||
32 | <%= _('If you are a registered user, you can login and be automatically recognized.') %> | 72 | <%= _('If you are a registered user, you can login and be automatically recognized.') %> |
33 | </p> | 73 | </p> |
34 | 74 | ||
75 | + <%= hidden_field_tag(:recaptcha_response_field, nil, :id => nil) %> | ||
76 | + <%= hidden_field_tag(:recaptcha_challenge_field, nil, :id => nil) %> | ||
77 | + | ||
35 | <% end %> | 78 | <% end %> |
36 | 79 | ||
37 | - <%= required labelled_form_field(_('Title'), text_field(:comment, :title)) %> | 80 | + <%= labelled_form_field(_('Title'), text_field(:comment, :title)) %> |
38 | <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %> | 81 | <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %> |
39 | 82 | ||
40 | - <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) unless logged_in? %> | ||
41 | - | ||
42 | <% button_bar do %> | 83 | <% button_bar do %> |
43 | - <%= submit_button('add', _('Post comment'), :onclick => "this.form.confirm.value = 'true'; this.disabled = true; this.form.submit(); return true;") %> | 84 | + <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %> |
44 | <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> | 85 | <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> |
45 | <% end %> | 86 | <% end %> |
46 | <% end %> | 87 | <% end %> |
public/javascripts/application.js
@@ -662,7 +662,6 @@ function add_comment_reply_form(button, comment_id) { | @@ -662,7 +662,6 @@ function add_comment_reply_form(button, comment_id) { | ||
662 | var f = container.find('.comment_form'); | 662 | var f = container.find('.comment_form'); |
663 | if (f.length == 0) { | 663 | if (f.length == 0) { |
664 | f = jQuery('#page-comment-form .comment_form').clone(); | 664 | f = jQuery('#page-comment-form .comment_form').clone(); |
665 | - f.find('#dynamic_recaptcha').remove(); | ||
666 | f.find('.fieldWithErrors').map(function() { jQuery(this).replaceWith(jQuery(this).contents()); }); | 665 | f.find('.fieldWithErrors').map(function() { jQuery(this).replaceWith(jQuery(this).contents()); }); |
667 | f.prepend('<input type="hidden" name="comment[reply_of_id]" value="' + comment_id + '" />'); | 666 | f.prepend('<input type="hidden" name="comment[reply_of_id]" value="' + comment_id + '" />'); |
668 | container.append(f); | 667 | container.append(f); |
public/stylesheets/application.css
@@ -6173,31 +6173,6 @@ h1#agenda-title { | @@ -6173,31 +6173,6 @@ h1#agenda-title { | ||
6173 | 6173 | ||
6174 | /* Captcha */ | 6174 | /* Captcha */ |
6175 | 6175 | ||
6176 | -.comment_reply #recaptcha_area { | ||
6177 | - margin-bottom: 3px !important; | ||
6178 | -} | ||
6179 | - | ||
6180 | -.comment_reply .recaptchatable tr td + td + td { | ||
6181 | - display: none !important; | ||
6182 | -} | ||
6183 | - | ||
6184 | -.comment_reply .recaptcha-container { | ||
6185 | - width: 100%; | ||
6186 | - overflow: hidden; | ||
6187 | -} | ||
6188 | - | ||
6189 | -.comment_reply .recaptcha-container:hover { | ||
6190 | - overflow: visible; | ||
6191 | -} | ||
6192 | - | ||
6193 | -.comment_reply .recaptcha-container tr:hover td { | ||
6194 | - background: transparent; | ||
6195 | -} | ||
6196 | - | ||
6197 | -.comment_reply .recaptcha_image_cell { | ||
6198 | - background: transparent !important; | ||
6199 | -} | ||
6200 | - | ||
6201 | /* Colorbox */ | 6176 | /* Colorbox */ |
6202 | 6177 | ||
6203 | #cboxClose { | 6178 | #cboxClose { |
test/unit/comment_test.rb
@@ -5,8 +5,8 @@ class CommentTest < Test::Unit::TestCase | @@ -5,8 +5,8 @@ class CommentTest < Test::Unit::TestCase | ||
5 | def setup | 5 | def setup |
6 | end | 6 | end |
7 | 7 | ||
8 | - should 'have a name and require it' do | ||
9 | - assert_mandatory(Comment.new, :title) | 8 | + should 'have a name but not require it' do |
9 | + assert_optional(Comment.new, :title) | ||
10 | end | 10 | end |
11 | 11 | ||
12 | should 'have a body and require it' do | 12 | should 'have a body and require it' do |
@@ -197,7 +197,6 @@ class CommentTest < Test::Unit::TestCase | @@ -197,7 +197,6 @@ class CommentTest < Test::Unit::TestCase | ||
197 | comment.valid? | 197 | comment.valid? |
198 | 198 | ||
199 | assert comment.errors.invalid?(:name) | 199 | assert comment.errors.invalid?(:name) |
200 | - assert comment.errors.invalid?(:title) | ||
201 | assert comment.errors.invalid?(:body) | 200 | assert comment.errors.invalid?(:body) |
202 | end | 201 | end |
203 | 202 |