# module Devise

### Constants

ALL

  Constants which holds devise configuration for extensions. Those should not be modified by the “end user” (this is why they are constants).

CONTROLLERS
ENCRYPTORS_LENGTH

  Declare encryptors length which are used in migrations.

NO_INPUT

  Strategies that do not require user input.

ROUTES
STRATEGIES
TRUE_VALUES

  True values used to check params

URL_HELPERS
VERSION

### Public Class Methods

add_mapping(resource, options) click to toggle source

Small method that adds a mapping to Devise.

    # File lib/devise.rb, line 318
    def self.add_mapping(resource, options)
      mapping = Devise::Mapping.new(resource, options)
      @@mappings[mapping.name] = mapping
      @@default_scope ||= mapping.name
      @@helpers.each { |h| h.define_helpers(mapping) }
      mapping
    end

add_module(module_name, options = {}) click to toggle source

Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.

## Options:

    +model+      - String representing the load path to a custom *model* for this module (to autoload.)
    +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
    +route+      - Symbol representing the named *route* helper for this module.
    +strategy+   - Symbol representing if this module got a custom *strategy*.

All values, except :model, accept also a boolean and will have the same name as the given module name.

## Examples:

    Devise.add_module(:party_module)
    Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
    Devise.add_module(:party_module, :model => 'party_module/model')

    # File lib/devise.rb, line 344
    def self.add_module(module_name, options = {})
      ALL << module_name
      options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)

      if strategy = options[:strategy]
        strategy = (strategy == true ? module_name : strategy)
        STRATEGIES[module_name] = strategy
      end

      if controller = options[:controller]
        controller = (controller == true ? module_name : controller)
        CONTROLLERS[module_name] = controller
      end

      NO_INPUT << strategy if options[:no_input]

      if route = options[:route]
        case route
        when TrueClass
          key, value = module_name, []
        when Symbol
          key, value = route, []
        when Hash
          key, value = route.keys.first, route.values.flatten
        else
          raise ArgumentError, ":route should be true, a Symbol or a Hash"
        end

        URL_HELPERS[key] ||= []
        URL_HELPERS[key].concat(value)
        URL_HELPERS[key].uniq!

        ROUTES[module_name] = key
      end

      if options[:model]
        path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
        camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
        Devise::Models.send(:autoload, camelized.to_sym, path)
      end

      Devise::Mapping.add_module module_name
    end

confirm_within=(value) click to toggle source

    # File lib/devise.rb, line 242
    def self.confirm_within=(value)
      warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
      Devise.allow_unconfirmed_access_for = value
    end

friendly_token() click to toggle source

Generate a friendly string randomically to be used as token.

    # File lib/devise.rb, line 449
    def self.friendly_token
      SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
    end

include_helpers(scope) click to toggle source

Include helpers in the given scope to AC and AV.

    # File lib/devise.rb, line 414
    def self.include_helpers(scope)
      ActiveSupport.on_load(:action_controller) do
        include scope::Helpers if defined?(scope::Helpers)
        include scope::UrlHelpers
      end

      ActiveSupport.on_load(:action_view) do
        include scope::UrlHelpers
      end
    end

mailer() click to toggle source

Get the mailer class from the mailer reference object.

    # File lib/devise.rb, line 307
    def self.mailer
      @@mailer_ref.get
    end

mailer=(class_name) click to toggle source

Set the mailer reference object to access the mailer.

    # File lib/devise.rb, line 312
    def self.mailer=(class_name)
      @@mailer_ref = ref(class_name)
    end

omniauth(provider, *args) click to toggle source

Specify an omniauth provider.

    config.omniauth :github, APP_ID, APP_SECRET

    # File lib/devise.rb, line 407
    def self.omniauth(provider, *args)
      @@helpers << Devise::OmniAuth::UrlHelpers
      config = Devise::OmniAuth::Config.new(provider, args)
      @@omniauth_configs[config.strategy_name.to_sym] = config
    end

omniauth_providers() click to toggle source

    # File lib/devise.rb, line 302
    def self.omniauth_providers
      omniauth_configs.keys
    end

ref(arg) click to toggle source

    # File lib/devise.rb, line 293
    def self.ref(arg)
      if defined?(ActiveSupport::Dependencies::ClassCache)
        ActiveSupport::Dependencies::reference(arg)
        Getter.new(arg)
      else
        ActiveSupport::Dependencies.ref(arg)
      end
    end

regenerate_helpers!() click to toggle source

Regenerates url helpers considering Devise.mapping

    # File lib/devise.rb, line 426
    def self.regenerate_helpers!
      Devise::Controllers::UrlHelpers.remove_helpers!
      Devise::Controllers::UrlHelpers.generate_helpers!
    end

remember_across_browsers=(value) click to toggle source

    # File lib/devise.rb, line 238
    def self.remember_across_browsers=(value)
      warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
    end

secure_compare(a, b) click to toggle source

constant-time comparison algorithm to prevent timing attacks

    # File lib/devise.rb, line 454
    def self.secure_compare(a, b)
      return false if a.blank? || b.blank? || a.bytesize != b.bytesize
      l = a.unpack "C#{a.bytesize}"

      res = 0
      b.each_byte { |byte| res |= byte ^ l.shift }
      res == 0
    end

setup() { |self| ... } click to toggle source

Default way to setup Devise. Run rails generate devise_install to create a fresh initializer with all configuration values.

    # File lib/devise.rb, line 279
    def self.setup
      yield self
    end

stateless_token=(value) click to toggle source

    # File lib/devise.rb, line 247
    def self.stateless_token=(value)
      warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage "        "instead, for example: Devise.skip_session_storage << :token_auth\n"
      Devise.skip_session_storage << :token_auth
    end

warden(&block) click to toggle source

Sets warden configuration using a block that will be invoked on warden initialization.

    Devise.initialize do |config|
      config.allow_unconfirmed_access_for = 2.days

      config.warden do |manager|
        # Configure warden to use other strategies, like oauth.
        manager.oauth(:twitter)
      end
    end

    # File lib/devise.rb, line 399
    def self.warden(&block)
      @@warden_config_block = block
    end