Add reCAPTCHA support to registration.
Because I *hate* spam bots.
This commit is contained in:
parent
464b148321
commit
a7fce677fc
6 changed files with 52 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
|||
class RegistrationsController < Devise::RegistrationsController
|
||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||
prepend_before_action :check_captcha, only: [:create]
|
||||
|
||||
def edit
|
||||
@openids = Openid.where(user_id: current_user.id).order(:provider)
|
||||
|
|
@ -21,14 +21,35 @@ class RegistrationsController < Devise::RegistrationsController
|
|||
edit_user_registration_path(resource)
|
||||
end
|
||||
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.permit(:account_update) do |u|
|
||||
u
|
||||
.permit(:email, :password, :password_confirmation, :current_password, :username, :email_public)
|
||||
end
|
||||
devise_parameter_sanitizer.permit(:sign_up) do |u|
|
||||
u
|
||||
.permit(:email, :password, :password_confirmation, :name, :username)
|
||||
private
|
||||
|
||||
def sign_up_params
|
||||
params.require(:user).permit(
|
||||
:email,
|
||||
:password,
|
||||
:password_confirmation,
|
||||
:name,
|
||||
:username
|
||||
)
|
||||
end
|
||||
|
||||
def account_update_params
|
||||
params.require(:user).permit(
|
||||
:email,
|
||||
:password,
|
||||
:password_confirmation,
|
||||
:current_password,
|
||||
:username,
|
||||
:email_public
|
||||
)
|
||||
end
|
||||
|
||||
def check_captcha
|
||||
unless verify_recaptcha
|
||||
self.resource = resource_class.new sign_up_params
|
||||
resource.validate # Look for any other validation errors besides Recaptcha
|
||||
respond_with_navigational(resource) { render :new }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue