Make recaptcha optional on signup page.

This commit is contained in:
evazion 2017-11-28 22:37:02 -06:00
parent 2000719227
commit 8d8a2f9c1e
5 changed files with 24 additions and 7 deletions

View File

@ -44,7 +44,7 @@ class UsersController < ApplicationController
def create
@user = User.new(params[:user], :as => CurrentUser.role)
@user.last_ip_addr = request.remote_ip
if verify_recaptcha(model: @user)
if !Danbooru.config.enable_recaptcha? || verify_recaptcha(model: @user)
@user.save
if @user.errors.empty?
session[:user_id] = @user.id

View File

@ -15,7 +15,11 @@
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= invisible_recaptcha_tags callback: 'submitInvisibleRecaptchaForm', text: 'Sign up' %>
<% if Danbooru.config.enable_recaptcha? %>
<%= invisible_recaptcha_tags callback: 'submitInvisibleRecaptchaForm', text: 'Sign up' %>
<% else %>
<%= f.submit "Sign up", :data => { :disable_with => "Signing up..." } %>
<% end %>
<% end %>
</div>
</div>

View File

@ -619,6 +619,18 @@ module Danbooru
def aws_sqs_cropper_url
end
# Use a recaptcha on the signup page to protect against spambots creating new accounts.
# https://developers.google.com/recaptcha/intro
def enable_recaptcha?
Rails.env.production? && Danbooru.config.recaptcha_site_key.present? && Danbooru.config.recaptcha_secret_key.present?
end
def recaptcha_site_key
end
def recaptcha_secret_key
end
end
class EnvironmentConfiguration

View File

@ -0,0 +1,5 @@
Recaptcha.configure do |config|
config.site_key = Danbooru.config.recaptcha_site_key
config.secret_key = Danbooru.config.recaptcha_secret_key
# config.proxy = "http://example.com"
end

View File

@ -76,11 +76,7 @@ class UsersControllerTest < ActionController::TestCase
context "new action" do
setup do
ENV["RECAPTCHA_SITE_KEY"] = "x"
end
teardown do
ENV["RECAPTCHA_SITE_KEY"] = nil
Danbooru.config.stubs(:enable_recaptcha?).returns(false)
end
should "render" do