class PetitionSignator < ActiveRecord::Base
  belongs_to :petition
  attr_accessor :email_confirmation
  attr_accessible :address, :address2, :city, :enabled, :token, :country, :cp, :email, :email_confirmation, :firstname, :name, :petition_id
  
  validates :email, :presence => true, :confirmation => true, :uniqueness => { :scope => :petition_id }

  validates :name, :presence => true
  validates :firstname, :presence => true
  validates :address, :presence => true
  validates :cp, :presence => true
  validates :city, :presence => true
  validates :country, :presence => true
  
  before_create do
    self.token = (Digest::MD5.hexdigest "#{SecureRandom.hex(10)}-#{DateTime.now.to_s}")
  end

end
