1

在 Rails 应用程序中使用 authlogic,我想阻止来自某些 IP 地址的用户注册(因为滥用)。这样做的正确方法是什么?

4

1 回答 1

4
class SignupsController < ApplicationController
  before_filter :block_ip_addresses

  protected

  def block_ip_addresses
    head :unauthorized if current_ip_address == "XX.XX.XX.XX"
  end

  def current_ip_address
    request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
  end
end
于 2012-06-05T10:14:36.423 回答