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