devise-edge 1.2.rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +500 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +335 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +75 -0
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +88 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +42 -0
- data/lib/devise.rb +371 -0
- data/lib/devise/controllers/helpers.rb +261 -0
- data/lib/devise/controllers/internal_helpers.rb +113 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +126 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +45 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +105 -0
- data/lib/devise/models.rb +66 -0
- data/lib/devise/models/authenticatable.rb +143 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +94 -0
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +168 -0
- data/lib/devise/models/oauthable.rb +49 -0
- data/lib/devise/models/recoverable.rb +83 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +122 -0
- data/lib/devise/models/timeoutable.rb +33 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +60 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/oauth.rb +41 -0
- data/lib/devise/oauth/config.rb +33 -0
- data/lib/devise/oauth/helpers.rb +18 -0
- data/lib/devise/oauth/internal_helpers.rb +182 -0
- data/lib/devise/oauth/test_helpers.rb +29 -0
- data/lib/devise/oauth/url_helpers.rb +35 -0
- data/lib/devise/orm/active_record.rb +36 -0
- data/lib/devise/orm/mongo_mapper.rb +46 -0
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +67 -0
- data/lib/devise/rails/routes.rb +260 -0
- data/lib/devise/rails/warden_compat.rb +42 -0
- data/lib/devise/schema.rb +96 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +30 -0
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +24 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +168 -0
- data/test/controllers/helpers_test.rb +220 -0
- data/test/controllers/internal_helpers_test.rb +56 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +148 -0
- data/test/integration/authenticatable_test.rb +424 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +64 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/oauthable_test.rb +258 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +179 -0
- data/test/integration/timeoutable_test.rb +80 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +95 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +82 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/oauthable_test.rb +21 -0
- data/test/models/recoverable_test.rb +155 -0
- data/test/models/rememberable_test.rb +271 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +77 -0
- data/test/oauth/config_test.rb +44 -0
- data/test/oauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +12 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +172 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +54 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +48 -0
- data/test/routes_test.rb +189 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +23 -0
- data/test/test_helpers_test.rb +101 -0
- metadata +335 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Oauth
|
|
3
|
+
module TestHelpers #:nodoc:
|
|
4
|
+
def self.short_circuit_authorizers!
|
|
5
|
+
module_eval <<-ALIASES, __FILE__, __LINE__ + 1
|
|
6
|
+
def oauth_authorize_url(scope, provider)
|
|
7
|
+
oauth_callback_path(scope, provider, :code => "12345")
|
|
8
|
+
end
|
|
9
|
+
ALIASES
|
|
10
|
+
|
|
11
|
+
Devise.mappings.each_value do |m|
|
|
12
|
+
next unless m.oauthable?
|
|
13
|
+
|
|
14
|
+
module_eval <<-ALIASES, __FILE__, __LINE__ + 1
|
|
15
|
+
def #{m.name}_oauth_authorize_url(provider)
|
|
16
|
+
#{m.name}_oauth_callback_path(provider, :code => "12345")
|
|
17
|
+
end
|
|
18
|
+
ALIASES
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.unshort_circuit_authorizers!
|
|
23
|
+
module_eval do
|
|
24
|
+
instance_methods.each { |m| remove_method(m) }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Oauth
|
|
3
|
+
module UrlHelpers
|
|
4
|
+
def self.define_helpers(mapping)
|
|
5
|
+
return unless mapping.oauthable?
|
|
6
|
+
|
|
7
|
+
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
|
8
|
+
def #{mapping.name}_oauth_authorize_url(provider, options={})
|
|
9
|
+
if config = Devise.oauth_configs[provider.to_sym]
|
|
10
|
+
options[:redirect_uri] ||= #{mapping.name}_oauth_callback_url(provider.to_s)
|
|
11
|
+
config.authorize_url(options)
|
|
12
|
+
else
|
|
13
|
+
raise ArgumentError, "Could not find oauth provider \#{provider.inspect}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
URL_HELPERS
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def oauth_authorize_url(resource_or_scope, *args)
|
|
20
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
|
21
|
+
send("#{scope}_oauth_authorize_url", *args)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def oauth_callback_url(resource_or_scope, *args)
|
|
25
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
|
26
|
+
send("#{scope}_oauth_callback_url", *args)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def oauth_callback_path(resource_or_scope, *args)
|
|
30
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
|
31
|
+
send("#{scope}_oauth_callback_path", *args)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Orm
|
|
3
|
+
# This module contains some helpers and handle schema (migrations):
|
|
4
|
+
#
|
|
5
|
+
# create_table :accounts do |t|
|
|
6
|
+
# t.database_authenticatable
|
|
7
|
+
# t.confirmable
|
|
8
|
+
# t.recoverable
|
|
9
|
+
# t.rememberable
|
|
10
|
+
# t.trackable
|
|
11
|
+
# t.lockable
|
|
12
|
+
# t.timestamps
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# However this method does not add indexes. If you need them, here is the declaration:
|
|
16
|
+
#
|
|
17
|
+
# add_index "accounts", ["email"], :name => "email", :unique => true
|
|
18
|
+
# add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
|
|
19
|
+
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
|
|
20
|
+
#
|
|
21
|
+
module ActiveRecord
|
|
22
|
+
module Schema
|
|
23
|
+
include Devise::Schema
|
|
24
|
+
|
|
25
|
+
# Tell how to apply schema methods.
|
|
26
|
+
def apply_devise_schema(name, type, options={})
|
|
27
|
+
column name, type.to_s.downcase.to_sym, options
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
ActiveRecord::Base.extend Devise::Models
|
|
35
|
+
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
|
|
36
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Orm
|
|
3
|
+
module MongoMapper
|
|
4
|
+
|
|
5
|
+
module Hook
|
|
6
|
+
def devise_modules_hook!
|
|
7
|
+
extend Schema
|
|
8
|
+
include Compatibility
|
|
9
|
+
yield
|
|
10
|
+
return unless Devise.apply_schema
|
|
11
|
+
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module Schema
|
|
16
|
+
include Devise::Schema
|
|
17
|
+
def apply_devise_schema(name, type, options={})
|
|
18
|
+
type = Time if type == DateTime
|
|
19
|
+
key name, type, options
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Compatibility
|
|
24
|
+
extend ActiveSupport::Concern
|
|
25
|
+
module ClassMethods
|
|
26
|
+
|
|
27
|
+
def find(*args)
|
|
28
|
+
case args.first
|
|
29
|
+
when :first, :all
|
|
30
|
+
send(args.shift, *args)
|
|
31
|
+
else
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
[MongoMapper::Plugins::Document, MongoMapper::Plugins::EmbeddedDocument].each do |mod|
|
|
42
|
+
mod::ClassMethods.class_eval do
|
|
43
|
+
include Devise::Models
|
|
44
|
+
include Devise::Orm::MongoMapper::Hook
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Orm
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Hook
|
|
5
|
+
def devise_modules_hook!
|
|
6
|
+
extend Schema
|
|
7
|
+
yield
|
|
8
|
+
return unless Devise.apply_schema
|
|
9
|
+
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Schema
|
|
14
|
+
include Devise::Schema
|
|
15
|
+
|
|
16
|
+
# Tell how to apply schema methods
|
|
17
|
+
def apply_devise_schema(name, type, options={})
|
|
18
|
+
type = Time if type == DateTime
|
|
19
|
+
field name, { :type => type }.merge!(options)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Mongoid::Document::ClassMethods.class_eval do
|
|
27
|
+
include Devise::Models
|
|
28
|
+
include Devise::Orm::Mongoid::Hook
|
|
29
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
class PathChecker
|
|
3
|
+
include Rails.application.routes.url_helpers
|
|
4
|
+
|
|
5
|
+
def self.default_url_options(*args)
|
|
6
|
+
ApplicationController.default_url_options(*args)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def initialize(env, scope)
|
|
10
|
+
@current_path = "/#{env["SCRIPT_NAME"]}/#{env["PATH_INFO"]}".squeeze("/")
|
|
11
|
+
@scope = scope
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def signing_out?
|
|
15
|
+
@current_path == send("destroy_#{@scope}_session_path")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/devise/rails.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'devise/rails/routes'
|
|
2
|
+
require 'devise/rails/warden_compat'
|
|
3
|
+
|
|
4
|
+
module Devise
|
|
5
|
+
class Engine < ::Rails::Engine
|
|
6
|
+
config.devise = Devise
|
|
7
|
+
|
|
8
|
+
# Skip eager load of controllers because it is handled by Devise
|
|
9
|
+
# to avoid loading unused controllers.
|
|
10
|
+
config.paths.app.controllers.autoload!
|
|
11
|
+
config.paths.app.controllers.skip_eager_load!
|
|
12
|
+
|
|
13
|
+
# Initialize Warden and copy its configurations.
|
|
14
|
+
config.app_middleware.use Warden::Manager do |config|
|
|
15
|
+
Devise.warden_config = config
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Force routes to be loaded if we are doing any eager load.
|
|
19
|
+
config.before_eager_load { |app| app.reload_routes! }
|
|
20
|
+
|
|
21
|
+
initializer "devise.add_filters" do |app|
|
|
22
|
+
app.config.filter_parameters += [:password, :password_confirmation]
|
|
23
|
+
app.config.filter_parameters.uniq
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
initializer "devise.url_helpers" do
|
|
27
|
+
Devise.include_helpers(Devise::Controllers)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
initializer "devise.oauth_url_helpers" do
|
|
31
|
+
if Devise.oauth_providers.any?
|
|
32
|
+
Devise.include_helpers(Devise::Oauth)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
initializer "devise.encryptor_check" do
|
|
37
|
+
case Devise.encryptor
|
|
38
|
+
when :bcrypt
|
|
39
|
+
puts "[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt " <<
|
|
40
|
+
"since encryptors are only enabled if you include :encryptable in your models. " <<
|
|
41
|
+
"With this change, we can integrate better with bcrypt and get rid of the " <<
|
|
42
|
+
"password_salt column (since bcrypt stores the salt with password). " <<
|
|
43
|
+
"Please comment config.encryptor in your initializer to get rid of this warning."
|
|
44
|
+
when nil
|
|
45
|
+
# Nothing to say
|
|
46
|
+
else
|
|
47
|
+
puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " <<
|
|
48
|
+
"you need to explicitly add :encryptable to your models in order for this " <<
|
|
49
|
+
"configuration value to work."
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Check all available mappings and only load related controllers.
|
|
54
|
+
def eager_load!
|
|
55
|
+
mappings = Devise.mappings.values.map(&:modules).flatten.uniq
|
|
56
|
+
controllers = Devise::CONTROLLERS.values_at(*mappings)
|
|
57
|
+
path = paths.app.controllers.to_a.first
|
|
58
|
+
matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
|
|
59
|
+
|
|
60
|
+
Dir.glob("#{path}/devise/{#{controllers.join(',')}}_controller.rb").sort.each do |file|
|
|
61
|
+
require_dependency file.sub(matcher, '\1')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
super
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
module ActionDispatch::Routing
|
|
2
|
+
class RouteSet #:nodoc:
|
|
3
|
+
# Ensure Devise modules are included only after loading routes, because we
|
|
4
|
+
# need devise_for mappings already declared to create filters and helpers.
|
|
5
|
+
def finalize_with_devise!
|
|
6
|
+
finalize_without_devise!
|
|
7
|
+
Devise.configure_warden!
|
|
8
|
+
end
|
|
9
|
+
alias_method_chain :finalize!, :devise
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Mapper
|
|
13
|
+
# Includes devise_for method for routes. This method is responsible to
|
|
14
|
+
# generate all needed routes for devise, based on what modules you have
|
|
15
|
+
# defined in your model.
|
|
16
|
+
#
|
|
17
|
+
# ==== Examples
|
|
18
|
+
#
|
|
19
|
+
# Let's say you have an User model configured to use authenticatable,
|
|
20
|
+
# confirmable and recoverable modules. After creating this inside your routes:
|
|
21
|
+
#
|
|
22
|
+
# devise_for :users
|
|
23
|
+
#
|
|
24
|
+
# This method is going to look inside your User model and create the
|
|
25
|
+
# needed routes:
|
|
26
|
+
#
|
|
27
|
+
# # Session routes for Authenticatable (default)
|
|
28
|
+
# new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
|
|
29
|
+
# user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
|
|
30
|
+
# destroy_user_session GET /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
|
|
31
|
+
#
|
|
32
|
+
# # Password routes for Recoverable, if User model has :recoverable configured
|
|
33
|
+
# new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
|
|
34
|
+
# edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
|
|
35
|
+
# user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
|
|
36
|
+
# POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
|
|
37
|
+
#
|
|
38
|
+
# # Confirmation routes for Confirmable, if User model has :confirmable configured
|
|
39
|
+
# new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
|
|
40
|
+
# user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
|
|
41
|
+
# POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
|
|
42
|
+
#
|
|
43
|
+
# ==== Options
|
|
44
|
+
#
|
|
45
|
+
# You can configure your routes with some options:
|
|
46
|
+
#
|
|
47
|
+
# * :class_name => setup a different class to be looked up by devise,
|
|
48
|
+
# if it cannot be correctly find by the route name.
|
|
49
|
+
#
|
|
50
|
+
# devise_for :users, :class_name => 'Account'
|
|
51
|
+
#
|
|
52
|
+
# * :path => allows you to setup path name that will be used, as rails routes does.
|
|
53
|
+
# The following route configuration would setup your route as /accounts instead of /users:
|
|
54
|
+
#
|
|
55
|
+
# devise_for :users, :path => 'accounts'
|
|
56
|
+
#
|
|
57
|
+
# * :singular => setup the singular name for the given resource. This is used as the instance variable name in
|
|
58
|
+
# controller, as the name in routes and the scope given to warden.
|
|
59
|
+
#
|
|
60
|
+
# devise_for :users, :singular => :user
|
|
61
|
+
#
|
|
62
|
+
# * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
|
63
|
+
# :password, :confirmation, :unlock.
|
|
64
|
+
#
|
|
65
|
+
# devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
|
|
66
|
+
#
|
|
67
|
+
# * :controllers => the controller which should be used. All routes by default points to Devise controllers.
|
|
68
|
+
# However, if you want them to point to custom controller, you should do:
|
|
69
|
+
#
|
|
70
|
+
# devise_for :users, :controllers => { :sessions => "users/sessions" }
|
|
71
|
+
#
|
|
72
|
+
# * :sign_out_via => the HTTP method(s) accepted for the :sign_out action (default: :get),
|
|
73
|
+
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
|
74
|
+
#
|
|
75
|
+
# devise_for :users, :sign_out_via => [ :post, :delete ]
|
|
76
|
+
#
|
|
77
|
+
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
|
78
|
+
#
|
|
79
|
+
# * :module => the namespace to find controlers. By default, devise will access devise/sessions,
|
|
80
|
+
# devise/registrations and so on. If you want to namespace all at once, use module:
|
|
81
|
+
#
|
|
82
|
+
# devise_for :users, :module => "users"
|
|
83
|
+
#
|
|
84
|
+
# Notice that whenever you use namespace in the router DSL, it automatically sets the module.
|
|
85
|
+
# So the following setup:
|
|
86
|
+
#
|
|
87
|
+
# namespace :publisher
|
|
88
|
+
# devise_for :account
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# Will use publisher/sessions controller instead of devise/sessions controller. You can revert
|
|
92
|
+
# this by providing the :module option to devise_for.
|
|
93
|
+
#
|
|
94
|
+
# Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers
|
|
95
|
+
# and views. For example, using the above setup you'll end with following methods:
|
|
96
|
+
# current_publisher_account, authenticate_publisher_account!, pusblisher_account_signed_in, etc.
|
|
97
|
+
#
|
|
98
|
+
# * :skip => tell which controller you want to skip routes from being created:
|
|
99
|
+
#
|
|
100
|
+
# devise_for :users, :skip => :sessions
|
|
101
|
+
#
|
|
102
|
+
# ==== Scoping
|
|
103
|
+
#
|
|
104
|
+
# Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:
|
|
105
|
+
#
|
|
106
|
+
# scope "/my" do
|
|
107
|
+
# devise_for :users
|
|
108
|
+
# end
|
|
109
|
+
#
|
|
110
|
+
# However, since Devise uses the request path to retrieve the current user, it has one caveats.
|
|
111
|
+
# If you are using a dynamic segment, as below:
|
|
112
|
+
#
|
|
113
|
+
# scope ":locale" do
|
|
114
|
+
# devise_for :users
|
|
115
|
+
# end
|
|
116
|
+
#
|
|
117
|
+
# You are required to configure default_url_options in your ApplicationController class level, so
|
|
118
|
+
# Devise can pick it:
|
|
119
|
+
#
|
|
120
|
+
# class ApplicationController < ActionController::Base
|
|
121
|
+
# def self.default_url_options
|
|
122
|
+
# { :locale => I18n.locale }
|
|
123
|
+
# end
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
def devise_for(*resources)
|
|
127
|
+
options = resources.extract_options!
|
|
128
|
+
|
|
129
|
+
options[:as] ||= @scope[:as] if @scope[:as].present?
|
|
130
|
+
options[:module] ||= @scope[:module] if @scope[:module].present?
|
|
131
|
+
options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
|
|
132
|
+
options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
|
|
133
|
+
|
|
134
|
+
resources.map!(&:to_sym)
|
|
135
|
+
|
|
136
|
+
resources.each do |resource|
|
|
137
|
+
mapping = Devise.add_mapping(resource, options)
|
|
138
|
+
|
|
139
|
+
begin
|
|
140
|
+
raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)
|
|
141
|
+
rescue NameError => e
|
|
142
|
+
raise unless mapping.class_name == resource.to_s.classify
|
|
143
|
+
warn "[WARNING] You provided devise_for #{resource.inspect} but there is " <<
|
|
144
|
+
"no model #{mapping.class_name} defined in your application"
|
|
145
|
+
next
|
|
146
|
+
rescue NoMethodError => e
|
|
147
|
+
raise unless e.message.include?("undefined method `devise'")
|
|
148
|
+
raise_no_devise_method_error!(mapping.class_name)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
routes = mapping.routes
|
|
152
|
+
routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
|
|
153
|
+
|
|
154
|
+
devise_scope mapping.name do
|
|
155
|
+
yield if block_given?
|
|
156
|
+
with_devise_exclusive_scope mapping.fullpath, mapping.name do
|
|
157
|
+
routes.each { |mod| send(:"devise_#{mod}", mapping, mapping.controllers) }
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Allow you to add authentication request from the router:
|
|
164
|
+
#
|
|
165
|
+
# authenticate(:user) do
|
|
166
|
+
# resources :post
|
|
167
|
+
# end
|
|
168
|
+
#
|
|
169
|
+
def authenticate(scope)
|
|
170
|
+
constraint = lambda do |request|
|
|
171
|
+
request.env["warden"].authenticate!(:scope => scope)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
constraints(constraint) do
|
|
175
|
+
yield
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Sets the devise scope to be used in the controller. If you have custom routes,
|
|
180
|
+
# you are required to call this method (also aliased as :as) in order to specify
|
|
181
|
+
# to which controller it is targetted.
|
|
182
|
+
#
|
|
183
|
+
# as :user do
|
|
184
|
+
# get "sign_in", :to => "devise/sessions#new"
|
|
185
|
+
# end
|
|
186
|
+
#
|
|
187
|
+
# Notice you cannot have two scopes mapping to the same URL. And remember, if
|
|
188
|
+
# you try to access a devise controller without specifying a scope, it will
|
|
189
|
+
# raise ActionNotFound error.
|
|
190
|
+
def devise_scope(scope)
|
|
191
|
+
constraint = lambda do |request|
|
|
192
|
+
request.env["devise.mapping"] = Devise.mappings[scope]
|
|
193
|
+
true
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
constraints(constraint) do
|
|
197
|
+
yield
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
alias :as :devise_scope
|
|
201
|
+
|
|
202
|
+
protected
|
|
203
|
+
|
|
204
|
+
def devise_session(mapping, controllers) #:nodoc:
|
|
205
|
+
resource :session, :only => [], :controller => controllers[:sessions], :path => "" do
|
|
206
|
+
get :new, :path => mapping.path_names[:sign_in], :as => "new"
|
|
207
|
+
post :create, :path => mapping.path_names[:sign_in]
|
|
208
|
+
match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy", :via => mapping.sign_out_via
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def devise_password(mapping, controllers) #:nodoc:
|
|
213
|
+
resource :password, :only => [:new, :create, :edit, :update],
|
|
214
|
+
:path => mapping.path_names[:password], :controller => controllers[:passwords]
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def devise_confirmation(mapping, controllers) #:nodoc:
|
|
218
|
+
resource :confirmation, :only => [:new, :create, :show],
|
|
219
|
+
:path => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def devise_unlock(mapping, controllers) #:nodoc:
|
|
223
|
+
if mapping.to.unlock_strategy_enabled?(:email)
|
|
224
|
+
resource :unlock, :only => [:new, :create, :show],
|
|
225
|
+
:path => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def devise_registration(mapping, controllers) #:nodoc:
|
|
230
|
+
path_names = {
|
|
231
|
+
:new => mapping.path_names[:sign_up],
|
|
232
|
+
:cancel => mapping.path_names[:cancel]
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
resource :registration, :except => :show, :path => mapping.path_names[:registration],
|
|
236
|
+
:path_names => path_names, :controller => controllers[:registrations] do
|
|
237
|
+
get :cancel
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def devise_oauth_callback(mapping, controllers) #:nodoc:
|
|
242
|
+
get "/oauth/:action/callback", :action => Regexp.union(mapping.to.oauth_providers.map(&:to_s)),
|
|
243
|
+
:to => controllers[:oauth_callbacks], :as => :oauth_callback
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def with_devise_exclusive_scope(new_path, new_as) #:nodoc:
|
|
247
|
+
old_as, old_path, old_module = @scope[:as], @scope[:path], @scope[:module]
|
|
248
|
+
@scope[:as], @scope[:path], @scope[:module] = new_as, new_path, nil
|
|
249
|
+
yield
|
|
250
|
+
ensure
|
|
251
|
+
@scope[:as], @scope[:path], @scope[:module] = old_as, old_path, old_module
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def raise_no_devise_method_error!(klass) #:nodoc:
|
|
255
|
+
raise "#{klass} does not respond to 'devise' method. This usually means you haven't " <<
|
|
256
|
+
"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " <<
|
|
257
|
+
"inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'"
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|