verify captcha only when captcha keys present
This commit is contained in:
@@ -7,4 +7,9 @@ class ApplicationController < ActionController::Base
|
|||||||
# Prevent CSRF attacks by raising an exception.
|
# Prevent CSRF attacks by raising an exception.
|
||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
|
def verify_captcha?(resource)
|
||||||
|
return true unless recaptcha_keys?
|
||||||
|
verify_recaptcha(model: resource)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class DebatesController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@debate = Debate.new(debate_params)
|
@debate = Debate.new(debate_params)
|
||||||
@debate.author = current_user
|
@debate.author = current_user
|
||||||
if verify_captcha? and @debate.save
|
if verify_captcha?(@debate) and @debate.save
|
||||||
redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate')
|
redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate')
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
@@ -51,9 +51,4 @@ class DebatesController < ApplicationController
|
|||||||
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
|
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_captcha?
|
|
||||||
return true unless recaptcha_keys?
|
|
||||||
verify_recaptcha(model: @debate)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class RegistrationsController < Devise::RegistrationsController
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
|
include RecaptchaHelper
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if verify_recaptcha
|
if verify_captcha?(resource)
|
||||||
super
|
super
|
||||||
else
|
else
|
||||||
build_resource(sign_up_params)
|
build_resource(sign_up_params)
|
||||||
|
|||||||
Reference in New Issue
Block a user