From 0ebd57811d43846f9eccb669f1472ef96f8a62d8 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 30 Oct 2024 18:03:23 -0300 Subject: [PATCH] feat: prueba de antispam --- app/controllers/registrations_controller.rb | 20 ++++++++++++++++++++ app/views/devise/registrations/new.haml | 3 +++ config/routes.rb | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/controllers/registrations_controller.rb diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 00000000..353d0c17 --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# Modificaciones locales al registro de usuaries +# +# @see {https://github.com/heartcombo/devise/wiki/How-To:-Use-Recaptcha-with-Devise} +class RegistrationsController < Devise::RegistrationsController + class SpambotError < StandardError; end + + prepend_before_action :anti_spambot_traps, only: %i[create] + + private + + # Detecta spambots simples + def anti_spambot_traps + raise SpambotError if params.dig(:usuarie, :name).blank? + rescue SpambotError => e + ExceptionNotifier.notify_exception(e, data: { params: params }) + nil + end +end diff --git a/app/views/devise/registrations/new.haml b/app/views/devise/registrations/new.haml index cc08c630..99a969a1 100644 --- a/app/views/devise/registrations/new.haml +++ b/app/views/devise/registrations/new.haml @@ -12,6 +12,9 @@ as: resource_name, url: registration_path(resource_name, params: { locale: params[:locale] })) do |f| + .d-none + = f.text_field :name, autocomplete: 'off' + .form-group = f.label :email, class: 'sr-only' = f.email_field :email, autofocus: true, autocomplete: 'email', diff --git a/config/routes.rb b/config/routes.rb index 110641e2..416eaa68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Rails.application.routes.draw do - devise_for :usuaries + devise_for :usuaries, controllers: { registrations: 'registrations' } get '/.well-known/change-password', to: redirect('/usuaries/edit') require 'que/web'