Module: Devise
- Defined in:
- lib/devise.rb,
lib/devise/rails.rb,
lib/devise/models.rb,
lib/devise/version.rb,
lib/devise/mapping.rb,
lib/devise/omniauth.rb,
lib/devise/delegator.rb,
lib/devise/failure_app.rb,
lib/devise/param_filter.rb,
lib/devise/test_helpers.rb,
lib/devise/models/lockable.rb,
lib/devise/mailers/helpers.rb,
lib/devise/omniauth/config.rb,
lib/devise/strategies/base.rb,
lib/devise/models/trackable.rb,
lib/devise/models/recoverable.rb,
lib/devise/models/timeoutable.rb,
lib/devise/models/validatable.rb,
lib/devise/models/confirmable.rb,
lib/devise/models/registerable.rb,
lib/devise/models/rememberable.rb,
lib/devise/controllers/helpers.rb,
lib/devise/models/omniauthable.rb,
lib/devise/omniauth/url_helpers.rb,
lib/generators/devise/orm_helpers.rb,
lib/devise/models/authenticatable.rb,
lib/devise/controllers/url_helpers.rb,
lib/devise/strategies/rememberable.rb,
lib/devise/controllers/scoped_views.rb,
lib/devise/controllers/rememberable.rb,
lib/devise/strategies/authenticatable.rb,
lib/generators/devise/views_generator.rb,
lib/generators/devise/devise_generator.rb,
lib/devise/models/token_authenticatable.rb,
lib/generators/devise/install_generator.rb,
lib/devise/models/database_authenticatable.rb,
lib/devise/strategies/token_authenticatable.rb,
lib/devise/strategies/database_authenticatable.rb
Defined Under Namespace
Modules: Controllers, Generators, Mailers, Models, OmniAuth, Strategies, TestHelpers Classes: ConfirmationsController, Delegator, Engine, FailureApp, Getter, Mailer, Mapping, OmniauthCallbacksController, ParamFilter, PasswordsController, RegistrationsController, SessionsController, UnlocksController
Constant Summary
- ALL =
Constants which holds devise configuration for extensions. Those should not be modified by the "end user" (this is why they are constants).
[]
- CONTROLLERS =
ActiveSupport::OrderedHash.new
- ROUTES =
ActiveSupport::OrderedHash.new
- STRATEGIES =
ActiveSupport::OrderedHash.new
- URL_HELPERS =
ActiveSupport::OrderedHash.new
- NO_INPUT =
Strategies that do not require user input.
[]
- TRUE_VALUES =
True values used to check params
[true, 1, '1', 't', 'T', 'true', 'TRUE']
- VERSION =
"2.1.0".freeze
- @@rememberable_options =
{}
- @@stretches =
10- @@authentication_keys =
[ :email ]
- @@request_keys =
[]
- @@case_insensitive_keys =
[ :email ]
- @@strip_whitespace_keys =
[]
- @@http_authenticatable =
false- @@http_authenticatable_on_xhr =
true- @@params_authenticatable =
true- @@http_authentication_realm =
"Application"- @@email_regexp =
/\A[^@]+@([^@\.]+\.)+[^@\.]+\z/- @@password_length =
6..128
- @@remember_for =
2.weeks
- @@extend_remember_period =
false- @@allow_unconfirmed_access_for =
0.days
- @@confirmation_keys =
[ :email ]
- @@reconfirmable =
false- @@timeout_in =
30.minutes
- @@expire_auth_token_on_timeout =
false- @@pepper =
nil- @@scoped_views =
false- @@lock_strategy =
:failed_attempts- @@unlock_keys =
[ :email ]
- @@unlock_strategy =
:both- @@maximum_attempts =
20- @@unlock_in =
1.hour
- @@reset_password_keys =
[ :email ]
- @@reset_password_within =
6.hours
- @@default_scope =
nil- @@mailer_sender =
nil- @@token_authentication_key =
:auth_token- @@skip_session_storage =
[]
["*/*", :html]
- @@sign_out_all_scopes =
true- @@sign_out_via =
:get- @@parent_controller =
"ApplicationController"- @@router_name =
nil- @@mappings =
ActiveSupport::OrderedHash.new
- @@omniauth_configs =
ActiveSupport::OrderedHash.new
- @@helpers =
Set.new
- @@warden_config =
nil- @@warden_config_block =
nil- @@paranoid =
false
Class Method Summary (collapse)
-
+ (Object) add_mapping(resource, options)
Small method that adds a mapping to Devise.
-
+ (Object) add_module(module_name, options = {})
Make Devise aware of an 3rd party Devise-module (like invitable).
- + (Object) apply_schema=(value)
- + (Object) available_router_name
-
+ (Object) configure_warden!
A method used internally to setup warden manager from the Rails initialize block.
- + (Object) encryptor=(value)
-
+ (Object) friendly_token
Generate a friendly string randomically to be used as token.
-
+ (Object) include_helpers(scope)
Include helpers in the given scope to AC and AV.
-
+ (Object) mailer
Get the mailer class from the mailer reference object.
-
+ (Object) mailer=(class_name)
Set the mailer reference object to access the mailer.
-
+ (Object) omniauth(provider, *args)
Specify an omniauth provider.
- + (Object) omniauth_providers
- + (Object) ref(arg)
-
+ (Object) regenerate_helpers!
Regenerates url helpers considering Devise.mapping.
-
+ (Object) secure_compare(a, b)
constant-time comparison algorithm to prevent timing attacks.
-
+ (Object) setup {|_self| ... }
Default way to setup Devise.
- + (Object) use_salt_as_remember_token=(value)
-
+ (Object) warden(&block)
Sets warden configuration using a block that will be invoked on warden initialization.
Class Method Details
+ (Object) add_mapping(resource, options)
Small method that adds a mapping to Devise.
284 285 286 287 288 289 290 |
# File 'lib/devise.rb', line 284 def self.add_mapping(resource, ) mapping = Devise::Mapping.new(resource, ) @@mappings[mapping.name] = mapping @@default_scope ||= mapping.name @@helpers.each { |h| h.define_helpers(mapping) } mapping end |
+ (Object) add_module(module_name, options = {})
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')
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/devise.rb', line 310 def self.add_module(module_name, = {}) ALL << module_name .assert_valid_keys(:strategy, :model, :controller, :route, :no_input) if strategy = [:strategy] strategy = (strategy == true ? module_name : strategy) STRATEGIES[module_name] = strategy end if controller = [:controller] controller = (controller == true ? module_name : controller) CONTROLLERS[module_name] = controller end NO_INPUT << strategy if [:no_input] if route = [: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 [:model] path = ([:model] == true ? "devise/models/#{module_name}" : [: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 |
+ (Object) apply_schema=(value)
211 212 213 |
# File 'lib/devise.rb', line 211 def self.apply_schema=(value) warn "\n[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.\n" end |
+ (Object) available_router_name
264 265 266 |
# File 'lib/devise.rb', line 264 def self.available_router_name router_name || :main_app end |
+ (Object) configure_warden!
A method used internally to setup warden manager from the Rails initialize block.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/devise.rb', line 399 def self.configure_warden! #:nodoc: @@warden_configured ||= begin warden_config.failure_app = Devise::Delegator.new warden_config.default_scope = Devise.default_scope warden_config.intercept_401 = false Devise.mappings.each_value do |mapping| warden_config.scope_defaults mapping.name, :strategies => mapping.strategies end @@warden_config_block.try :call, Devise.warden_config true end end |
+ (Object) encryptor=(value)
203 204 205 |
# File 'lib/devise.rb', line 203 def self.encryptor=(value) warn "\n[DEVISE] To select a encryption which isn't bcrypt, you should use devise-encryptable gem.\n" end |
+ (Object) friendly_token
Generate a friendly string randomically to be used as token.
415 416 417 |
# File 'lib/devise.rb', line 415 def self.friendly_token SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz') end |
+ (Object) include_helpers(scope)
Include helpers in the given scope to AC and AV.
380 381 382 383 384 385 386 387 388 389 |
# File 'lib/devise.rb', line 380 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 |
+ (Object) mailer
Get the mailer class from the mailer reference object.
273 274 275 |
# File 'lib/devise.rb', line 273 def self.mailer @@mailer_ref.get end |
+ (Object) mailer=(class_name)
Set the mailer reference object to access the mailer.
278 279 280 |
# File 'lib/devise.rb', line 278 def self.mailer=(class_name) @@mailer_ref = ref(class_name) end |
+ (Object) omniauth(provider, *args)
Specify an omniauth provider.
config.omniauth :github, APP_ID, APP_SECRET
373 374 375 376 377 |
# File 'lib/devise.rb', line 373 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 |
+ (Object) omniauth_providers
268 269 270 |
# File 'lib/devise.rb', line 268 def self.omniauth_providers omniauth_configs.keys end |
+ (Object) ref(arg)
255 256 257 258 259 260 261 262 |
# File 'lib/devise.rb', line 255 def self.ref(arg) if defined?(ActiveSupport::Dependencies::ClassCache) ActiveSupport::Dependencies::reference(arg) Getter.new(arg) else ActiveSupport::Dependencies.ref(arg) end end |
+ (Object) regenerate_helpers!
Regenerates url helpers considering Devise.mapping
392 393 394 395 |
# File 'lib/devise.rb', line 392 def self.regenerate_helpers! Devise::Controllers::UrlHelpers.remove_helpers! Devise::Controllers::UrlHelpers.generate_helpers! end |
+ (Object) secure_compare(a, b)
constant-time comparison algorithm to prevent timing attacks
420 421 422 423 424 425 426 427 |
# File 'lib/devise.rb', line 420 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 |
+ (Object) setup {|_self| ... }
Default way to setup Devise. Run rails generate devise_install to create a fresh initializer with all configuration values.
241 242 243 |
# File 'lib/devise.rb', line 241 def self.setup yield self end |
+ (Object) use_salt_as_remember_token=(value)
207 208 209 |
# File 'lib/devise.rb', line 207 def self.use_salt_as_remember_token=(value) warn "\n[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.\n" end |
+ (Object) warden(&block)
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
365 366 367 |
# File 'lib/devise.rb', line 365 def self.warden(&block) @@warden_config_block = block end |