Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Add CAPTCHA to Stripe payment processing #111

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'sidekiq'
gem 'skylight'
gem 'stripe', :source => 'https://code.stripe.com/'
gem 'uglifier', '>= 1.3.0'
gem 'simple_captcha2', require: 'simple_captcha'

group :development, :test do
gem 'foreman'
Expand Down
236 changes: 122 additions & 114 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,193 +2,200 @@ GEM
remote: https://rubygems.org/
remote: https://code.stripe.com/
specs:
actioncable (5.1.6)
actionpack (= 5.1.6)
actioncable (5.1.7)
actionpack (= 5.1.7)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
actionmailer (5.1.7)
actionpack (= 5.1.7)
actionview (= 5.1.7)
activejob (= 5.1.7)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.6)
actionview (= 5.1.6)
activesupport (= 5.1.6)
actionpack (5.1.7)
actionview (= 5.1.7)
activesupport (= 5.1.7)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.6)
activesupport (= 5.1.6)
actionview (5.1.7)
activesupport (= 5.1.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.6)
activesupport (= 5.1.6)
activejob (5.1.7)
activesupport (= 5.1.7)
globalid (>= 0.3.6)
activemodel (5.1.6)
activesupport (= 5.1.6)
activerecord (5.1.6)
activemodel (= 5.1.6)
activesupport (= 5.1.6)
activemodel (5.1.7)
activesupport (= 5.1.7)
activerecord (5.1.7)
activemodel (= 5.1.7)
activesupport (= 5.1.7)
arel (~> 8.0)
activesupport (5.1.6)
activesupport (5.1.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
ast (2.4.0)
autoprefixer-rails (7.1.6)
autoprefixer-rails (9.5.1.1)
execjs
binding_of_caller (0.7.3)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
builder (3.2.3)
coderay (1.1.2)
concurrent-ruby (1.0.5)
connection_pool (2.2.1)
concurrent-ruby (1.1.5)
connection_pool (2.2.2)
crass (1.0.4)
debug_inspector (0.0.3)
diff-lcs (1.3)
dotenv (2.2.1)
dotenv-rails (2.2.1)
dotenv (= 2.2.1)
railties (>= 3.2, < 5.2)
erubi (1.7.1)
dotenv (2.7.2)
dotenv-rails (2.7.2)
dotenv (= 2.7.2)
railties (>= 3.2, < 6.1)
erubi (1.8.0)
execjs (2.7.0)
factory_bot (4.10.0)
activesupport (>= 3.0.0)
factory_bot_rails (4.10.0)
factory_bot (~> 4.10.0)
railties (>= 3.0.0)
faraday (0.13.1)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.2)
factory_bot (~> 5.0.2)
railties (>= 4.2.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
ffi (1.9.25)
foreman (0.84.0)
ffi (1.11.1)
foreman (0.85.0)
thor (~> 0.19.1)
globalid (0.4.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
httparty (0.15.6)
httparty (0.17.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.1.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
jquery-rails (4.3.1)
jaro_winkler (1.5.2)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
loofah (2.2.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.9.0)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
mini_portile2 (2.4.0)
minitest (5.11.3)
multi_xml (0.6.0)
multipart-post (2.0.0)
multipart-post (2.1.1)
net-http-persistent (3.0.1)
connection_pool (~> 2.2)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.12.1)
parser (2.5.1.2)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
pg (0.21.0)
powerpack (0.1.2)
pry (0.11.2)
pg (1.1.4)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.0.5)
rack-protection (2.0.0)
rack (2.0.7)
rack-protection (2.0.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.1.6)
actioncable (= 5.1.6)
actionmailer (= 5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
activemodel (= 5.1.6)
activerecord (= 5.1.6)
activesupport (= 5.1.6)
rails (5.1.7)
actioncable (= 5.1.7)
actionmailer (= 5.1.7)
actionpack (= 5.1.7)
actionview (= 5.1.7)
activejob (= 5.1.7)
activemodel (= 5.1.7)
activerecord (= 5.1.7)
activesupport (= 5.1.7)
bundler (>= 1.3.0)
railties (= 5.1.6)
railties (= 5.1.7)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.1.6)
actionpack (= 5.1.6)
activesupport (= 5.1.6)
railties (5.1.7)
actionpack (= 5.1.7)
activesupport (= 5.1.7)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (12.3.1)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redis (4.0.1)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
redis (4.1.1)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-rails (3.7.1)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.58.2)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.70.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.0)
sass (3.5.3)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.6)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
secure_headers (5.0.1)
useragent (>= 0.15.0)
sentry-raven (2.7.1)
secure_headers (6.1.0)
sentry-raven (2.9.0)
faraday (>= 0.7.6, < 1.0)
shoulda-matchers (3.1.2)
activesupport (>= 4.0.0)
sidekiq (5.0.5)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
shoulda-matchers (4.0.1)
activesupport (>= 4.2.0)
sidekiq (5.2.7)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.4, < 5)
skylight (1.4.4)
activesupport (>= 3.0.0)
redis (>= 3.3.5, < 5)
simple_captcha2 (0.4.3)
rails (>= 4.1)
skylight (4.0.2)
skylight-core (= 4.0.2)
skylight-core (4.0.2)
activesupport (>= 4.2.0)
spring (2.0.2)
activesupport (>= 4.2)
sprockets (3.7.2)
Expand All @@ -198,17 +205,17 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stripe (3.8.0)
faraday (~> 0.10)
stripe (4.18.1)
faraday (~> 0.13)
net-http-persistent (~> 3.0)
thor (0.19.4)
thread_safe (0.3.6)
tilt (2.0.8)
tilt (2.0.9)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (3.2.0)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.0)
useragent (0.16.8)
unicode-display_width (1.6.0)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand Down Expand Up @@ -239,11 +246,12 @@ DEPENDENCIES
sentry-raven
shoulda-matchers
sidekiq
simple_captcha2
skylight
spring
stripe!
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.16.5
1.17.3
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ A really simple rails application to accept credit card donations for [Noisebrid
* PostgreSQL
* Ruby >= 2.4.0
* foreman `gem install foreman`
* ghostscript `apt-get install ghostscript`
* imagemagick `apt-get install imagemagick`

If you have `rbenv` and `ruby-build` installed you should be able to do the following
```bash
Expand Down
9 changes: 9 additions & 0 deletions app/assets/stylesheets/donation_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@
.input-group.custom-amount {
margin-top: 10px;
}

.simple_captcha {
width: 100%;
display: flex;
flex-direction: column;
border-radius: 5px;
align-items: center;
margin-bottom: 15px;
}
}
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

include SecureHeaders::ViewHelpers
include SimpleCaptcha::ControllerHelpers
end
6 changes: 6 additions & 0 deletions app/controllers/donations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def plan_params
end

def find_or_create_donor
unless simple_captcha_valid?
flash[:danger] = "Invalid CAPTCHA"
return redirect_to root_url
end


@donor = if Donor.exists?(email: donor_params[:email])
find_and_update_donor
else
Expand Down
Loading