2009-10-18 11:30:32 -04:00
|
|
|
module Devise
|
2009-12-01 13:35:46 -05:00
|
|
|
autoload :FailureApp, 'devise/failure_app'
|
2009-12-12 19:52:48 -05:00
|
|
|
autoload :Mapping, 'devise/mapping'
|
|
|
|
autoload :Schema, 'devise/schema'
|
|
|
|
autoload :TestHelpers, 'devise/test_helpers'
|
|
|
|
|
|
|
|
module Controllers
|
|
|
|
autoload :Filters, 'devise/controllers/filters'
|
|
|
|
autoload :Helpers, 'devise/controllers/helpers'
|
|
|
|
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
|
|
|
end
|
|
|
|
|
|
|
|
module Encryptors
|
|
|
|
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
|
|
|
|
autoload :AuthlogicSha1, 'devise/encryptors/authlogic_sha1'
|
|
|
|
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
|
|
|
|
autoload :Sha512, 'devise/encryptors/sha512'
|
|
|
|
autoload :Sha1, 'devise/encryptors/sha1'
|
|
|
|
end
|
|
|
|
|
|
|
|
module Orm
|
|
|
|
autoload :ActiveRecord, 'devise/orm/active_record'
|
|
|
|
autoload :DataMapper, 'devise/orm/data_mapper'
|
|
|
|
autoload :MongoMapper, 'devise/orm/mongo_mapper'
|
|
|
|
end
|
2009-12-01 13:35:46 -05:00
|
|
|
|
2009-11-24 12:18:42 -05:00
|
|
|
ALL = [:authenticatable, :confirmable, :recoverable, :rememberable,
|
2009-12-08 15:29:00 -05:00
|
|
|
:timeoutable, :trackable, :validatable]
|
2009-10-18 11:30:32 -04:00
|
|
|
|
|
|
|
# Maps controller names to devise modules
|
|
|
|
CONTROLLERS = {
|
2009-12-08 17:39:38 -05:00
|
|
|
:sessions => [:authenticatable],
|
|
|
|
:passwords => [:recoverable],
|
|
|
|
:confirmations => [:confirmable]
|
2009-12-09 05:14:50 -05:00
|
|
|
}
|
2009-10-20 06:44:21 -04:00
|
|
|
|
2009-12-08 15:29:00 -05:00
|
|
|
STRATEGIES = [:authenticatable]
|
2009-12-20 06:31:02 -05:00
|
|
|
SERIALIZERS = [:session, :cookie]
|
2009-12-08 15:29:00 -05:00
|
|
|
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
2009-10-18 11:30:32 -04:00
|
|
|
|
2009-11-18 06:26:47 -05:00
|
|
|
# Maps the messages types that are used in flash message. This array is not
|
|
|
|
# frozen, so you can add messages from your own strategies.
|
2009-11-23 19:56:04 -05:00
|
|
|
FLASH_MESSAGES = [ :unauthenticated, :unconfirmed, :invalid, :timeout ]
|
2009-11-06 11:27:27 -05:00
|
|
|
|
2009-11-10 15:55:13 -05: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
|
|
|
|
}
|
|
|
|
|
2009-11-18 06:41:42 -05:00
|
|
|
# Used to encrypt password. Please generate one with rake secret.
|
2009-11-09 19:00:44 -05:00
|
|
|
mattr_accessor :pepper
|
|
|
|
@@pepper = nil
|
2009-11-13 17:54:21 -05:00
|
|
|
|
2009-11-09 19:00:44 -05:00
|
|
|
# The number of times to encrypt password.
|
|
|
|
mattr_accessor :stretches
|
|
|
|
@@stretches = 10
|
2009-11-13 17:54:21 -05:00
|
|
|
|
2009-11-15 00:31:13 -05:00
|
|
|
# Keys used when authenticating an user.
|
|
|
|
mattr_accessor :authentication_keys
|
|
|
|
@@authentication_keys = [ :email ]
|
|
|
|
|
2009-11-09 19:00:44 -05:00
|
|
|
# Time interval where the remember me token is valid.
|
|
|
|
mattr_accessor :remember_for
|
|
|
|
@@remember_for = 2.weeks
|
2009-11-13 17:54:21 -05:00
|
|
|
|
2009-11-09 19:00:44 -05:00
|
|
|
# Time interval you can access your account before confirming your account.
|
|
|
|
mattr_accessor :confirm_within
|
|
|
|
@@confirm_within = 0.days
|
2009-11-03 19:34:37 -05:00
|
|
|
|
2009-11-22 19:19:29 -05:00
|
|
|
# Time interval to timeout the user session without activity.
|
2009-11-24 21:11:49 -05:00
|
|
|
mattr_accessor :timeout_in
|
|
|
|
@@timeout_in = 30.minutes
|
2009-11-22 19:19:29 -05:00
|
|
|
|
2009-11-10 15:55:13 -05:00
|
|
|
# Used to define the password encryption algorithm.
|
2009-11-22 19:32:54 -05:00
|
|
|
mattr_accessor :encryptor
|
|
|
|
@@encryptor = :sha1
|
2009-11-10 15:55:13 -05:00
|
|
|
|
2009-11-09 19:00:44 -05:00
|
|
|
# Store scopes mappings.
|
2009-11-06 11:27:27 -05:00
|
|
|
mattr_accessor :mappings
|
2009-11-09 19:00:44 -05:00
|
|
|
@@mappings = {}
|
2009-11-06 11:27:27 -05:00
|
|
|
|
2009-11-13 19:33:00 -05:00
|
|
|
# Stores the chosen ORM.
|
2009-11-13 17:54:21 -05:00
|
|
|
mattr_accessor :orm
|
2009-11-13 19:33:00 -05:00
|
|
|
@@orm = :active_record
|
2009-11-13 17:54:21 -05:00
|
|
|
|
2009-11-18 06:41:42 -05:00
|
|
|
# Configure default options used in :all.
|
2009-11-18 06:26:47 -05:00
|
|
|
mattr_accessor :all
|
|
|
|
@@all = Devise::ALL.dup
|
|
|
|
|
2009-11-18 06:41:42 -05:00
|
|
|
# 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
|
|
|
|
|
2009-11-21 17:07:37 -05:00
|
|
|
# Scoped views. Since it relies on fallbacks to render default views, it's
|
|
|
|
# turned off by default.
|
|
|
|
mattr_accessor :scoped_views
|
|
|
|
@@scoped_views = false
|
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
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 06:40:38 -05:00
|
|
|
def mailer_sender=(value)
|
2009-11-03 06:35:11 -05:00
|
|
|
DeviseMailer.sender = value
|
|
|
|
end
|
2009-11-06 06:40:38 -05:00
|
|
|
alias :sender= :mailer_sender=
|
2009-10-30 19:51:50 -04:00
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
# 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
|
|
|
|
|
2009-11-06 17:59:36 -05:00
|
|
|
# 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
|
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
# 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-14 21:13:43 -05:00
|
|
|
manager.default_serializers *Devise::SERIALIZERS
|
2009-11-16 11:31:09 -05:00
|
|
|
manager.failure_app = Devise::FailureApp
|
2009-11-03 06:35:11 -05:00
|
|
|
manager.silence_missing_strategies!
|
2009-11-14 21:13:43 -05:00
|
|
|
manager.silence_missing_serializers!
|
2009-11-03 06:35:11 -05:00
|
|
|
|
|
|
|
# If the user provided a warden hook, call it now.
|
|
|
|
@warden_config.try :call, manager
|
|
|
|
end
|
2009-11-13 17:54:21 -05:00
|
|
|
|
2009-11-13 19:33:00 -05:00
|
|
|
# The class of the configured ORM
|
|
|
|
def orm_class
|
|
|
|
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
|
2009-11-13 17:54:21 -05:00
|
|
|
end
|
2009-11-18 06:26:47 -05:00
|
|
|
|
|
|
|
# Generate a friendly string randomically to be used as token.
|
|
|
|
def friendly_token
|
|
|
|
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
|
|
|
end
|
2009-11-03 06:35:11 -05:00
|
|
|
end
|
2009-10-11 07:15:48 -04:00
|
|
|
end
|
2009-10-20 22:12:21 -04:00
|
|
|
|
2009-11-14 21:13:43 -05:00
|
|
|
begin
|
|
|
|
require 'warden'
|
|
|
|
rescue
|
|
|
|
gem 'warden'
|
|
|
|
require 'warden'
|
|
|
|
end
|
|
|
|
|
2009-12-20 06:31:02 -05:00
|
|
|
# Clear some Warden default configuration which will be overwritten
|
|
|
|
Warden::Strategies.clear!
|
|
|
|
Warden::Serializers.clear!
|
2009-11-19 10:09:05 -05:00
|
|
|
Warden::Manager.default_scope = nil
|
2009-12-20 06:31:02 -05:00
|
|
|
|
|
|
|
require 'devise/rails'
|