Add captcha for signup

This commit is contained in:
Kyle Drake 2013-06-16 11:44:18 -07:00
parent a4c31d4618
commit 5164914c4e
6 changed files with 29 additions and 4 deletions

View file

@ -9,6 +9,7 @@ gem 'sinatra-flash', require: 'sinatra/flash'
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
gem 'puma', require: nil
gem 'rubyzip'
gem 'rack-recaptcha', require: 'rack/recaptcha'
platform :mri do
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic

View file

@ -21,6 +21,7 @@ GEM
hashie (2.0.5)
hiredis (0.4.5)
i18n (0.6.4)
json (1.8.0)
kgio (2.8.0)
magic (0.2.6)
ffi (>= 0.6.3)
@ -51,6 +52,8 @@ GEM
rack (1.5.2)
rack-protection (1.5.0)
rack
rack-recaptcha (0.6.6)
json
rack-test (0.6.2)
rack (>= 1.0)
rainbows (4.5.0)
@ -112,6 +115,7 @@ DEPENDENCIES
pry
pry-debugger
puma
rack-recaptcha
rack-test
rainbows
rake

9
app.rb
View file

@ -5,6 +5,9 @@ use Rack::Session::Cookie, key: 'neocities',
expire_after: 31556926, # one year in seconds
secret: $config['session_secret']
use Rack::Recaptcha, public_key: $config['recaptcha_public_key'], private_key: $config['recaptcha_private_key']
helpers Rack::Recaptcha::Helpers
get %r{.+} do
pass if request.host == '127.0.0.1'
subname = request.host.match /[\w-]+/
@ -50,7 +53,9 @@ post '/create' do
dashboard_if_signed_in
@site = Site.new username: params[:username], password: params[:password], email: params[:email], new_tags: params[:tags]
if @site.valid?
recaptcha_is_valid = recaptcha_valid?
if @site.valid? && recaptcha_is_valid
base_path = site_base_path @site.username
@ -69,6 +74,8 @@ post '/create' do
session[:id] = @site.id
redirect '/dashboard'
else
@site.errors.add :captcha, 'You must type in the two words correctly! Try again.' if !recaptcha_is_valid
slim :'/new'
end
end

View file

@ -1,3 +1,5 @@
development:
database: 'postgres://localhost/neocities'
session_secret: SETSOMETHINGHERE
session_secret: SETSOMETHINGHERE
recaptcha_public_key: ddsfsdfsdf
recaptcha_private_key: fsdgfdsdfd

View file

@ -21,4 +21,4 @@ textarea, input[type="text"], input[type="password"], input[type="datetime"], in
select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
color: #000000;
}
}

View file

@ -1,4 +1,9 @@
javascript:
var RecaptchaOptions = {
theme : 'clean'
};
- if !@site.errors.empty?
.row
.span8.offset2
@ -54,10 +59,16 @@
p: input name="tags" type="text" style="width: 400px" placeholder="pokemon, video games, bulbasaur" value="#{params[:tags]}"
.row
.span6
p Last thing! Enter these two words correctly (with spaces) so we know you're not a robot (don't worry robots, we still love you).
div
== recaptcha_tag :challenge
.row
.span6
h3 You're done. Just click the button below!
.row style="margin-top: 30px"
.row style="margin-top: 10px"
.span3.offset1
input.btn.btn-success.btn-large type="submit" value="Create Home Page"