Sha256: cac8bcf46e732decfac0fc190c75deef68895d3340c6e8a21fa5931488f4745a

Contents?: true

Size: 901 Bytes

Versions: 28

Compression:

Stored size: 901 Bytes

Contents

module NotifyUser
  class UserHash < ActiveRecord::Base
    self.table_name = "notify_user_user_hashes"

    # The user to send the notification to
    belongs_to :target, polymorphic: true

    validates_presence_of :target_id, :target_type, :target, :type

    before_create :generate_token

    self.inheritance_column = :_type_disabled

    if Rails.version.to_i < 4
      attr_accessible :target, :type, :active
    end

    def self.confirm_hash(token, type)
      return NotifyUser::UserHash.exists?(token: token, type: type, active: true)
    end

    def deactivate
      self.active = false
      save
    end

    private
    def generate_token
      self.token = loop do
        random_token = SecureRandom.urlsafe_base64(nil, false) + SecureRandom.urlsafe_base64(nil, false)
        break random_token unless NotifyUser::UserHash.exists?(token: random_token)
      end
    end

  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
notify_user-0.3.2 app/models/notify_user/user_hash.rb
notify_user-0.3.1 app/models/notify_user/user_hash.rb
notify_user-0.1.4 app/models/notify_user/user_hash.rb
notify_user-0.1.3 app/models/notify_user/user_hash.rb
notify_user-0.1.2 app/models/notify_user/user_hash.rb
notify_user-0.1.1 app/models/notify_user/user_hash.rb
notify_user-0.0.30 app/models/notify_user/user_hash.rb
notify_user-0.0.29 app/models/notify_user/user_hash.rb
notify_user-0.0.28 app/models/notify_user/user_hash.rb
notify_user-0.0.27 app/models/notify_user/user_hash.rb
notify_user-0.0.26 app/models/notify_user/user_hash.rb
notify_user-0.0.25 app/models/notify_user/user_hash.rb
notify_user-0.0.24 app/models/notify_user/user_hash.rb
notify_user-0.0.23 app/models/notify_user/user_hash.rb
notify_user-0.0.22 app/models/notify_user/user_hash.rb
notify_user-0.0.20 app/models/notify_user/user_hash.rb
notify_user-0.0.19 app/models/notify_user/user_hash.rb
notify_user-0.0.18 app/models/notify_user/user_hash.rb
notify_user-0.0.16 app/models/notify_user/user_hash.rb
notify_user-0.0.15 app/models/notify_user/user_hash.rb