Skip to content

Commit cbe0ca4

Browse files
committed
implement recaptcha. its ugly as hell but it works and this way we can keep emailing
1 parent 13b49b1 commit cbe0ca4

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,4 @@ gem 'rack-attack'
147147
gem 'unf_ext', '0.0.6'
148148

149149
gem 'foreman'
150+
gem "recaptcha", :git => 'git://github.com/brendon/recaptcha.git', :ref => 'remove-ruby-restriction', require: "recaptcha/rails"

Gemfile.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ GIT
55
compass-rails (2.0.alpha.0)
66
compass (>= 0.12.2, < 0.14)
77

8+
GIT
9+
remote: git://github.com/brendon/recaptcha.git
10+
revision: 21473e536b93c0237ec02edcc78cf4f7a547a221
11+
ref: remove-ruby-restriction
12+
specs:
13+
recaptcha (1.3.0)
14+
json
15+
816
GIT
917
remote: git://github.com/chriseppstein/compass.git
1018
revision: 0a74e91931e53fb798323cd8684198c38a2b76b8
@@ -331,6 +339,7 @@ DEPENDENCIES
331339
rack-attack
332340
rails (= 3.2.22)
333341
rails-dev-boost!
342+
recaptcha!
334343
resque
335344
rspec
336345
rspec-rails
@@ -340,5 +349,8 @@ DEPENDENCIES
340349
unf_ext (= 0.0.6)
341350
unicorn
342351

352+
RUBY VERSION
353+
ruby 1.9.3p484
354+
343355
BUNDLED WITH
344-
1.11.2
356+
1.15.3

app/controllers/users_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class UsersController < Devise::RegistrationsController
22
before_filter :authenticate_user!, :except => [:auth]
3+
prepend_before_filter :check_captcha, only: [:create] # Change this to be any actions you want to protect.
34
respond_to :html, :json, :xml
45

56
# Overriding devise helpers
@@ -38,4 +39,13 @@ def update
3839
current_user.update_attributes(params[:user])
3940
render :text => "OK"
4041
end
42+
43+
private
44+
def check_captcha
45+
unless verify_recaptcha
46+
self.resource = resource_class.new sign_up_params
47+
respond_with_navigational(resource) { render :new }
48+
else
49+
end
50+
end
4151
end
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
<%= render 'devise/aio' %>
1+
<h2>Sign up</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4+
<%= devise_error_messages! %>
5+
<%= flash[:recaptcha_error] %>
6+
7+
<div><%= f.label :email %><br />
8+
<%= f.email_field :email, :autofocus => true %></div>
9+
10+
<div><%= f.label :password %><br />
11+
<%= f.password_field :password %></div>
12+
13+
<div>
14+
<%= recaptcha_tags(stoken: false, ajax: true) %>
15+
</div>
16+
<div><%= f.submit "Sign up" %></div>
17+
<% end %>

config/initializers/recaptcha.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Recaptcha.configure do |config|
2+
config.public_key = '6Lcg3SkUAAAAAO4yYqDriPdh-er7islVavz1m-X2'
3+
config.private_key = '6Lcg3SkUAAAAAEKwJT0Xy-U8XRC8_Qhc1w6FlZRv'
4+
end

0 commit comments

Comments
 (0)