mirror of
https://github.com/neocities/neocities.git
synced 2025-04-28 11:12:30 +02:00
Add captcha for signup
This commit is contained in:
parent
a4c31d4618
commit
5164914c4e
6 changed files with 29 additions and 4 deletions
1
Gemfile
1
Gemfile
|
@ -9,6 +9,7 @@ gem 'sinatra-flash', require: 'sinatra/flash'
|
||||||
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
|
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
|
||||||
gem 'puma', require: nil
|
gem 'puma', require: nil
|
||||||
gem 'rubyzip'
|
gem 'rubyzip'
|
||||||
|
gem 'rack-recaptcha', require: 'rack/recaptcha'
|
||||||
|
|
||||||
platform :mri do
|
platform :mri do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
|
@ -21,6 +21,7 @@ GEM
|
||||||
hashie (2.0.5)
|
hashie (2.0.5)
|
||||||
hiredis (0.4.5)
|
hiredis (0.4.5)
|
||||||
i18n (0.6.4)
|
i18n (0.6.4)
|
||||||
|
json (1.8.0)
|
||||||
kgio (2.8.0)
|
kgio (2.8.0)
|
||||||
magic (0.2.6)
|
magic (0.2.6)
|
||||||
ffi (>= 0.6.3)
|
ffi (>= 0.6.3)
|
||||||
|
@ -51,6 +52,8 @@ GEM
|
||||||
rack (1.5.2)
|
rack (1.5.2)
|
||||||
rack-protection (1.5.0)
|
rack-protection (1.5.0)
|
||||||
rack
|
rack
|
||||||
|
rack-recaptcha (0.6.6)
|
||||||
|
json
|
||||||
rack-test (0.6.2)
|
rack-test (0.6.2)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
rainbows (4.5.0)
|
rainbows (4.5.0)
|
||||||
|
@ -112,6 +115,7 @@ DEPENDENCIES
|
||||||
pry
|
pry
|
||||||
pry-debugger
|
pry-debugger
|
||||||
puma
|
puma
|
||||||
|
rack-recaptcha
|
||||||
rack-test
|
rack-test
|
||||||
rainbows
|
rainbows
|
||||||
rake
|
rake
|
||||||
|
|
9
app.rb
9
app.rb
|
@ -5,6 +5,9 @@ use Rack::Session::Cookie, key: 'neocities',
|
||||||
expire_after: 31556926, # one year in seconds
|
expire_after: 31556926, # one year in seconds
|
||||||
secret: $config['session_secret']
|
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
|
get %r{.+} do
|
||||||
pass if request.host == '127.0.0.1'
|
pass if request.host == '127.0.0.1'
|
||||||
subname = request.host.match /[\w-]+/
|
subname = request.host.match /[\w-]+/
|
||||||
|
@ -50,7 +53,9 @@ post '/create' do
|
||||||
dashboard_if_signed_in
|
dashboard_if_signed_in
|
||||||
@site = Site.new username: params[:username], password: params[:password], email: params[:email], new_tags: params[:tags]
|
@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
|
base_path = site_base_path @site.username
|
||||||
|
|
||||||
|
@ -69,6 +74,8 @@ post '/create' do
|
||||||
session[:id] = @site.id
|
session[:id] = @site.id
|
||||||
redirect '/dashboard'
|
redirect '/dashboard'
|
||||||
else
|
else
|
||||||
|
@site.errors.add :captcha, 'You must type in the two words correctly! Try again.' if !recaptcha_is_valid
|
||||||
|
|
||||||
slim :'/new'
|
slim :'/new'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
development:
|
development:
|
||||||
database: 'postgres://localhost/neocities'
|
database: 'postgres://localhost/neocities'
|
||||||
session_secret: SETSOMETHINGHERE
|
session_secret: SETSOMETHINGHERE
|
||||||
|
recaptcha_public_key: ddsfsdfsdf
|
||||||
|
recaptcha_private_key: fsdgfdsdfd
|
|
@ -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 {
|
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;
|
color: #000000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
|
||||||
|
javascript:
|
||||||
|
var RecaptchaOptions = {
|
||||||
|
theme : 'clean'
|
||||||
|
};
|
||||||
|
|
||||||
- if !@site.errors.empty?
|
- if !@site.errors.empty?
|
||||||
.row
|
.row
|
||||||
.span8.offset2
|
.span8.offset2
|
||||||
|
@ -54,10 +59,16 @@
|
||||||
p: input name="tags" type="text" style="width: 400px" placeholder="pokemon, video games, bulbasaur" value="#{params[:tags]}"
|
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
|
.row
|
||||||
.span6
|
.span6
|
||||||
h3 You're done. Just click the button below!
|
h3 You're done. Just click the button below!
|
||||||
|
|
||||||
.row style="margin-top: 30px"
|
.row style="margin-top: 10px"
|
||||||
.span3.offset1
|
.span3.offset1
|
||||||
input.btn.btn-success.btn-large type="submit" value="Create Home Page"
|
input.btn.btn-success.btn-large type="submit" value="Create Home Page"
|
Loading…
Add table
Reference in a new issue