Commit 5e1be3e43901afa6fa4e71d968c198bb1ca92cf5

Authored by JoenioCosta
1 parent e7c62647

ActionItem537: added captcha to signup

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2160 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/account_controller.rb
1 1 class AccountController < PublicController
2 2  
  3 + inverse_captcha :field => 'e_mail'
  4 +
3 5 # say something nice, you goof! something sweet.
4 6 def index
5 7 unless logged_in?
... ... @@ -39,7 +41,7 @@ class AccountController &lt; PublicController
39 41 @user = User.new(params[:user])
40 42 @user.terms_of_use = environment.terms_of_use
41 43 @terms_of_use = environment.terms_of_use
42   - if request.post? && answer_correct
  44 + if request.post? && params[self.icaptcha_field].blank? && answer_correct
43 45 @user.save!
44 46 @user.person.environment = environment
45 47 @user.person.save!
... ...
app/views/account/signup.rhtml
... ... @@ -24,6 +24,8 @@
24 24 :help => help=_('We need to be sure that you wrote correctly your password.') %>
25 25 <small><%= help %></small>
26 26  
  27 +<%= icaptcha_field() %>
  28 +
27 29 <% if @terms_of_use %>
28 30 <p>
29 31 <%= @terms_of_use %>
... ...
test/functional/account_controller_test.rb
... ... @@ -400,6 +400,17 @@ class AccountControllerTest &lt; Test::Unit::TestCase
400 400  
401 401 end
402 402  
  403 + should 'not be able to signup while inverse captcha field filled' do
  404 + assert_no_difference User, :count do
  405 + create_user({}, @controller.icaptcha_field => 'bli@bla.email.foo')
  406 + end
  407 + end
  408 +
  409 + should 'render inverse captcha field' do
  410 + get :signup
  411 + assert_tag :tag => 'input', :attributes => { :type => 'text', :name => @controller.icaptcha_field }
  412 + end
  413 +
403 414 protected
404 415 def create_user(options = {}, extra_options ={})
405 416 post :signup, { :user => { :login => 'quire',
... ...