Skip to content

Commit

Permalink
Merge pull request #404 from alphagov/prevent-disposable-email-addresses
Browse files Browse the repository at this point in the history
Prevent the use of disposable email addresses for signing
  • Loading branch information
alanth committed Oct 21, 2015
2 parents 572c7f8 + 046113e commit 5a768ef
Show file tree
Hide file tree
Showing 8 changed files with 1,200 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/models/staged/base/creator_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class CreatorSignature
def initialize(petition)
@petition = petition
end
delegate :id, :to_param, :model_name, :to_key,
:name, :email, :uk_citizenship,
:postcode, :country, :constituency,
to: :creator_signature

delegate :id, :to_param, :model_name, :to_key, :name,
:email, :email?, :uk_citizenship, :postcode,
:country, :constituency, to: :creator_signature

def validation_context
:create
Expand Down
6 changes: 3 additions & 3 deletions app/models/staged/base/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class Signature

attr_reader :signature

delegate :id, :to_param, :model_name, :to_key, :new_record?, :name,
:email, :uk_citizenship, :postcode, :country, :petition_id,
to: :signature
delegate :id, :to_param, :model_name, :to_key, :new_record?,
:name, :email, :email?, :uk_citizenship, :postcode,
:country, :petition_id, to: :signature

def initialize(signature)
@signature = signature
Expand Down
24 changes: 24 additions & 0 deletions app/models/staged/validations/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ module Email

included do
validates :email, presence: true, format: { with: EMAIL_REGEX, allow_blank: true }

validate do
errors.add :email, :disposable if disposable_domain?
end
end

private

def disposable_domain?
return false unless email?

begin
disposable_domains.include?(parsed_email.domain)
rescue Mail::Field::ParseError
false
end
end

def parsed_email
Mail::Address.new(email)
end

def disposable_domains
Rails.application.config.x.disposable_domains
end
end
end
Expand Down
Loading

0 comments on commit 5a768ef

Please sign in to comment.