Commit 5e1be3e43901afa6fa4e71d968c198bb1ca92cf5
1 parent
e7c62647
Exists in
master
and in
28 other branches
ActionItem537: added captcha to signup
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2160 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
16 additions
and
1 deletions
Show diff stats
app/controllers/public/account_controller.rb
1 | class AccountController < PublicController | 1 | class AccountController < PublicController |
2 | 2 | ||
3 | + inverse_captcha :field => 'e_mail' | ||
4 | + | ||
3 | # say something nice, you goof! something sweet. | 5 | # say something nice, you goof! something sweet. |
4 | def index | 6 | def index |
5 | unless logged_in? | 7 | unless logged_in? |
@@ -39,7 +41,7 @@ class AccountController < PublicController | @@ -39,7 +41,7 @@ class AccountController < PublicController | ||
39 | @user = User.new(params[:user]) | 41 | @user = User.new(params[:user]) |
40 | @user.terms_of_use = environment.terms_of_use | 42 | @user.terms_of_use = environment.terms_of_use |
41 | @terms_of_use = environment.terms_of_use | 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 | @user.save! | 45 | @user.save! |
44 | @user.person.environment = environment | 46 | @user.person.environment = environment |
45 | @user.person.save! | 47 | @user.person.save! |
app/views/account/signup.rhtml
@@ -24,6 +24,8 @@ | @@ -24,6 +24,8 @@ | ||
24 | :help => help=_('We need to be sure that you wrote correctly your password.') %> | 24 | :help => help=_('We need to be sure that you wrote correctly your password.') %> |
25 | <small><%= help %></small> | 25 | <small><%= help %></small> |
26 | 26 | ||
27 | +<%= icaptcha_field() %> | ||
28 | + | ||
27 | <% if @terms_of_use %> | 29 | <% if @terms_of_use %> |
28 | <p> | 30 | <p> |
29 | <%= @terms_of_use %> | 31 | <%= @terms_of_use %> |
test/functional/account_controller_test.rb
@@ -400,6 +400,17 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -400,6 +400,17 @@ class AccountControllerTest < Test::Unit::TestCase | ||
400 | 400 | ||
401 | end | 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 | protected | 414 | protected |
404 | def create_user(options = {}, extra_options ={}) | 415 | def create_user(options = {}, extra_options ={}) |
405 | post :signup, { :user => { :login => 'quire', | 416 | post :signup, { :user => { :login => 'quire', |