Module: Devise
- Defined in:
- lib/devise.rb,
lib/devise/rails.rb,
lib/devise/models.rb,
lib/devise/schema.rb,
lib/devise/mapping.rb,
lib/devise/version.rb,
lib/devise/failure_app.rb,
lib/devise/orm/mongoid.rb,
lib/devise/path_checker.rb,
lib/devise/test_helpers.rb,
lib/devise/encryptors/base.rb,
lib/devise/encryptors/sha1.rb,
lib/devise/models/lockable.rb,
lib/devise/strategies/base.rb,
lib/devise/models/trackable.rb,
lib/devise/encryptors/bcrypt.rb,
lib/devise/encryptors/sha512.rb,
lib/devise/orm/active_record.rb,
lib/devise/hooks/rememberable.rb,
lib/devise/models/confirmable.rb,
lib/devise/models/recoverable.rb,
lib/devise/models/timeoutable.rb,
lib/devise/models/validatable.rb,
lib/devise/controllers/helpers.rb,
lib/devise/models/registerable.rb,
lib/devise/models/rememberable.rb,
lib/devise/models/authenticatable.rb,
lib/generators/devise/orm_helpers.rb,
lib/devise/controllers/url_helpers.rb,
lib/devise/strategies/rememberable.rb,
lib/devise/controllers/scoped_views.rb,
lib/devise/encryptors/clearance_sha1.rb,
lib/devise/strategies/authenticatable.rb,
lib/generators/devise/views_generator.rb,
lib/devise/encryptors/authlogic_sha512.rb,
lib/generators/devise/devise_generator.rb,
lib/devise/controllers/internal_helpers.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,
lib/devise/encryptors/restful_authentication_sha1.rb
Defined Under Namespace
Modules: Controllers, Encryptors, Generators, Hooks, Models, Orm, Schema, Strategies, TestHelpers Classes: ConfirmationsController, Engine, FailureApp, IndifferentHash, Mailer, Mapping, PasswordsController, PathChecker, RegistrationsController, SessionsController, UnlocksController
Constant Summary collapse
- ALL =
Constants which holds devise configuration for extensions. Those should not be modified by the “end user”.
[]
- CONTROLLERS =
ActiveSupport::OrderedHash.new
- ROUTES =
ActiveSupport::OrderedHash.new
- STRATEGIES =
ActiveSupport::OrderedHash.new
- TRUE_VALUES =
True values used to check params
[true, 1, '1', 't', 'T', 'true', 'TRUE']
- ENCRYPTORS_LENGTH =
Declare encryptors length which are used in migrations.
{ :sha1 => 40, :sha512 => 128, :clearance_sha1 => 40, :restful_authentication_sha1 => 40, :authlogic_sha512 => 128, :bcrypt => 60 }
- VERSION =
"1.1.5".freeze
false
- @@pepper =
nil
- @@stretches =
10
- @@authentication_keys =
[ :email ]
- @@http_authenticatable =
false
- @@http_authenticatable_on_xhr =
true
- @@params_authenticatable =
true
- @@http_authentication_realm =
"Application"
- @@email_regexp =
/^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
- @@password_length =
6..20
- @@remember_for =
2.weeks
- @@remember_across_browsers =
true
- @@extend_remember_period =
false
- @@confirm_within =
0.days
- @@timeout_in =
30.minutes
- @@encryptor =
nil
- @@mappings =
ActiveSupport::OrderedHash.new
- @@apply_schema =
true
- @@scoped_views =
false
- @@lock_strategy =
:failed_attempts
- @@unlock_strategy =
:both
- @@maximum_attempts =
20
- @@unlock_in =
1.hour
- @@default_scope =
nil
- @@mailer_sender =
nil
- @@token_authentication_key =
:auth_token
[:html]
- @@warden_config =
nil
- @@warden_config_block =
nil
- @@sign_out_all_scopes =
false
Class Method Summary collapse
-
.add_mapping(resource, options) ⇒ Object
Small method that adds a mapping to Devise.
-
.add_module(module_name, options = {}) ⇒ Object
Make Devise aware of an 3rd party Devise-module.
-
.configure_warden! ⇒ Object
A method used internally to setup warden manager from the Rails initialize block.
-
.friendly_token ⇒ Object
Generate a friendly string randomically to be used as token.
-
.mailer ⇒ Object
Get the mailer class from the mailer reference object.
-
.mailer=(class_name) ⇒ Object
Set the mailer reference object to access the mailer.
-
.rack_session? ⇒ Boolean
Returns true if Rails version is bigger than 3.0.x.
-
.setup {|_self| ... } ⇒ Object
Default way to setup Devise.
- .use_default_scope= ⇒ Object
-
.warden(&block) ⇒ Object
Sets warden configuration using a block that will be invoked on warden initialization.
Class Method Details
.add_mapping(resource, options) ⇒ Object
Small method that adds a mapping to Devise.
198 199 200 201 202 203 |
# File 'lib/devise.rb', line 198 def self.add_mapping(resource, ) mapping = Devise::Mapping.new(resource, ) self.mappings[mapping.name] = mapping self.default_scope ||= mapping.name mapping end |
.add_module(module_name, options = {}) ⇒ Object
Make Devise aware of an 3rd party Devise-module. 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.
+flash+ - Symbol representing the *flash messages* used by this helper.
+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')
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/devise.rb', line 224 def self.add_module(module_name, = {}) ALL << module_name .assert_valid_keys(:strategy, :model, :controller, :route) config = { :strategy => STRATEGIES, :route => ROUTES, :controller => CONTROLLERS } config.each do |key, value| next unless [key] name = ([key] == true ? module_name : [key]) if value.is_a?(Hash) value[module_name] = name else value << name unless value.include?(name) end end if [:model] model_path = ([:model] == true ? "devise/models/#{module_name}" : [:model]) Devise::Models.send(:autoload, module_name.to_s.camelize.to_sym, model_path) end Devise::Mapping.add_module module_name end |
.configure_warden! ⇒ Object
A method used internally to setup warden manager from the Rails initialize block.
275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/devise.rb', line 275 def self.configure_warden! #:nodoc: @@warden_configured ||= begin warden_config.failure_app = Devise::FailureApp warden_config.default_scope = Devise.default_scope 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 |
.friendly_token ⇒ Object
Generate a friendly string randomically to be used as token.
290 291 292 |
# File 'lib/devise.rb', line 290 def self.friendly_token ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n") end |
.mailer ⇒ Object
Get the mailer class from the mailer reference object.
187 188 189 |
# File 'lib/devise.rb', line 187 def self.mailer @@mailer_ref.get end |
.mailer=(class_name) ⇒ Object
Set the mailer reference object to access the mailer.
192 193 194 |
# File 'lib/devise.rb', line 192 def self.mailer=(class_name) @@mailer_ref = ActiveSupport::Dependencies.ref(class_name) end |
.rack_session? ⇒ Boolean
Returns true if Rails version is bigger than 3.0.x
269 270 271 |
# File 'lib/devise.rb', line 269 def self.rack_session? Rails::VERSION::STRING[0,3] != "3.0" end |
.setup {|_self| ... } ⇒ Object
Default way to setup Devise. Run rails generate devise_install to create a fresh initializer with all configuration values.
182 183 184 |
# File 'lib/devise.rb', line 182 def self.setup yield self end |
.use_default_scope= ⇒ Object
173 174 175 176 177 178 |
# File 'lib/devise.rb', line 173 def self.use_default_scope=(*) ActiveSupport::Deprecation.warn "config.use_default_scope is deprecated and removed from Devise. " << "If you are using non conventional routes in Devise, all you need to do is to pass the devise " << "scope in the router DSL:\n\n as :user do\n get \"sign_in\", :to => \"devise/sessions\"\n end\n\n" << "The method :as is also aliased to :devise_scope. Choose the one you prefer.", caller end |
.warden(&block) ⇒ Object
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
264 265 266 |
# File 'lib/devise.rb', line 264 def self.warden(&block) @@warden_config_block = block end |