Skip to content

Commit

Permalink
update recaptcha usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonislawski committed Mar 14, 2018
1 parent af669e3 commit eda7526
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
4 changes: 3 additions & 1 deletion app/controllers/spree/admin/captcha_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module Spree
module Admin
class CaptchaSettingsController < BaseController
def update
Spree::Captcha::Config.set(params[:preferences])
params[:preferences].each do |key, value|
Spree::Captcha::Config.set_preference(key, value)
end

respond_to do |format|
format.html { redirect_to edit_admin_captcha_settings_path }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/email_sender_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def mail_to_friend
@mail_to_friend.host = request.env['HTTP_HOST']
respond_to do |format|
format.html do
captcha_passed = !Spree::Captcha::Config[:use_captcha] || verify_recaptcha(private_key: Spree::Captcha::Config[:private_key])
captcha_passed = !Spree::Captcha::Config[:use_captcha] || verify_recaptcha(secret_key: Spree::Captcha::Config[:secret_key])
if @mail_to_friend.valid? && captcha_passed
flash[:notice] = Spree.t('email_to_friend.mail_sent_to', email: @mail_to_friend.recipients.join(', '))

Expand Down
4 changes: 2 additions & 2 deletions app/models/spree/captcha_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class Spree::CaptchaConfiguration < Spree::Preferences::Configuration
THEMES = %w(red white blackglass clean custom)

# These keys works for localhost.
preference :private_key, :string, default: '6LfIsgEAAAAAAGfB6Z0lEUtdL3GVuBkRa9cYlMZz'
preference :public_key, :string, default: '6LfIsgEAAAAAALpT20eiC3RslZQmmCbiNS-AUvSe'
preference :secret_key, :string, default: '6LfIsgEAAAAAAGfB6Z0lEUtdL3GVuBkRa9cYlMZz'
preference :site_key, :string, default: '6LfIsgEAAAAAALpT20eiC3RslZQmmCbiNS-AUvSe'
preference :theme, :string, default: 'red'
preference :use_captcha, :boolean, default: true
end
12 changes: 6 additions & 6 deletions app/views/spree/admin/captcha_settings/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
</div>
</div>

<div data-hook="public_key" class="form-group">
<%= label_tag Spree.t('captcha.public_key') %>
<%= text_field_tag 'preferences[public_key]', Spree::Captcha::Config[:public_key], class: 'control-form' %>
<div data-hook="site_key" class="form-group">
<%= label_tag Spree.t('captcha.site_key') %>
<%= text_field_tag 'preferences[site_key]', Spree::Captcha::Config[:site_key], class: 'control-form' %>
</div>

<div data-hook="private_key" class="form-group">
<%= label_tag Spree.t('captcha.private_key') %>
<%= text_field_tag 'preferences[private_key]', Spree::Captcha::Config[:private_key], class: 'control-form' %>
<div data-hook="secret_key" class="form-group">
<%= label_tag Spree.t('captcha.secret_key') %>
<%= text_field_tag 'preferences[secret_key]', Spree::Captcha::Config[:secret_key], class: 'control-form' %>
</div>

<div data-hook="theme" class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/email_sender/send_mail.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<%= f.text_area(:message) %>
</p>
<% if Spree::Captcha::Config[:use_captcha] %>
<%= recaptcha_tags public_key: Spree::Captcha::Config[:public_key], display: { theme: Spree::Captcha::Config[:theme] } %>
<%= recaptcha_tags site_key: Spree::Captcha::Config[:site_key], display: { theme: Spree::Captcha::Config[:theme] } %>
<% end %>
<p>
<%= f.submit Spree.t('email_to_friend.send_message') %>
Expand Down
16 changes: 8 additions & 8 deletions spec/controllers/admin/captcha_settings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@

context 'For parameters:
theme: clean,
private_key: FAKE,
public_key: FAKE,
secret_key: FAKE,
site_key: FAKE,
use_captcha: false' do
it 'sets preferred_theme to clean' do
spree_put :update, preferences: { theme: 'clean' }
expect(Spree::Captcha::Config.preferred_theme).to eq 'clean'
end

it 'sets preferred_private_key to FAKE' do
spree_put :update, preferences: { private_key: 'FAKE' }
expect(Spree::Captcha::Config.preferred_private_key).to eq 'FAKE'
it 'sets preferred_secret_key to FAKE' do
spree_put :update, preferences: { secret_key: 'FAKE' }
expect(Spree::Captcha::Config.preferred_secret_key).to eq 'FAKE'
end

it 'sets preferred_public_key to FAKE' do
spree_put :update, preferences: { public_key: 'FAKE' }
expect(Spree::Captcha::Config.preferred_public_key).to eq 'FAKE'
it 'sets preferred_secret_key to FAKE' do
spree_put :update, preferences: { secret_key: 'FAKE' }
expect(Spree::Captcha::Config.preferred_secret_key).to eq 'FAKE'
end

it 'sets preferred_use_captcha to false' do
Expand Down

0 comments on commit eda7526

Please sign in to comment.