2024-10-30 21:03:23 +00:00
|
|
|
# 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
|
|
|
|
|
2024-10-31 14:17:21 +00:00
|
|
|
# Condiciones bajo las que consideramos que un registro viene de unx
|
|
|
|
# spambot
|
|
|
|
#
|
|
|
|
# @return [Bool]
|
|
|
|
def spambot?
|
|
|
|
@spambot ||= params.dig(:usuarie, :name).present?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Detecta e informa spambots muy simples
|
|
|
|
#
|
|
|
|
# @return [nil]
|
2024-10-30 21:03:23 +00:00
|
|
|
def anti_spambot_traps
|
2024-10-31 14:17:21 +00:00
|
|
|
raise SpambotError if spambot?
|
2024-10-30 21:03:23 +00:00
|
|
|
rescue SpambotError => e
|
2024-10-31 14:17:21 +00:00
|
|
|
ExceptionNotifier.notify_exception(e, data: { params: anonymized_params })
|
2024-10-30 21:03:23 +00:00
|
|
|
nil
|
|
|
|
end
|
2024-10-31 14:17:21 +00:00
|
|
|
|
|
|
|
# Devuelve parámetros anonimizados para prevenir filtrar la contraseña
|
|
|
|
# de falsos positivos.
|
|
|
|
#
|
|
|
|
# @return [Hash]
|
|
|
|
def anonymized_params
|
|
|
|
params.except(:authenticity_token).permit!.to_h.tap do |p|
|
|
|
|
p['usuarie'].delete 'password'
|
|
|
|
p['usuarie'].delete 'password_confirmation'
|
|
|
|
end
|
|
|
|
end
|
2024-10-30 21:03:23 +00:00
|
|
|
end
|