2013-08-14 23:05:53 +08:00
|
|
|
require_dependency 'screening_model'
|
|
|
|
|
|
|
|
# A ScreenedEmail record represents an email address that is being watched,
|
|
|
|
# typically when creating a new User account. If the email of the signup form
|
|
|
|
# (or some other form) matches a ScreenedEmail record, an action can be
|
|
|
|
# performed based on the action_type.
|
|
|
|
class ScreenedEmail < ActiveRecord::Base
|
|
|
|
|
|
|
|
include ScreeningModel
|
|
|
|
|
|
|
|
default_action :block
|
|
|
|
|
|
|
|
validates :email, presence: true, uniqueness: true
|
|
|
|
|
|
|
|
def self.block(email, opts={})
|
2013-08-23 07:04:17 +08:00
|
|
|
find_by_email(email) || create(opts.slice(:action_type, :ip_address).merge({email: email}))
|
2013-08-14 23:05:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.should_block?(email)
|
2014-05-06 21:41:59 +08:00
|
|
|
screened_email = ScreenedEmail.find_by(email: email)
|
2013-08-14 23:05:53 +08:00
|
|
|
screened_email.record_match! if screened_email
|
|
|
|
screened_email && screened_email.action_type == actions[:block]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-08-28 08:42:58 +08:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: screened_emails
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# email :string(255) not null
|
|
|
|
# action_type :integer not null
|
|
|
|
# match_count :integer default(0), not null
|
|
|
|
# last_match_at :datetime
|
2014-04-15 13:53:48 +08:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2013-12-05 14:40:35 +08:00
|
|
|
# ip_address :inet
|
2013-08-28 08:42:58 +08:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2014-04-15 13:53:48 +08:00
|
|
|
# index_blocked_emails_on_email (email) UNIQUE
|
|
|
|
# index_blocked_emails_on_last_match_at (last_match_at)
|
2013-08-28 08:42:58 +08:00
|
|
|
#
|