Sha256: 54702c11104652024bcd29603b6e9a6d9ffce226a60cc3010c9e117b7be74e66

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 KB

Contents

include Kryptonite::ConfigHelper

$KRYPTONITE_USER_ACCESS_LEVEL_ADMIN = 0
$KRYPTONITE_USER_ACCESS_LEVEL_USER = 10

module Kryptonite
  class User < ActiveRecord::Base

	  def self.table_name
      self.to_s.gsub("::", "_").tableize
    end

    acts_as_authentic { |c| c.validate_email_field = false }
	 
    attr_accessor :notify_of_new_password
    
    attr_accessible :login, :name, :email, :time_zone, :access_level, :password, :password_confirmation
	 
    after_create :send_create_notification
    after_update :send_update_notification
    before_validation :check_time_zone
    
    validates_presence_of :login, :name, :email
    validates_uniqueness_of :login
    validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
    validates_presence_of :time_zone
	  
  	def self.has_more_than_one_admin
      Kryptonite::User.where(:access_level => $KRYPTONITE_USER_ACCESS_LEVEL_ADMIN).count > 1
    end
	
  	def send_create_notification
      Kryptonite::KryptoniteNotification.new_user_information(kryptonite_config_email_from_address, self, kryptonite_config_hostname, @password).deliver
    end
  
    def send_update_notification
      if notify_of_new_password
        notify_of_new_password = false
        Kryptonite::KryptoniteNotification.generate_new_password(kryptonite_config_email_from_address, self, kryptonite_config_hostname, @password).deliver
      end
    end
    
    def send_password_reset_instructions
      reset_perishable_token!
      Kryptonite::KryptoniteNotification.password_reset_instructions(kryptonite_config_email_from_address, self, kryptonite_config_hostname).deliver
    end
    
    def check_time_zone
      self.time_zone = Rails.configuration.time_zone unless self.time_zone
    end
	
  	def is_admin?
  	  access_level == $KRYPTONITE_USER_ACCESS_LEVEL_ADMIN
  	end
  
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kryptonite-0.0.9 app/models/kryptonite/user.rb
kryptonite-0.0.8 app/models/kryptonite/user.rb
kryptonite-0.0.7 app/models/kryptonite/user.rb
kryptonite-0.0.6 app/models/kryptonite/user.rb
kryptonite-0.0.5 app/models/kryptonite/user.rb
kryptonite-0.0.4 app/models/kryptonite/user.rb
kryptonite-0.0.3 app/models/kryptonite/user.rb
kryptonite-0.0.2 app/models/kryptonite/user.rb