devise 2.1.2 → 3.5.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
data/lib/devise/rails/routes.rb
CHANGED
@@ -43,103 +43,132 @@ module ActionDispatch::Routing
|
|
43
43
|
# needed routes:
|
44
44
|
#
|
45
45
|
# # Session routes for Authenticatable (default)
|
46
|
-
# new_user_session GET
|
47
|
-
# user_session POST
|
48
|
-
# destroy_user_session
|
46
|
+
# new_user_session GET /users/sign_in {controller:"devise/sessions", action:"new"}
|
47
|
+
# user_session POST /users/sign_in {controller:"devise/sessions", action:"create"}
|
48
|
+
# destroy_user_session DELETE /users/sign_out {controller:"devise/sessions", action:"destroy"}
|
49
49
|
#
|
50
50
|
# # Password routes for Recoverable, if User model has :recoverable configured
|
51
|
-
# new_user_password GET
|
52
|
-
# edit_user_password GET
|
53
|
-
# user_password PUT
|
54
|
-
# POST
|
51
|
+
# new_user_password GET /users/password/new(.:format) {controller:"devise/passwords", action:"new"}
|
52
|
+
# edit_user_password GET /users/password/edit(.:format) {controller:"devise/passwords", action:"edit"}
|
53
|
+
# user_password PUT /users/password(.:format) {controller:"devise/passwords", action:"update"}
|
54
|
+
# POST /users/password(.:format) {controller:"devise/passwords", action:"create"}
|
55
55
|
#
|
56
56
|
# # Confirmation routes for Confirmable, if User model has :confirmable configured
|
57
|
-
# new_user_confirmation GET
|
58
|
-
# user_confirmation GET
|
59
|
-
# POST
|
57
|
+
# new_user_confirmation GET /users/confirmation/new(.:format) {controller:"devise/confirmations", action:"new"}
|
58
|
+
# user_confirmation GET /users/confirmation(.:format) {controller:"devise/confirmations", action:"show"}
|
59
|
+
# POST /users/confirmation(.:format) {controller:"devise/confirmations", action:"create"}
|
60
|
+
#
|
61
|
+
# ==== Routes integration
|
62
|
+
#
|
63
|
+
# +devise_for+ is meant to play nicely with other routes methods. For example,
|
64
|
+
# by calling +devise_for+ inside a namespace, it automatically nests your devise
|
65
|
+
# controllers:
|
66
|
+
#
|
67
|
+
# namespace :publisher do
|
68
|
+
# devise_for :account
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# The snippet above will use publisher/sessions controller instead of devise/sessions
|
72
|
+
# controller. You can revert this change or configure it directly by passing the :module
|
73
|
+
# option described below to +devise_for+.
|
74
|
+
#
|
75
|
+
# Also note that when you use a namespace it will affect all the helpers and methods
|
76
|
+
# for controllers and views. For example, using the above setup you'll end with
|
77
|
+
# following methods: current_publisher_account, authenticate_publisher_account!,
|
78
|
+
# publisher_account_signed_in, etc.
|
79
|
+
#
|
80
|
+
# The only aspect not affect by the router configuration is the model name. The
|
81
|
+
# model name can be explicitly set via the :class_name option.
|
60
82
|
#
|
61
83
|
# ==== Options
|
62
84
|
#
|
63
85
|
# You can configure your routes with some options:
|
64
86
|
#
|
65
|
-
# * :
|
87
|
+
# * class_name: setup a different class to be looked up by devise, if it cannot be
|
66
88
|
# properly found by the route name.
|
67
89
|
#
|
68
|
-
# devise_for :users, :
|
90
|
+
# devise_for :users, class_name: 'Account'
|
69
91
|
#
|
70
|
-
# * :
|
92
|
+
# * path: allows you to setup path name that will be used, as rails routes does.
|
71
93
|
# The following route configuration would setup your route as /accounts instead of /users:
|
72
94
|
#
|
73
|
-
# devise_for :users, :
|
95
|
+
# devise_for :users, path: 'accounts'
|
96
|
+
#
|
97
|
+
# * singular: setup the singular name for the given resource. This is used as the helper methods
|
98
|
+
# names in controller ("authenticate_#{singular}!", "#{singular}_signed_in?", "current_#{singular}"
|
99
|
+
# and "#{singular}_session"), as the scope name in routes and as the scope given to warden.
|
100
|
+
#
|
101
|
+
# devise_for :admins, singular: :manager
|
74
102
|
#
|
75
|
-
#
|
76
|
-
#
|
103
|
+
# devise_scope :manager do
|
104
|
+
# ...
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# class ManagerController < ApplicationController
|
108
|
+
# before_filter authenticate_manager!
|
77
109
|
#
|
78
|
-
#
|
110
|
+
# def show
|
111
|
+
# @manager = current_manager
|
112
|
+
# ...
|
113
|
+
# end
|
114
|
+
# end
|
79
115
|
#
|
80
|
-
# * :
|
116
|
+
# * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
81
117
|
# :password, :confirmation, :unlock.
|
82
118
|
#
|
83
|
-
# devise_for :users, :
|
119
|
+
# devise_for :users, path_names: {
|
120
|
+
# sign_in: 'login', sign_out: 'logout',
|
121
|
+
# password: 'secret', confirmation: 'verification',
|
122
|
+
# registration: 'register', edit: 'edit/profile'
|
123
|
+
# }
|
84
124
|
#
|
85
|
-
# * :
|
125
|
+
# * controllers: the controller which should be used. All routes by default points to Devise controllers.
|
86
126
|
# However, if you want them to point to custom controller, you should do:
|
87
127
|
#
|
88
|
-
# devise_for :users, :
|
128
|
+
# devise_for :users, controllers: { sessions: "users/sessions" }
|
89
129
|
#
|
90
|
-
# * :
|
130
|
+
# * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given
|
91
131
|
# are also allowed as parameter.
|
92
132
|
#
|
93
|
-
# * :
|
133
|
+
# * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :get),
|
94
134
|
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
95
135
|
#
|
96
|
-
# devise_for :users, :
|
136
|
+
# devise_for :users, sign_out_via: [:post, :delete]
|
97
137
|
#
|
98
138
|
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
99
139
|
#
|
100
|
-
# * :
|
140
|
+
# * module: the namespace to find controllers (default: "devise", thus
|
101
141
|
# accessing devise/sessions, devise/registrations, and so on). If you want
|
102
142
|
# to namespace all at once, use module:
|
103
143
|
#
|
104
|
-
# devise_for :users, :
|
144
|
+
# devise_for :users, module: "users"
|
105
145
|
#
|
106
|
-
#
|
107
|
-
#
|
146
|
+
# * skip: tell which controller you want to skip routes from being created.
|
147
|
+
# It accepts :all as an option, meaning it will not generate any route at all:
|
108
148
|
#
|
109
|
-
#
|
110
|
-
# devise_for :account
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# Will use publisher/sessions controller instead of devise/sessions controller. You can revert
|
114
|
-
# this by providing the :module option to devise_for.
|
115
|
-
#
|
116
|
-
# Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers
|
117
|
-
# and views. For example, using the above setup you'll end with following methods:
|
118
|
-
# current_publisher_account, authenticate_publisher_account!, publisher_account_signed_in, etc.
|
149
|
+
# devise_for :users, skip: :sessions
|
119
150
|
#
|
120
|
-
# * :skip
|
151
|
+
# * only: the opposite of :skip, tell which controllers only to generate routes to:
|
121
152
|
#
|
122
|
-
# devise_for :users, :
|
153
|
+
# devise_for :users, only: :sessions
|
123
154
|
#
|
124
|
-
# * :
|
125
|
-
#
|
126
|
-
# devise_for :users, :only => :sessions
|
127
|
-
#
|
128
|
-
# * :skip_helpers => skip generating Devise url helpers like new_session_path(@user).
|
155
|
+
# * skip_helpers: skip generating Devise url helpers like new_session_path(@user).
|
129
156
|
# This is useful to avoid conflicts with previous routes and is false by default.
|
130
157
|
# It accepts true as option, meaning it will skip all the helpers for the controllers
|
131
158
|
# given in :skip but it also accepts specific helpers to be skipped:
|
132
159
|
#
|
133
|
-
# devise_for :users, :
|
134
|
-
# devise_for :users, :
|
160
|
+
# devise_for :users, skip: [:registrations, :confirmations], skip_helpers: true
|
161
|
+
# devise_for :users, skip_helpers: [:registrations, :confirmations]
|
162
|
+
#
|
163
|
+
# * format: include "(.:format)" in the generated routes? true by default, set to false to disable:
|
135
164
|
#
|
136
|
-
#
|
165
|
+
# devise_for :users, format: false
|
137
166
|
#
|
138
|
-
#
|
167
|
+
# * constraints: works the same as Rails' constraints
|
139
168
|
#
|
140
|
-
# * :
|
169
|
+
# * defaults: works the same as Rails' defaults
|
141
170
|
#
|
142
|
-
# * :
|
171
|
+
# * router_name: allows application level router name to be overwritten for the current scope
|
143
172
|
#
|
144
173
|
# ==== Scoping
|
145
174
|
#
|
@@ -161,7 +190,7 @@ module ActionDispatch::Routing
|
|
161
190
|
#
|
162
191
|
# class ApplicationController < ActionController::Base
|
163
192
|
# def self.default_url_options
|
164
|
-
# { :
|
193
|
+
# { locale: I18n.locale }
|
165
194
|
# end
|
166
195
|
# end
|
167
196
|
#
|
@@ -183,14 +212,15 @@ module ActionDispatch::Routing
|
|
183
212
|
# end
|
184
213
|
# end
|
185
214
|
#
|
186
|
-
# In order to get Devise to recognize the deactivate action, your
|
215
|
+
# In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:
|
187
216
|
#
|
188
217
|
# devise_scope :owner do
|
189
|
-
# post "deactivate", :
|
218
|
+
# post "deactivate", to: "registrations#deactivate", as: "deactivate_registration"
|
190
219
|
# end
|
191
220
|
#
|
192
221
|
def devise_for(*resources)
|
193
222
|
@devise_finalized = false
|
223
|
+
raise_no_secret_key unless Devise.secret_key
|
194
224
|
options = resources.extract_options!
|
195
225
|
|
196
226
|
options[:as] ||= @scope[:as] if @scope[:as].present?
|
@@ -211,7 +241,7 @@ module ActionDispatch::Routing
|
|
211
241
|
raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)
|
212
242
|
rescue NameError => e
|
213
243
|
raise unless mapping.class_name == resource.to_s.classify
|
214
|
-
warn "[WARNING] You provided devise_for #{resource.inspect} but there is "
|
244
|
+
warn "[WARNING] You provided devise_for #{resource.inspect} but there is " \
|
215
245
|
"no model #{mapping.class_name} defined in your application"
|
216
246
|
next
|
217
247
|
rescue NoMethodError => e
|
@@ -219,17 +249,16 @@ module ActionDispatch::Routing
|
|
219
249
|
raise_no_devise_method_error!(mapping.class_name)
|
220
250
|
end
|
221
251
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
ActiveSupport::Deprecation.warn "Passing a block to devise_for is deprecated. " \
|
227
|
-
"Please remove the block from devise_for (only the block, the call to " \
|
228
|
-
"devise_for must still exist) and call devise_scope :#{mapping.name} do ... end " \
|
229
|
-
"with the block instead", caller
|
230
|
-
yield
|
252
|
+
if options[:controllers] && options[:controllers][:omniauth_callbacks]
|
253
|
+
unless mapping.omniauthable?
|
254
|
+
raise ArgumentError, "Mapping omniauth_callbacks on a resource that is not omniauthable\n" \
|
255
|
+
"Please add `devise :omniauthable` to the `#{mapping.class_name}` model"
|
231
256
|
end
|
257
|
+
end
|
232
258
|
|
259
|
+
routes = mapping.used_routes
|
260
|
+
|
261
|
+
devise_scope mapping.name do
|
233
262
|
with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
|
234
263
|
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
|
235
264
|
end
|
@@ -250,15 +279,11 @@ module ActionDispatch::Routing
|
|
250
279
|
# end
|
251
280
|
#
|
252
281
|
# authenticate :user, lambda {|u| u.role == "admin"} do
|
253
|
-
# root :
|
282
|
+
# root to: "admin/dashboard#show", as: :user_root
|
254
283
|
# end
|
255
284
|
#
|
256
285
|
def authenticate(scope=nil, block=nil)
|
257
|
-
|
258
|
-
request.env["warden"].authenticate!(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope)))
|
259
|
-
end
|
260
|
-
|
261
|
-
constraints(constraint) do
|
286
|
+
constraints_for(:authenticate!, scope, block) do
|
262
287
|
yield
|
263
288
|
end
|
264
289
|
end
|
@@ -268,25 +293,21 @@ module ActionDispatch::Routing
|
|
268
293
|
# a model and allows extra constraints to be done on the instance.
|
269
294
|
#
|
270
295
|
# authenticated :admin do
|
271
|
-
# root :
|
296
|
+
# root to: 'admin/dashboard#show', as: :admin_root
|
272
297
|
# end
|
273
298
|
#
|
274
299
|
# authenticated do
|
275
|
-
# root :
|
300
|
+
# root to: 'dashboard#show', as: :authenticated_root
|
276
301
|
# end
|
277
302
|
#
|
278
303
|
# authenticated :user, lambda {|u| u.role == "admin"} do
|
279
|
-
# root :
|
304
|
+
# root to: "admin/dashboard#show", as: :user_root
|
280
305
|
# end
|
281
306
|
#
|
282
|
-
# root :
|
307
|
+
# root to: 'landing#show'
|
283
308
|
#
|
284
309
|
def authenticated(scope=nil, block=nil)
|
285
|
-
|
286
|
-
request.env["warden"].authenticate?(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope)))
|
287
|
-
end
|
288
|
-
|
289
|
-
constraints(constraint) do
|
310
|
+
constraints_for(:authenticate?, scope, block) do
|
290
311
|
yield
|
291
312
|
end
|
292
313
|
end
|
@@ -296,15 +317,15 @@ module ActionDispatch::Routing
|
|
296
317
|
#
|
297
318
|
# unauthenticated do
|
298
319
|
# as :user do
|
299
|
-
# root :
|
320
|
+
# root to: 'devise/registrations#new'
|
300
321
|
# end
|
301
322
|
# end
|
302
323
|
#
|
303
|
-
# root :
|
324
|
+
# root to: 'dashboard#show'
|
304
325
|
#
|
305
326
|
def unauthenticated(scope=nil)
|
306
327
|
constraint = lambda do |request|
|
307
|
-
not request.env["warden"].authenticate? :
|
328
|
+
not request.env["warden"].authenticate? scope: scope
|
308
329
|
end
|
309
330
|
|
310
331
|
constraints(constraint) do
|
@@ -317,7 +338,7 @@ module ActionDispatch::Routing
|
|
317
338
|
# to which controller it is targetted.
|
318
339
|
#
|
319
340
|
# as :user do
|
320
|
-
# get "sign_in", :
|
341
|
+
# get "sign_in", to: "devise/sessions#new"
|
321
342
|
# end
|
322
343
|
#
|
323
344
|
# Notice you cannot have two scopes mapping to the same URL. And remember, if
|
@@ -329,7 +350,7 @@ module ActionDispatch::Routing
|
|
329
350
|
# good and working example.
|
330
351
|
#
|
331
352
|
# devise_scope :user do
|
332
|
-
#
|
353
|
+
# get "/some/route" => "some_devise_controller"
|
333
354
|
# end
|
334
355
|
# devise_for :users
|
335
356
|
#
|
@@ -349,41 +370,42 @@ module ActionDispatch::Routing
|
|
349
370
|
protected
|
350
371
|
|
351
372
|
def devise_session(mapping, controllers) #:nodoc:
|
352
|
-
resource :session, :
|
353
|
-
get :new, :
|
354
|
-
post :create, :
|
355
|
-
match :destroy, :
|
373
|
+
resource :session, only: [], controller: controllers[:sessions], path: "" do
|
374
|
+
get :new, path: mapping.path_names[:sign_in], as: "new"
|
375
|
+
post :create, path: mapping.path_names[:sign_in]
|
376
|
+
match :destroy, path: mapping.path_names[:sign_out], as: "destroy", via: mapping.sign_out_via
|
356
377
|
end
|
357
378
|
end
|
358
379
|
|
359
380
|
def devise_password(mapping, controllers) #:nodoc:
|
360
|
-
resource :password, :
|
361
|
-
:
|
381
|
+
resource :password, only: [:new, :create, :edit, :update],
|
382
|
+
path: mapping.path_names[:password], controller: controllers[:passwords]
|
362
383
|
end
|
363
384
|
|
364
385
|
def devise_confirmation(mapping, controllers) #:nodoc:
|
365
|
-
resource :confirmation, :
|
366
|
-
:
|
386
|
+
resource :confirmation, only: [:new, :create, :show],
|
387
|
+
path: mapping.path_names[:confirmation], controller: controllers[:confirmations]
|
367
388
|
end
|
368
389
|
|
369
390
|
def devise_unlock(mapping, controllers) #:nodoc:
|
370
391
|
if mapping.to.unlock_strategy_enabled?(:email)
|
371
|
-
resource :unlock, :
|
372
|
-
:
|
392
|
+
resource :unlock, only: [:new, :create, :show],
|
393
|
+
path: mapping.path_names[:unlock], controller: controllers[:unlocks]
|
373
394
|
end
|
374
395
|
end
|
375
396
|
|
376
397
|
def devise_registration(mapping, controllers) #:nodoc:
|
377
398
|
path_names = {
|
378
|
-
:
|
379
|
-
:
|
399
|
+
new: mapping.path_names[:sign_up],
|
400
|
+
edit: mapping.path_names[:edit],
|
401
|
+
cancel: mapping.path_names[:cancel]
|
380
402
|
}
|
381
403
|
|
382
404
|
options = {
|
383
|
-
:
|
384
|
-
:
|
385
|
-
:
|
386
|
-
:
|
405
|
+
only: [:new, :create, :edit, :update, :destroy],
|
406
|
+
path: mapping.path_names[:registration],
|
407
|
+
path_names: path_names,
|
408
|
+
controller: controllers[:registrations]
|
387
409
|
}
|
388
410
|
|
389
411
|
resource :registration, options do
|
@@ -392,38 +414,64 @@ module ActionDispatch::Routing
|
|
392
414
|
end
|
393
415
|
|
394
416
|
def devise_omniauth_callback(mapping, controllers) #:nodoc:
|
417
|
+
if mapping.fullpath =~ /:[a-zA-Z_]/
|
418
|
+
raise <<-ERROR
|
419
|
+
Devise does not support scoping OmniAuth callbacks under a dynamic segment
|
420
|
+
and you have set #{mapping.fullpath.inspect}. You can work around by passing
|
421
|
+
`skip: :omniauth_callbacks` to the `devise_for` call and extract omniauth
|
422
|
+
options to another `devise_for` call outside the scope. Here is an example:
|
423
|
+
|
424
|
+
devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'users/omniauth_callbacks'}
|
425
|
+
|
426
|
+
scope '/(:locale)', locale: /ru|en/ do
|
427
|
+
devise_for :users, skip: :omniauth_callbacks
|
428
|
+
end
|
429
|
+
ERROR
|
430
|
+
end
|
431
|
+
|
395
432
|
path, @scope[:path] = @scope[:path], nil
|
396
|
-
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.
|
433
|
+
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/")
|
434
|
+
|
397
435
|
set_omniauth_path_prefix!(path_prefix)
|
398
436
|
|
399
437
|
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
|
400
438
|
|
401
439
|
match "#{path_prefix}/:provider",
|
402
|
-
:
|
403
|
-
:
|
404
|
-
:
|
440
|
+
constraints: { provider: providers },
|
441
|
+
to: "#{controllers[:omniauth_callbacks]}#passthru",
|
442
|
+
as: :omniauth_authorize,
|
443
|
+
via: [:get, :post]
|
405
444
|
|
406
445
|
match "#{path_prefix}/:action/callback",
|
407
|
-
:
|
408
|
-
:
|
409
|
-
:
|
446
|
+
constraints: { action: providers },
|
447
|
+
to: "#{controllers[:omniauth_callbacks]}#:action",
|
448
|
+
as: :omniauth_callback,
|
449
|
+
via: [:get, :post]
|
410
450
|
ensure
|
411
451
|
@scope[:path] = path
|
412
452
|
end
|
413
453
|
|
414
|
-
DEVISE_SCOPE_KEYS = [:as, :path, :module, :constraints, :defaults, :options]
|
415
|
-
|
416
454
|
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
|
417
|
-
|
418
|
-
DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] }
|
455
|
+
current_scope = @scope.dup
|
419
456
|
|
420
|
-
|
421
|
-
|
457
|
+
exclusive = { as: new_as, path: new_path, module: nil }
|
458
|
+
exclusive.merge!(options.slice(:constraints, :defaults, :options))
|
422
459
|
|
423
|
-
@scope
|
460
|
+
exclusive.each_pair { |key, value| @scope[key] = value }
|
424
461
|
yield
|
425
462
|
ensure
|
426
|
-
@scope
|
463
|
+
@scope = current_scope
|
464
|
+
end
|
465
|
+
|
466
|
+
def constraints_for(method_to_apply, scope=nil, block=nil)
|
467
|
+
constraint = lambda do |request|
|
468
|
+
request.env['warden'].send(method_to_apply, scope: scope) &&
|
469
|
+
(block.nil? || block.call(request.env["warden"].user(scope)))
|
470
|
+
end
|
471
|
+
|
472
|
+
constraints(constraint) do
|
473
|
+
yield
|
474
|
+
end
|
427
475
|
end
|
428
476
|
|
429
477
|
def set_omniauth_path_prefix!(path_prefix) #:nodoc:
|
@@ -437,6 +485,16 @@ module ActionDispatch::Routing
|
|
437
485
|
end
|
438
486
|
end
|
439
487
|
|
488
|
+
def raise_no_secret_key #:nodoc:
|
489
|
+
raise <<-ERROR
|
490
|
+
Devise.secret_key was not set. Please add the following to your Devise initializer:
|
491
|
+
|
492
|
+
config.secret_key = '#{SecureRandom.hex(64)}'
|
493
|
+
|
494
|
+
Please ensure you restarted your application after installing Devise or setting the key.
|
495
|
+
ERROR
|
496
|
+
end
|
497
|
+
|
440
498
|
def raise_no_devise_method_error!(klass) #:nodoc:
|
441
499
|
raise "#{klass} does not respond to 'devise' method. This usually means you haven't " \
|
442
500
|
"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " \
|