Make recaptcha optional on signup page.
This commit is contained in:
@@ -44,7 +44,7 @@ class UsersController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@user = User.new(params[:user], :as => CurrentUser.role)
|
@user = User.new(params[:user], :as => CurrentUser.role)
|
||||||
@user.last_ip_addr = request.remote_ip
|
@user.last_ip_addr = request.remote_ip
|
||||||
if verify_recaptcha(model: @user)
|
if !Danbooru.config.enable_recaptcha? || verify_recaptcha(model: @user)
|
||||||
@user.save
|
@user.save
|
||||||
if @user.errors.empty?
|
if @user.errors.empty?
|
||||||
session[:user_id] = @user.id
|
session[:user_id] = @user.id
|
||||||
|
|||||||
@@ -15,7 +15,11 @@
|
|||||||
<%= f.input :password %>
|
<%= f.input :password %>
|
||||||
<%= f.input :password_confirmation %>
|
<%= 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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -619,6 +619,18 @@ module Danbooru
|
|||||||
|
|
||||||
def aws_sqs_cropper_url
|
def aws_sqs_cropper_url
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class EnvironmentConfiguration
|
class EnvironmentConfiguration
|
||||||
|
|||||||
5
config/initializers/recaptcha.rb
Normal file
5
config/initializers/recaptcha.rb
Normal 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
|
||||||
@@ -76,11 +76,7 @@ class UsersControllerTest < ActionController::TestCase
|
|||||||
|
|
||||||
context "new action" do
|
context "new action" do
|
||||||
setup do
|
setup do
|
||||||
ENV["RECAPTCHA_SITE_KEY"] = "x"
|
Danbooru.config.stubs(:enable_recaptcha?).returns(false)
|
||||||
end
|
|
||||||
|
|
||||||
teardown do
|
|
||||||
ENV["RECAPTCHA_SITE_KEY"] = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render" do
|
should "render" do
|
||||||
|
|||||||
Reference in New Issue
Block a user