Commit 4dfaa51dab30d07efa0d357ce226e761e6345988

Authored by Ábner Silva de Oliveira
Committed by Victor Costa
1 parent 1e0cc2a4

Add captcha checking to forgot_password action

app/controllers/public/account_controller.rb
... ... @@ -189,6 +189,11 @@ class AccountController < ApplicationController
189 189  
190 190 if request.post?
191 191 begin
  192 + unless verify_recaptcha
  193 + @change_password.errors.add(:base, _('Please type the words correctly'))
  194 + return false
  195 + end
  196 +
192 197 requestors = fetch_requestors(params[:value])
193 198 raise ActiveRecord::RecordNotFound if requestors.blank? || params[:value].blank?
194 199  
... ...
app/views/account/forgot_password.html.erb
... ... @@ -5,6 +5,9 @@
5 5 <%= form_tag do %>
6 6 <%= labelled_form_field fields_label, text_field_tag(:value) %>
7 7  
  8 + <h3><%= _('Please type the two words below') %></h3>
  9 + <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) %>
  10 +
8 11 <div>
9 12 <% button_bar do %>
10 13 <%= submit_button('send', _('Send instructions')) %>
... ...
test/functional/account_controller_test.rb
... ... @@ -232,6 +232,16 @@ class AccountControllerTest &lt; ActionController::TestCase
232 232 assert_template 'password_recovery_sent'
233 233 end
234 234  
  235 + should 'not respond to forgotten password change if captcha verification fails' do
  236 + create_user('test')
  237 + @controller.stubs(:verify_recaptcha).returns(false)
  238 + post :forgot_password, :value => 'test'
  239 + change = assigns(:change_password)
  240 + assert change.errors.has_key?(:base)
  241 + assert_response :success
  242 + assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation', :class => 'errorExplanation' }
  243 + end
  244 +
235 245 should 'respond to forgotten password change request with email' do
236 246 change = ChangePassword.new
237 247 create_user('test', :email => 'test@localhost.localdomain')
... ...