Commit 4dfaa51dab30d07efa0d357ce226e761e6345988
Committed by
Victor Costa
1 parent
1e0cc2a4
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Add captcha checking to forgot_password action
Showing
3 changed files
with
18 additions
and
0 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -189,6 +189,11 @@ class AccountController < ApplicationController | @@ -189,6 +189,11 @@ class AccountController < ApplicationController | ||
189 | 189 | ||
190 | if request.post? | 190 | if request.post? |
191 | begin | 191 | begin |
192 | + unless verify_recaptcha | ||
193 | + @change_password.errors.add(:base, _('Please type the words correctly')) | ||
194 | + return false | ||
195 | + end | ||
196 | + | ||
192 | requestors = fetch_requestors(params[:value]) | 197 | requestors = fetch_requestors(params[:value]) |
193 | raise ActiveRecord::RecordNotFound if requestors.blank? || params[:value].blank? | 198 | raise ActiveRecord::RecordNotFound if requestors.blank? || params[:value].blank? |
194 | 199 |
app/views/account/forgot_password.html.erb
@@ -5,6 +5,9 @@ | @@ -5,6 +5,9 @@ | ||
5 | <%= form_tag do %> | 5 | <%= form_tag do %> |
6 | <%= labelled_form_field fields_label, text_field_tag(:value) %> | 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 | <div> | 11 | <div> |
9 | <% button_bar do %> | 12 | <% button_bar do %> |
10 | <%= submit_button('send', _('Send instructions')) %> | 13 | <%= submit_button('send', _('Send instructions')) %> |
test/functional/account_controller_test.rb
@@ -232,6 +232,16 @@ class AccountControllerTest < ActionController::TestCase | @@ -232,6 +232,16 @@ class AccountControllerTest < ActionController::TestCase | ||
232 | assert_template 'password_recovery_sent' | 232 | assert_template 'password_recovery_sent' |
233 | end | 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 | should 'respond to forgotten password change request with email' do | 245 | should 'respond to forgotten password change request with email' do |
236 | change = ChangePassword.new | 246 | change = ChangePassword.new |
237 | create_user('test', :email => 'test@localhost.localdomain') | 247 | create_user('test', :email => 'test@localhost.localdomain') |