Skip to content

Commit

Permalink
Added captcha configuration stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
calas committed Oct 14, 2009
1 parent 4081045 commit 997bd52
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 33 deletions.
11 changes: 11 additions & 0 deletions app/controllers/admin/captcha_settings_controller.rb
@@ -0,0 +1,11 @@
class Admin::CaptchaSettingsController < Admin::BaseController
def update
Spree::Captcha::Config.set(params[:preferences])

respond_to do |format|
format.html {
redirect_to admin_captcha_settings_path
}
end
end
end
8 changes: 8 additions & 0 deletions app/models/captcha_configuration.rb
@@ -0,0 +1,8 @@
class CaptchaConfiguration < Configuration
THEMES = ['red', 'white', 'blackglass', 'clean', 'custom']

# this keys works for localhost
preference :private_key, :string, :default => '6LfIsgEAAAAAAGfB6Z0lEUtdL3GVuBkRa9cYlMZz'
preference :public_key, :string, :default => '6LfIsgEAAAAAALpT20eiC3RslZQmmCbiNS-AUvSe'
preference :theme, :string, :default => 'red'
end
22 changes: 22 additions & 0 deletions app/views/admin/captcha_settings/edit.html.erb
@@ -0,0 +1,22 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<h1><%= t("captcha.captcha_settings") %></h1>

<% form_tag(admin_captcha_settings_path, :method => :put) do -%>
<p>
<label><%= t("captcha.public_key") %>:</label>
<%= text_field_tag('preferences[public_key]', Spree::Captcha::Config[:public_key], :size => 40) %>
</p>
<p>
<label><%= t('captcha.private_key') %>:</label>
<%= text_field_tag('preferences[private_key]', Spree::Captcha::Config[:private_key], :size => 40)%>
</p>
<p>
<label><%= t('captcha.theme') %>:</label>
<%= select_tag('preferences[theme]', options_for_select(CaptchaConfiguration::THEMES, Spree::Captcha::Config[:theme])) %>
</p>
<p class="form-buttons">
<%= button t('update') %>
<%= t("or") %> <%= link_to t("cancel"), admin_captcha_settings_url %>
</p>
<% end -%>
22 changes: 22 additions & 0 deletions app/views/admin/captcha_settings/show.html.erb
@@ -0,0 +1,22 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<h1><%= t("captcha.captcha_settings") %></h1>

<table>
<tr>
<th scope="row"><%= t("captcha.public_key") %>:</th>
<td><%= Spree::Captcha::Config[:public_key] %></td>
</tr>
<tr>
<th scope="row"><%= t("captcha.private_key") %>:</th>
<td><%= Spree::Captcha::Config[:private_key] %></td>
</tr>
<tr>
<th scope="row"><%= t("captcha.theme") %>:</th>
<td><%= Spree::Captcha::Config[:theme] %></td>
</tr>
</table>

<p>
<%= link_to_with_icon('edit', t("edit"), edit_admin_captcha_settings_path) %>
</p>
5 changes: 1 addition & 4 deletions app/views/products/tell_a_friend.html.erb
Expand Up @@ -6,7 +6,6 @@
<%= f.label(:sender_name, t('email_to_friend.sender_name')) %><br/>
<%= f.text_field(:sender_name) %>
</p>

<p>
<%= f.label(:sender_email, t('email_to_friend.sender_email')) %><br/>
<%= f.text_field(:sender_email) %>
Expand All @@ -23,9 +22,7 @@
<%= f.label(:message, t('email_to_friend.message')) %><br/>
<%= f.text_area(:message) %>
</p>

<%= recaptcha_tags :public_key => Spree::Config[:recaptcha_public_key] %>

<%= recaptcha_tags :public_key => Spree::Captcha::Config[:public_key], :display => {:theme => Spree::Captcha::Config[:theme]} %>
<p>
<%= f.submit(t('email_to_friend.send_message')) %>
</p>
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en-US.yml
Expand Up @@ -12,3 +12,10 @@ en-US:
mail_sent_to: "Mail sent to {{email}} "
send_to_other: "Send to other friend"
you_would_like_this: "I think you would like this item"

