Sha256: 64a0d8660a24a9f1807fc74bb046f5180384f89bb87cc50873fc29db2302cc3c

Contents?: true

Size: 826 Bytes

Versions: 4

Compression:

Stored size: 826 Bytes

Contents

module Devise
  module Models
    module Pinfirmable
      extend ActiveSupport::Concern

      included do
        before_create :generate_confirmation_token, unless: "skip_pinfirmation?"
        after_commit :send_confirmation_instructions, on: :create
      end

      def confirm
        update_attribute(:pinfirmable_pin, nil)
      end

      def skip_pinfirmation!
        @skip_pinfirmation = true
      end

      protected

      def generate_confirmation_token
        pin = ""
        6.times { pin << SecureRandom.random_number(9).to_s }
        self.pinfirmable_pin = pin
      end

      def send_confirmation_instructions
        PinfirmableMailer.pin_email(self).deliver unless @skip_pinfirmation
      end

      private

      def skip_pinfirmation?
        !!@skip_pinfirmation
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pinfirmable-0.1.5 lib/pinfirmable/models/pinfirmable.rb
pinfirmable-0.1.4 lib/pinfirmable/models/pinfirmable.rb
pinfirmable-0.1.3 lib/pinfirmable/models/pinfirmable.rb
pinfirmable-0.1.2 lib/pinfirmable/models/pinfirmable.rb