heartcombo--devise/lib/devise.rb

150 lines
4.3 KiB
Ruby
Raw Normal View History

module Devise
ALL = [:authenticatable, :confirmable, :recoverable, :rememberable,
2009-11-24 17:29:46 +00:00
:timeoutable, :trackable, :validatable].freeze
# Maps controller names to devise modules
CONTROLLERS = {
:sessions => :authenticatable,
:passwords => :recoverable,
:confirmations => :confirmable
}.freeze
2009-10-20 10:44:21 +00:00
STRATEGIES = [:authenticatable].freeze
2009-11-15 02:13:43 +00:00
SERIALIZERS = [:authenticatable, :rememberable].freeze
2009-10-20 10:44:21 +00:00
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
# Maps the messages types that are used in flash message. This array is not
# frozen, so you can add messages from your own strategies.
FLASH_MESSAGES = [ :unauthenticated, :unconfirmed, :invalid, :timeout ]
2009-11-10 20:55:13 +00:00
# Declare encryptors length which are used in migrations.
ENCRYPTORS_LENGTH = {
:sha1 => 40,
:sha512 => 128,
:clearance_sha1 => 40,
:restful_authentication_sha1 => 40,
:authlogic_sha512 => 128
}
# Used to encrypt password. Please generate one with rake secret.
mattr_accessor :pepper
@@pepper = nil
# The number of times to encrypt password.
mattr_accessor :stretches
@@stretches = 10
2009-11-15 05:31:13 +00:00
# Keys used when authenticating an user.
mattr_accessor :authentication_keys
@@authentication_keys = [ :email ]
# Time interval where the remember me token is valid.
mattr_accessor :remember_for
@@remember_for = 2.weeks
# Time interval you can access your account before confirming your account.
mattr_accessor :confirm_within
@@confirm_within = 0.days
# Time interval to timeout the user session without activity.
mattr_accessor :timeout_in
@@timeout_in = 30.minutes
2009-11-10 20:55:13 +00:00
# Used to define the password encryption algorithm.
mattr_accessor :encryptor
@@encryptor = :sha1
2009-11-10 20:55:13 +00:00
# Store scopes mappings.
mattr_accessor :mappings
@@mappings = {}
2009-11-14 00:33:00 +00:00
# Stores the chosen ORM.
mattr_accessor :orm
2009-11-14 00:33:00 +00:00
@@orm = :active_record
# Configure default options used in :all.
mattr_accessor :all
@@all = Devise::ALL.dup
# Tells if devise should apply the schema in ORMs where devise declaration
# and schema belongs to the same class (as Datamapper and MongoMapper).
mattr_accessor :apply_schema
@@apply_schema = true
# Scoped views. Since it relies on fallbacks to render default views, it's
# turned off by default.
mattr_accessor :scoped_views
@@scoped_views = false
class << self
# Default way to setup Devise. Run script/generate devise_install to create
# a fresh initializer with all configuration values.
def setup
yield self
end
# Sets the sender in DeviseMailer.
2009-11-06 11:40:38 +00:00
def mailer_sender=(value)
DeviseMailer.sender = value
end
2009-11-06 11:40:38 +00:00
alias :sender= :mailer_sender=
# Sets warden configuration using a block that will be invoked on warden
# initialization.
#
# Devise.initialize do |config|
# config.confirm_within = 2.days
#
# config.warden do |manager|
# # Configure warden to use other strategies, like oauth.
# manager.oauth(:twitter)
# end
# end
def warden(&block)
@warden_config = block
end
# Configure default url options to be used within Devise and ActionController.
def default_url_options(&block)
Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
end
# A method used internally to setup warden manager from the Rails initialize
# block.
def configure_warden_manager(manager) #:nodoc:
manager.default_strategies *Devise::STRATEGIES
2009-11-15 02:13:43 +00:00
manager.default_serializers *Devise::SERIALIZERS
2009-11-16 16:31:09 +00:00
manager.failure_app = Devise::FailureApp
manager.silence_missing_strategies!
2009-11-15 02:13:43 +00:00
manager.silence_missing_serializers!
# If the user provided a warden hook, call it now.
@warden_config.try :call, manager
end
2009-11-14 00:33:00 +00:00
# The class of the configured ORM
def orm_class
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
end
# Generate a friendly string randomically to be used as token.
def friendly_token
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
end
end
end
2009-10-21 02:12:21 +00:00
2009-11-15 02:13:43 +00:00
begin
require 'warden'
rescue
gem 'warden'
require 'warden'
end
2009-11-19 15:09:05 +00:00
# Set the default_scope to nil, so it's overwritten when the first route is declared.
Warden::Manager.default_scope = nil
2009-11-15 02:13:43 +00:00
require 'devise/strategies/base'
require 'devise/serializers/base'
2009-11-16 16:31:09 +00:00
require 'devise/rails'