Sha256: b67764b23b2d62e9e64a4453f224d2e8b5a2c781f70f7cb44ba4efd92c855bc2

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

module DoubleAuthEngine
  module UserMixin
    def self.included(base)
      base.class_eval do
        acts_as_authentic
        validates :email, :name, :presence => true
        has_many :assignments
        has_many :roles, :through => :assignments
      end
      base.send :extend, ClassMethods
      base.send :include, InstanceMethods
    end

    module ClassMethods
      def self.emails(query)
        (User.all(:select => "DISTINCT(email)",
                  :conditions => ["email LIKE ?", "%#{query}%"])).map(& :email).compact
      end
    end

    module InstanceMethods
      def email=(value)
        write_attribute :email, (value ? value.downcase : nil)
      end

      def deliver_password_reset_instructions!
        reset_perishable_token!
        Notifier.password_reset_instructions(self).deliver
      end

      def role_symbols
        roles.map do |role|
          role.name.underscore.to_sym
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
double_auth_engine-0.0.2 lib/double_auth_engine/models/user_mixin.rb
double_auth_engine-0.0.1 lib/double_auth_engine/models/user_mixin.rb