captcha:
captcha_settings: "Captcha Settings"
public_key: "Public key"
private_key: "Private key"
manage_keys: "Manage your (re)captcha keys"
theme: "Theme"
6 changes: 6 additions & 0 deletions config/locales/es.yml
Expand Up @@ -12,3 +12,9 @@ es:
mail_sent_to: "Mensaje enviado a {{email}} "
send_to_other: "Enviar a otro amigo"
you_would_like_this: "Creo que este artículo te gustará"
captcha:
captcha_settings: "Configuracion de Captcha"
public_key: "Llave pública"
private_key: "Llave privada"
manage_keys: "Administrar tus llaves de recaptcha."
theme: "Tema"
6 changes: 3 additions & 3 deletions config/routes.rb
Expand Up @@ -2,6 +2,6 @@

map.resources :products, :member => { :tell_a_friend => :get, :mail_to_friend => :put }

# map.namespace :admin do |admin|
# admin.resources :whatever
# end
map.namespace :admin do |admin|
admin.resource :captcha_settings
end
35 changes: 10 additions & 25 deletions email_to_friend_extension.rb
Expand Up @@ -17,35 +17,20 @@ def self.require_gems(config)
end

def activate
AppConfiguration.class_eval do
# this keys works for localhost
preference :recaptcha_private_key, :string, :default => '6LfIsgEAAAAAAGfB6Z0lEUtdL3GVuBkRa9cYlMZz'
preference :recaptcha_public_key, :string, :default => '6LfIsgEAAAAAALpT20eiC3RslZQmmCbiNS-AUvSe'
end

ProductsController.class_eval do
include TellFriendActions
end

# Add your extension tab to the admin.
# Requires that you have defined an admin controller:
# app/controllers/admin/yourextension_controller
# and that you mapped your admin in config/routes
Admin::ConfigurationsController.class_eval do
before_filter :add_captcha_settings_links, :only => :index

#Admin::BaseController.class_eval do
# before_filter :add_yourextension_tab
#
# def add_yourextension_tab
# # add_extension_admin_tab takes an array containing the same arguments expected
# # by the tab helper method:
# # [ :extension_name, { :label => "Your Extension", :route => "/some/non/standard/route" } ]
# add_extension_admin_tab [ :yourextension ]
# end
#end

# make your helper avaliable in all views
# Spree::BaseController.class_eval do
# helper YourHelper
# end
def add_captcha_settings_links
@extension_links << {
:link => admin_captcha_settings_path,
:link_text => t('captcha.captcha_settings'),
:description => t('captcha.manage_keys')
}
end
end
end
end
10 changes: 10 additions & 0 deletions lib/spree/captcha/config.rb
@@ -0,0 +1,10 @@
module Spree::Captcha
class Config < Spree::Config
class << self
def instance
return nil unless ActiveRecord::Base.connection.tables.include?('configurations')
CaptchaConfiguration.find_or_create_by_name("Captcha configuration")
end
end
end
end
2 changes: 1 addition & 1 deletion lib/tell_friend_actions.rb
Expand Up @@ -13,7 +13,7 @@ def mail_to_friend
respond_to do |format|
format.html do
if @mail_to_friend.valid? &&
verify_recaptcha(:private_key => Spree::Config[:recaptcha_private_key])
verify_recaptcha(:private_key => Spree::Captcha::Config[:private_key])
flash[:notice] = I18n.t('email_to_friend.mail_sent_to', :email => @mail_to_friend.recipient_email)
flash[:notice] << @template.link_to(I18n.t('email_to_friend.send_to_other'),
tell_a_friend_product_path(@product))
Expand Down

0 comments on commit 997bd52

Please sign in to comment.