ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
936 B

  1. class ApplicationController < ActionController::API
  2. before_action :reject_banned_ip_address!
  3. before_action :authenticate_user
  4. before_action :reject_banned_user!
  5. def current_user = @current_user
  6. private
  7. def authenticate_user
  8. code = request.headers['X-Transfer-Code'] || request.headers['HTTP_X_TRANSFER_CODE']
  9. return if code.blank?
  10. @current_user = User.find_by(inheritance_code: code)
  11. end
  12. def bool? key, default: false
  13. return default if params[key].nil?
  14. s = params[key].to_s.strip.downcase
  15. if default
  16. !(s.in?(['0', 'false', 'off', 'no']))
  17. else
  18. s.in?(['', '1', 'true', 'on', 'yes'])
  19. end
  20. end
  21. def reject_banned_ip_address!
  22. ip_address = IpAddress.find_by(ip_address: IPAddr.new(request.remote_ip).hton)
  23. return unless ip_address&.banned?
  24. head :forbidden
  25. end
  26. def reject_banned_user!
  27. return unless current_user&.banned?
  28. head :forbidden
  29. end
  30. end