devise 3.2.0 → 3.3.0
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.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +18 -3
- data/CHANGELOG.md +82 -9
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +7 -9
- data/Gemfile.lock +102 -96
- data/MIT-LICENSE +1 -1
- data/README.md +94 -42
- data/Rakefile +1 -1
- data/app/controllers/devise/confirmations_controller.rb +5 -3
- data/app/controllers/devise/omniauth_callbacks_controller.rb +2 -2
- data/app/controllers/devise/passwords_controller.rb +5 -3
- data/app/controllers/devise/registrations_controller.rb +26 -10
- data/app/controllers/devise/sessions_controller.rb +39 -14
- data/app/controllers/devise/unlocks_controller.rb +4 -2
- data/app/controllers/devise_controller.rb +6 -6
- data/app/helpers/devise_helper.rb +2 -2
- data/app/views/devise/confirmations/new.html.erb +2 -2
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +6 -6
- data/app/views/devise/registrations/new.html.erb +5 -5
- data/app/views/devise/sessions/new.html.erb +5 -5
- data/app/views/devise/shared/_links.erb +1 -1
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +17 -16
- data/devise.gemspec +2 -2
- data/gemfiles/{Gemfile.rails-3.2.x → Gemfile.rails-3.2-stable} +8 -10
- data/gemfiles/Gemfile.rails-3.2-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.0-stable +29 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +162 -0
- data/gemfiles/Gemfile.rails-head +32 -0
- data/gemfiles/Gemfile.rails-head.lock +190 -0
- data/lib/devise/controllers/helpers.rb +84 -29
- data/lib/devise/controllers/rememberable.rb +3 -3
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +9 -10
- data/lib/devise/controllers/store_location.rb +56 -0
- data/lib/devise/controllers/url_helpers.rb +3 -1
- data/lib/devise/failure_app.rb +12 -10
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +3 -1
- data/lib/devise/hooks/lockable.rb +1 -1
- data/lib/devise/hooks/proxy.rb +2 -2
- data/lib/devise/hooks/rememberable.rb +2 -2
- data/lib/devise/hooks/timeoutable.rb +10 -3
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +8 -8
- data/lib/devise/mapping.rb +4 -1
- data/lib/devise/models/authenticatable.rb +5 -5
- data/lib/devise/models/confirmable.rb +14 -14
- data/lib/devise/models/database_authenticatable.rb +18 -5
- data/lib/devise/models/lockable.rb +14 -11
- data/lib/devise/models/omniauthable.rb +1 -1
- data/lib/devise/models/recoverable.rb +23 -7
- data/lib/devise/models/rememberable.rb +6 -6
- data/lib/devise/models/timeoutable.rb +2 -2
- data/lib/devise/models/trackable.rb +5 -2
- data/lib/devise/models/validatable.rb +6 -6
- data/lib/devise/modules.rb +10 -10
- 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/rails/routes.rb +107 -78
- data/lib/devise/rails.rb +7 -1
- data/lib/devise/strategies/authenticatable.rb +11 -4
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +7 -4
- data/lib/devise/test_helpers.rb +2 -2
- data/lib/devise/time_inflector.rb +2 -2
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +15 -10
- data/lib/generators/active_record/devise_generator.rb +27 -10
- data/lib/generators/active_record/templates/migration.rb +4 -4
- data/lib/generators/active_record/templates/migration_existing.rb +4 -4
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/views_generator.rb +31 -18
- data/lib/generators/mongoid/devise_generator.rb +20 -19
- data/lib/generators/templates/README +4 -4
- data/lib/generators/templates/devise.rb +20 -11
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +2 -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 +6 -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 +4 -4
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +2 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +35 -0
- data/test/controllers/helpers_test.rb +89 -31
- data/test/controllers/internal_helpers_test.rb +11 -8
- data/test/controllers/passwords_controller_test.rb +1 -1
- data/test/controllers/sessions_controller_test.rb +29 -25
- data/test/controllers/url_helpers_test.rb +4 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +21 -8
- data/test/failure_app_test.rb +61 -25
- data/test/generators/active_record_generator_test.rb +10 -4
- 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 +30 -1
- data/test/helpers/devise_helper_test.rb +14 -13
- data/test/integration/authenticatable_test.rb +61 -45
- data/test/integration/confirmable_test.rb +95 -55
- data/test/integration/database_authenticatable_test.rb +16 -16
- data/test/integration/http_authenticatable_test.rb +12 -12
- data/test/integration/lockable_test.rb +43 -43
- data/test/integration/omniauthable_test.rb +3 -3
- data/test/integration/recoverable_test.rb +53 -53
- data/test/integration/registerable_test.rb +90 -80
- data/test/integration/rememberable_test.rb +15 -15
- data/test/integration/timeoutable_test.rb +27 -16
- data/test/integration/trackable_test.rb +4 -4
- data/test/mailers/confirmation_instructions_test.rb +7 -7
- data/test/mailers/reset_password_instructions_test.rb +6 -6
- data/test/mailers/unlock_instructions_test.rb +5 -5
- data/test/mapping_test.rb +3 -3
- data/test/models/authenticatable_test.rb +3 -3
- data/test/models/confirmable_test.rb +32 -32
- data/test/models/database_authenticatable_test.rb +32 -27
- data/test/models/lockable_test.rb +57 -33
- data/test/models/recoverable_test.rb +34 -22
- data/test/models/rememberable_test.rb +29 -14
- data/test/models/serializable_test.rb +8 -8
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +13 -13
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +3 -3
- data/test/orm/mongoid.rb +1 -1
- data/test/parameter_sanitizer_test.rb +1 -1
- 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/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +1 -1
- data/test/rails_app/app/controllers/application_controller.rb +5 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -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 +6 -6
- data/test/rails_app/app/mailers/users/mailer.rb +4 -4
- data/test/rails_app/app/mongoid/admin.rb +11 -11
- data/test/rails_app/app/mongoid/shim.rb +2 -2
- data/test/rails_app/app/mongoid/user.rb +19 -19
- 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/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/config/application.rb +2 -2
- data/test/rails_app/config/boot.rb +7 -1
- data/test/rails_app/config/environments/development.rb +0 -4
- data/test/rails_app/config/environments/production.rb +0 -4
- data/test/rails_app/config/initializers/devise.rb +7 -5
- data/test/rails_app/config/initializers/secret_token.rb +1 -1
- data/test/rails_app/config/routes.rb +60 -42
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +7 -7
- data/test/rails_app/db/schema.rb +21 -17
- data/test/rails_app/lib/shared_admin.rb +4 -4
- data/test/rails_app/lib/shared_user.rb +1 -1
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/routes_test.rb +72 -58
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +4 -4
- data/test/support/integration.rb +14 -14
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +2 -7
- data/test/test_helpers_test.rb +25 -35
- data/test/test_models.rb +12 -5
- metadata +53 -38
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
data/lib/devise/modules.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'active_support/core_ext/object/with_options'
|
2
2
|
|
3
|
-
Devise.with_options :
|
3
|
+
Devise.with_options model: true do |d|
|
4
4
|
# Strategies first
|
5
|
-
d.with_options :
|
5
|
+
d.with_options strategy: true do |s|
|
6
6
|
routes = [nil, :new, :destroy]
|
7
|
-
s.add_module :database_authenticatable, :
|
8
|
-
s.add_module :rememberable, :
|
7
|
+
s.add_module :database_authenticatable, controller: :sessions, route: { session: routes }
|
8
|
+
s.add_module :rememberable, no_input: true
|
9
9
|
end
|
10
10
|
|
11
11
|
# Other authentications
|
12
|
-
d.add_module :omniauthable, :
|
12
|
+
d.add_module :omniauthable, controller: :omniauth_callbacks, route: :omniauth_callback
|
13
13
|
|
14
14
|
# Misc after
|
15
15
|
routes = [nil, :new, :edit]
|
16
|
-
d.add_module :recoverable, :
|
17
|
-
d.add_module :registerable, :
|
16
|
+
d.add_module :recoverable, controller: :passwords, route: { password: routes }
|
17
|
+
d.add_module :registerable, controller: :registrations, route: { registration: (routes << :cancel) }
|
18
18
|
d.add_module :validatable
|
19
19
|
|
20
20
|
# The ones which can sign out after
|
21
21
|
routes = [nil, :new]
|
22
|
-
d.add_module :confirmable, :
|
23
|
-
d.add_module :lockable, :
|
22
|
+
d.add_module :confirmable, controller: :confirmations, route: { confirmation: routes }
|
23
|
+
d.add_module :lockable, controller: :unlocks, route: { unlock: routes }
|
24
24
|
d.add_module :timeoutable
|
25
25
|
|
26
26
|
# Stats for last, so we make sure the user is really signed in
|
27
27
|
d.add_module :trackable
|
28
|
-
end
|
28
|
+
end
|
@@ -6,12 +6,12 @@ module Devise
|
|
6
6
|
|
7
7
|
def omniauth_authorize_path(resource_or_scope, *args)
|
8
8
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
9
|
-
send("#{scope}_omniauth_authorize_path", *args)
|
9
|
+
_devise_route_context.send("#{scope}_omniauth_authorize_path", *args)
|
10
10
|
end
|
11
11
|
|
12
12
|
def omniauth_callback_path(resource_or_scope, *args)
|
13
13
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
14
|
-
send("#{scope}_omniauth_callback_path", *args)
|
14
|
+
_devise_route_context.send("#{scope}_omniauth_callback_path", *args)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/devise/orm/mongoid.rb
CHANGED
data/lib/devise/rails/routes.rb
CHANGED
@@ -43,20 +43,20 @@ module ActionDispatch::Routing
|
|
43
43
|
# needed routes:
|
44
44
|
#
|
45
45
|
# # Session routes for Authenticatable (default)
|
46
|
-
# new_user_session GET /users/sign_in {:
|
47
|
-
# user_session POST /users/sign_in {:
|
48
|
-
# destroy_user_session DELETE /users/sign_out {:
|
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 /users/password/new(.:format) {:
|
52
|
-
# edit_user_password GET /users/password/edit(.:format) {:
|
53
|
-
# user_password PUT /users/password(.:format) {:
|
54
|
-
# POST /users/password(.:format) {:
|
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 /users/confirmation/new(.:format) {:
|
58
|
-
# user_confirmation GET /users/confirmation(.:format) {:
|
59
|
-
# POST /users/confirmation(.:format) {:
|
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
60
|
#
|
61
61
|
# ==== Routes integration
|
62
62
|
#
|
@@ -84,71 +84,77 @@ module ActionDispatch::Routing
|
|
84
84
|
#
|
85
85
|
# You can configure your routes with some options:
|
86
86
|
#
|
87
|
-
# * :
|
87
|
+
# * class_name: setup a different class to be looked up by devise, if it cannot be
|
88
88
|
# properly found by the route name.
|
89
89
|
#
|
90
|
-
# devise_for :users, :
|
90
|
+
# devise_for :users, class_name: 'Account'
|
91
91
|
#
|
92
|
-
# * :
|
92
|
+
# * path: allows you to setup path name that will be used, as rails routes does.
|
93
93
|
# The following route configuration would setup your route as /accounts instead of /users:
|
94
94
|
#
|
95
|
-
# devise_for :users, :
|
95
|
+
# devise_for :users, path: 'accounts'
|
96
96
|
#
|
97
|
-
# * :
|
97
|
+
# * singular: setup the singular name for the given resource. This is used as the instance variable
|
98
98
|
# name in controller, as the name in routes and the scope given to warden.
|
99
99
|
#
|
100
|
-
# devise_for :users, :
|
100
|
+
# devise_for :users, singular: :user
|
101
101
|
#
|
102
|
-
# * :
|
102
|
+
# * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
103
103
|
# :password, :confirmation, :unlock.
|
104
104
|
#
|
105
|
-
# devise_for :users, :
|
106
|
-
# :
|
105
|
+
# devise_for :users, path_names: {
|
106
|
+
# sign_in: 'login', sign_out: 'logout',
|
107
|
+
# password: 'secret', confirmation: 'verification',
|
108
|
+
# registration: 'register', edit: 'edit/profile'
|
109
|
+
# }
|
107
110
|
#
|
108
|
-
# * :
|
111
|
+
# * controllers: the controller which should be used. All routes by default points to Devise controllers.
|
109
112
|
# However, if you want them to point to custom controller, you should do:
|
110
113
|
#
|
111
|
-
# devise_for :users, :
|
114
|
+
# devise_for :users, controllers: { sessions: "users/sessions" }
|
112
115
|
#
|
113
|
-
# * :
|
116
|
+
# * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given
|
114
117
|
# are also allowed as parameter.
|
115
118
|
#
|
116
|
-
# * :
|
119
|
+
# * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :get),
|
117
120
|
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
118
121
|
#
|
119
|
-
# devise_for :users, :
|
122
|
+
# devise_for :users, sign_out_via: [ :post, :delete ]
|
120
123
|
#
|
121
124
|
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
122
125
|
#
|
123
|
-
# * :
|
126
|
+
# * module: the namespace to find controllers (default: "devise", thus
|
124
127
|
# accessing devise/sessions, devise/registrations, and so on). If you want
|
125
128
|
# to namespace all at once, use module:
|
126
129
|
#
|
127
|
-
# devise_for :users, :
|
130
|
+
# devise_for :users, module: "users"
|
128
131
|
#
|
129
|
-
# * :
|
132
|
+
# * skip: tell which controller you want to skip routes from being created.
|
133
|
+
# It accepts :all as an option, meaning it will not generate any route at all:
|
130
134
|
#
|
131
|
-
# devise_for :users, :
|
135
|
+
# devise_for :users, skip: :sessions
|
132
136
|
#
|
133
|
-
# * :
|
137
|
+
# * only: the opposite of :skip, tell which controllers only to generate routes to:
|
134
138
|
#
|
135
|
-
# devise_for :users, :
|
139
|
+
# devise_for :users, only: :sessions
|
136
140
|
#
|
137
|
-
# * :
|
141
|
+
# * skip_helpers: skip generating Devise url helpers like new_session_path(@user).
|
138
142
|
# This is useful to avoid conflicts with previous routes and is false by default.
|
139
143
|
# It accepts true as option, meaning it will skip all the helpers for the controllers
|
140
144
|
# given in :skip but it also accepts specific helpers to be skipped:
|
141
145
|
#
|
142
|
-
# devise_for :users, :
|
143
|
-
# devise_for :users, :
|
146
|
+
# devise_for :users, skip: [:registrations, :confirmations], skip_helpers: true
|
147
|
+
# devise_for :users, skip_helpers: [:registrations, :confirmations]
|
144
148
|
#
|
145
|
-
# * :
|
149
|
+
# * format: include "(.:format)" in the generated routes? true by default, set to false to disable:
|
146
150
|
#
|
147
|
-
# devise_for :users, :
|
151
|
+
# devise_for :users, format: false
|
148
152
|
#
|
149
|
-
# * :
|
153
|
+
# * constraints: works the same as Rails' constraints
|
150
154
|
#
|
151
|
-
# * :
|
155
|
+
# * defaults: works the same as Rails' defaults
|
156
|
+
#
|
157
|
+
# * router_name: allows application level router name to be overwritten for the current scope
|
152
158
|
#
|
153
159
|
# ==== Scoping
|
154
160
|
#
|
@@ -170,7 +176,7 @@ module ActionDispatch::Routing
|
|
170
176
|
#
|
171
177
|
# class ApplicationController < ActionController::Base
|
172
178
|
# def self.default_url_options
|
173
|
-
# { :
|
179
|
+
# { locale: I18n.locale }
|
174
180
|
# end
|
175
181
|
# end
|
176
182
|
#
|
@@ -195,7 +201,7 @@ module ActionDispatch::Routing
|
|
195
201
|
# In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:
|
196
202
|
#
|
197
203
|
# devise_scope :owner do
|
198
|
-
# post "deactivate", :
|
204
|
+
# post "deactivate", to: "registrations#deactivate", as: "deactivate_registration"
|
199
205
|
# end
|
200
206
|
#
|
201
207
|
def devise_for(*resources)
|
@@ -221,7 +227,7 @@ module ActionDispatch::Routing
|
|
221
227
|
raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)
|
222
228
|
rescue NameError => e
|
223
229
|
raise unless mapping.class_name == resource.to_s.classify
|
224
|
-
warn "[WARNING] You provided devise_for #{resource.inspect} but there is "
|
230
|
+
warn "[WARNING] You provided devise_for #{resource.inspect} but there is " \
|
225
231
|
"no model #{mapping.class_name} defined in your application"
|
226
232
|
next
|
227
233
|
rescue NoMethodError => e
|
@@ -229,7 +235,14 @@ module ActionDispatch::Routing
|
|
229
235
|
raise_no_devise_method_error!(mapping.class_name)
|
230
236
|
end
|
231
237
|
|
232
|
-
|
238
|
+
if options[:controllers] && options[:controllers][:omniauth_callbacks]
|
239
|
+
unless mapping.omniauthable?
|
240
|
+
raise ArgumentError, "Mapping omniauth_callbacks on a resource that is not omniauthable\n" \
|
241
|
+
"Please add `devise :omniauthable` to the `#{mapping.class_name}` model"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
routes = mapping.used_routes
|
233
246
|
|
234
247
|
devise_scope mapping.name do
|
235
248
|
with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
|
@@ -252,7 +265,7 @@ module ActionDispatch::Routing
|
|
252
265
|
# end
|
253
266
|
#
|
254
267
|
# authenticate :user, lambda {|u| u.role == "admin"} do
|
255
|
-
# root :
|
268
|
+
# root to: "admin/dashboard#show", as: :user_root
|
256
269
|
# end
|
257
270
|
#
|
258
271
|
def authenticate(scope=nil, block=nil)
|
@@ -266,18 +279,18 @@ module ActionDispatch::Routing
|
|
266
279
|
# a model and allows extra constraints to be done on the instance.
|
267
280
|
#
|
268
281
|
# authenticated :admin do
|
269
|
-
# root :
|
282
|
+
# root to: 'admin/dashboard#show', as: :admin_root
|
270
283
|
# end
|
271
284
|
#
|
272
285
|
# authenticated do
|
273
|
-
# root :
|
286
|
+
# root to: 'dashboard#show', as: :authenticated_root
|
274
287
|
# end
|
275
288
|
#
|
276
289
|
# authenticated :user, lambda {|u| u.role == "admin"} do
|
277
|
-
# root :
|
290
|
+
# root to: "admin/dashboard#show", as: :user_root
|
278
291
|
# end
|
279
292
|
#
|
280
|
-
# root :
|
293
|
+
# root to: 'landing#show'
|
281
294
|
#
|
282
295
|
def authenticated(scope=nil, block=nil)
|
283
296
|
constraints_for(:authenticate?, scope, block) do
|
@@ -290,15 +303,15 @@ module ActionDispatch::Routing
|
|
290
303
|
#
|
291
304
|
# unauthenticated do
|
292
305
|
# as :user do
|
293
|
-
# root :
|
306
|
+
# root to: 'devise/registrations#new'
|
294
307
|
# end
|
295
308
|
# end
|
296
309
|
#
|
297
|
-
# root :
|
310
|
+
# root to: 'dashboard#show'
|
298
311
|
#
|
299
312
|
def unauthenticated(scope=nil)
|
300
313
|
constraint = lambda do |request|
|
301
|
-
not request.env["warden"].authenticate? :
|
314
|
+
not request.env["warden"].authenticate? scope: scope
|
302
315
|
end
|
303
316
|
|
304
317
|
constraints(constraint) do
|
@@ -311,7 +324,7 @@ module ActionDispatch::Routing
|
|
311
324
|
# to which controller it is targetted.
|
312
325
|
#
|
313
326
|
# as :user do
|
314
|
-
# get "sign_in", :
|
327
|
+
# get "sign_in", to: "devise/sessions#new"
|
315
328
|
# end
|
316
329
|
#
|
317
330
|
# Notice you cannot have two scopes mapping to the same URL. And remember, if
|
@@ -343,41 +356,42 @@ module ActionDispatch::Routing
|
|
343
356
|
protected
|
344
357
|
|
345
358
|
def devise_session(mapping, controllers) #:nodoc:
|
346
|
-
resource :session, :
|
347
|
-
get :new, :
|
348
|
-
post :create, :
|
349
|
-
match :destroy, :
|
359
|
+
resource :session, only: [], controller: controllers[:sessions], path: "" do
|
360
|
+
get :new, path: mapping.path_names[:sign_in], as: "new"
|
361
|
+
post :create, path: mapping.path_names[:sign_in]
|
362
|
+
match :destroy, path: mapping.path_names[:sign_out], as: "destroy", via: mapping.sign_out_via
|
350
363
|
end
|
351
364
|
end
|
352
365
|
|
353
366
|
def devise_password(mapping, controllers) #:nodoc:
|
354
|
-
resource :password, :
|
355
|
-
:
|
367
|
+
resource :password, only: [:new, :create, :edit, :update],
|
368
|
+
path: mapping.path_names[:password], controller: controllers[:passwords]
|
356
369
|
end
|
357
370
|
|
358
371
|
def devise_confirmation(mapping, controllers) #:nodoc:
|
359
|
-
resource :confirmation, :
|
360
|
-
:
|
372
|
+
resource :confirmation, only: [:new, :create, :show],
|
373
|
+
path: mapping.path_names[:confirmation], controller: controllers[:confirmations]
|
361
374
|
end
|
362
375
|
|
363
376
|
def devise_unlock(mapping, controllers) #:nodoc:
|
364
377
|
if mapping.to.unlock_strategy_enabled?(:email)
|
365
|
-
resource :unlock, :
|
366
|
-
:
|
378
|
+
resource :unlock, only: [:new, :create, :show],
|
379
|
+
path: mapping.path_names[:unlock], controller: controllers[:unlocks]
|
367
380
|
end
|
368
381
|
end
|
369
382
|
|
370
383
|
def devise_registration(mapping, controllers) #:nodoc:
|
371
384
|
path_names = {
|
372
|
-
:
|
373
|
-
:
|
385
|
+
new: mapping.path_names[:sign_up],
|
386
|
+
edit: mapping.path_names[:edit],
|
387
|
+
cancel: mapping.path_names[:cancel]
|
374
388
|
}
|
375
389
|
|
376
390
|
options = {
|
377
|
-
:
|
378
|
-
:
|
379
|
-
:
|
380
|
-
:
|
391
|
+
only: [:new, :create, :edit, :update, :destroy],
|
392
|
+
path: mapping.path_names[:registration],
|
393
|
+
path_names: path_names,
|
394
|
+
controller: controllers[:registrations]
|
381
395
|
}
|
382
396
|
|
383
397
|
resource :registration, options do
|
@@ -387,8 +401,23 @@ module ActionDispatch::Routing
|
|
387
401
|
|
388
402
|
def devise_omniauth_callback(mapping, controllers) #:nodoc:
|
389
403
|
if mapping.fullpath =~ /:[a-zA-Z_]/
|
390
|
-
raise
|
391
|
-
|
404
|
+
raise <<-ERROR
|
405
|
+
Devise does not support scoping omniauth callbacks under a dynamic segment
|
406
|
+
and you have set #{mapping.fullpath.inspect}. You can work around by passing
|
407
|
+
`skip: :omniauth_callbacks` and manually defining the routes. Here is an example:
|
408
|
+
|
409
|
+
match "/users/auth/:provider",
|
410
|
+
constraints: { provider: /google|facebook/ },
|
411
|
+
to: "devise/omniauth_callbacks#passthru",
|
412
|
+
as: :omniauth_authorize,
|
413
|
+
via: [:get, :post]
|
414
|
+
|
415
|
+
match "/users/auth/:action/callback",
|
416
|
+
constraints: { action: /google|facebook/ },
|
417
|
+
to: "devise/omniauth_callbacks",
|
418
|
+
as: :omniauth_callback,
|
419
|
+
via: [:get, :post]
|
420
|
+
ERROR
|
392
421
|
end
|
393
422
|
|
394
423
|
path, @scope[:path] = @scope[:path], nil
|
@@ -399,16 +428,16 @@ module ActionDispatch::Routing
|
|
399
428
|
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
|
400
429
|
|
401
430
|
match "#{path_prefix}/:provider",
|
402
|
-
:
|
403
|
-
:
|
404
|
-
:
|
405
|
-
:
|
431
|
+
constraints: { provider: providers },
|
432
|
+
to: "#{controllers[:omniauth_callbacks]}#passthru",
|
433
|
+
as: :omniauth_authorize,
|
434
|
+
via: [:get, :post]
|
406
435
|
|
407
436
|
match "#{path_prefix}/:action/callback",
|
408
|
-
:
|
409
|
-
:
|
410
|
-
:
|
411
|
-
:
|
437
|
+
constraints: { action: providers },
|
438
|
+
to: controllers[:omniauth_callbacks],
|
439
|
+
as: :omniauth_callback,
|
440
|
+
via: [:get, :post]
|
412
441
|
ensure
|
413
442
|
@scope[:path] = path
|
414
443
|
end
|
@@ -419,7 +448,7 @@ module ActionDispatch::Routing
|
|
419
448
|
old = {}
|
420
449
|
DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] }
|
421
450
|
|
422
|
-
new = { :
|
451
|
+
new = { as: new_as, path: new_path, module: nil }
|
423
452
|
new.merge!(options.slice(:constraints, :defaults, :options))
|
424
453
|
|
425
454
|
@scope.merge!(new)
|
@@ -430,7 +459,7 @@ module ActionDispatch::Routing
|
|
430
459
|
|
431
460
|
def constraints_for(method_to_apply, scope=nil, block=nil)
|
432
461
|
constraint = lambda do |request|
|
433
|
-
request.env['warden'].send(method_to_apply, :
|
462
|
+
request.env['warden'].send(method_to_apply, scope: scope) &&
|
434
463
|
(block.nil? || block.call(request.env["warden"].user(scope)))
|
435
464
|
end
|
436
465
|
|
data/lib/devise/rails.rb
CHANGED
@@ -29,7 +29,13 @@ module Devise
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
initializer "devise.secret_key" do
|
32
|
+
initializer "devise.secret_key" do |app|
|
33
|
+
if app.respond_to?(:secrets)
|
34
|
+
Devise.secret_key ||= app.secrets.secret_key_base
|
35
|
+
elsif app.config.respond_to?(:secret_key_base)
|
36
|
+
Devise.secret_key ||= app.config.secret_key_base
|
37
|
+
end
|
38
|
+
|
33
39
|
Devise.token_generator ||=
|
34
40
|
if secret_key = Devise.secret_key
|
35
41
|
Devise::TokenGenerator.new(
|
@@ -16,6 +16,13 @@ module Devise
|
|
16
16
|
valid_for_params_auth? || valid_for_http_auth?
|
17
17
|
end
|
18
18
|
|
19
|
+
# Override and set to false for things like OmniAuth that technically
|
20
|
+
# run through Authentication (user_set) very often, which would normally
|
21
|
+
# reset CSRF data in the session
|
22
|
+
def clean_up_csrf?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
19
26
|
private
|
20
27
|
|
21
28
|
# Receives a resource and check if it is valid by calling valid_for_authentication?
|
@@ -49,7 +56,7 @@ module Devise
|
|
49
56
|
valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
|
50
57
|
end
|
51
58
|
|
52
|
-
# Check if this is
|
59
|
+
# Check if this is a valid strategy for http authentication by:
|
53
60
|
#
|
54
61
|
# * Validating if the model allows params authentication;
|
55
62
|
# * If any of the authorization headers were sent;
|
@@ -59,7 +66,7 @@ module Devise
|
|
59
66
|
http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
|
60
67
|
end
|
61
68
|
|
62
|
-
# Check if this is
|
69
|
+
# Check if this is a valid strategy for params authentication by:
|
63
70
|
#
|
64
71
|
# * Validating if the model allows params authentication;
|
65
72
|
# * If the request hits the sessions controller through POST;
|
@@ -102,9 +109,9 @@ module Devise
|
|
102
109
|
params_auth_hash.is_a?(Hash)
|
103
110
|
end
|
104
111
|
|
105
|
-
# Check if password is present
|
112
|
+
# Check if password is present.
|
106
113
|
def valid_password?
|
107
|
-
password.present?
|
114
|
+
password.present?
|
108
115
|
end
|
109
116
|
|
110
117
|
# Helper to decode credentials from HTTP.
|
@@ -2,16 +2,19 @@ require 'devise/strategies/authenticatable'
|
|
2
2
|
|
3
3
|
module Devise
|
4
4
|
module Strategies
|
5
|
-
# Default strategy for signing in a user, based on
|
5
|
+
# Default strategy for signing in a user, based on their email and password in the database.
|
6
6
|
class DatabaseAuthenticatable < Authenticatable
|
7
7
|
def authenticate!
|
8
|
-
resource
|
9
|
-
|
8
|
+
resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash)
|
9
|
+
encrypted = false
|
10
10
|
|
11
|
-
if validate(resource){ resource.valid_password?(password) }
|
11
|
+
if validate(resource){ encrypted = true; resource.valid_password?(password) }
|
12
12
|
resource.after_database_authentication
|
13
13
|
success!(resource)
|
14
14
|
end
|
15
|
+
|
16
|
+
mapping.to.new.password = password if !encrypted && Devise.paranoid
|
17
|
+
fail(:not_found_in_database) unless resource
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
data/lib/devise/test_helpers.rb
CHANGED
@@ -109,8 +109,8 @@ module Devise
|
|
109
109
|
|
110
110
|
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
|
111
111
|
@controller.response.headers.merge!(headers)
|
112
|
-
@controller.send :render, :
|
113
|
-
:
|
112
|
+
@controller.send :render, status: status, text: response.body,
|
113
|
+
content_type: headers["Content-Type"], location: headers["Location"]
|
114
114
|
nil # causes process return @response
|
115
115
|
end
|
116
116
|
|
data/lib/devise/version.rb
CHANGED
data/lib/devise.rb
CHANGED
@@ -21,6 +21,7 @@ module Devise
|
|
21
21
|
autoload :Rememberable, 'devise/controllers/rememberable'
|
22
22
|
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
23
23
|
autoload :SignInOut, 'devise/controllers/sign_in_out'
|
24
|
+
autoload :StoreLocation, 'devise/controllers/store_location'
|
24
25
|
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
25
26
|
end
|
26
27
|
|
@@ -133,6 +134,10 @@ module Devise
|
|
133
134
|
mattr_accessor :extend_remember_period
|
134
135
|
@@extend_remember_period = false
|
135
136
|
|
137
|
+
# If true, all the remember me tokens are going to be invalidated when the user signs out.
|
138
|
+
mattr_accessor :expire_all_remember_me_on_sign_out
|
139
|
+
@@expire_all_remember_me_on_sign_out = true
|
140
|
+
|
136
141
|
# Time interval you can access your account before confirming your account.
|
137
142
|
# nil - allows unconfirmed access for unlimited time
|
138
143
|
mattr_accessor :allow_unconfirmed_access_for
|
@@ -235,12 +240,12 @@ module Devise
|
|
235
240
|
@@parent_mailer = "ActionMailer::Base"
|
236
241
|
|
237
242
|
# The router Devise should use to generate routes. Defaults
|
238
|
-
# to :main_app. Should be
|
243
|
+
# to :main_app. Should be overridden by engines in order
|
239
244
|
# to provide custom routes.
|
240
245
|
mattr_accessor :router_name
|
241
246
|
@@router_name = nil
|
242
247
|
|
243
|
-
# Set the omniauth path prefix so it can be
|
248
|
+
# Set the omniauth path prefix so it can be overridden when
|
244
249
|
# Devise is used in a mountable engine
|
245
250
|
mattr_accessor :omniauth_path_prefix
|
246
251
|
@@omniauth_path_prefix = nil
|
@@ -267,13 +272,13 @@ module Devise
|
|
267
272
|
# Private methods to interface with Warden.
|
268
273
|
mattr_accessor :warden_config
|
269
274
|
@@warden_config = nil
|
270
|
-
@@
|
275
|
+
@@warden_config_blocks = []
|
271
276
|
|
272
277
|
# When true, enter in paranoid mode to avoid user enumeration.
|
273
278
|
mattr_accessor :paranoid
|
274
279
|
@@paranoid = false
|
275
280
|
|
276
|
-
# When true, warn user if
|
281
|
+
# When true, warn user if they just used next-to-last attempt of authentication
|
277
282
|
mattr_accessor :last_attempt_warning
|
278
283
|
@@last_attempt_warning = false
|
279
284
|
|
@@ -349,8 +354,8 @@ module Devise
|
|
349
354
|
# == Examples:
|
350
355
|
#
|
351
356
|
# Devise.add_module(:party_module)
|
352
|
-
# Devise.add_module(:party_module, :
|
353
|
-
# Devise.add_module(:party_module, :
|
357
|
+
# Devise.add_module(:party_module, strategy: true, controller: :sessions)
|
358
|
+
# Devise.add_module(:party_module, model: 'party_module/model')
|
354
359
|
#
|
355
360
|
def self.add_module(module_name, options = {})
|
356
361
|
ALL << module_name
|
@@ -399,7 +404,7 @@ module Devise
|
|
399
404
|
# Sets warden configuration using a block that will be invoked on warden
|
400
405
|
# initialization.
|
401
406
|
#
|
402
|
-
# Devise.
|
407
|
+
# Devise.setup do |config|
|
403
408
|
# config.allow_unconfirmed_access_for = 2.days
|
404
409
|
#
|
405
410
|
# config.warden do |manager|
|
@@ -408,7 +413,7 @@ module Devise
|
|
408
413
|
# end
|
409
414
|
# end
|
410
415
|
def self.warden(&block)
|
411
|
-
@@
|
416
|
+
@@warden_config_blocks << block
|
412
417
|
end
|
413
418
|
|
414
419
|
# Specify an omniauth provider.
|
@@ -448,7 +453,7 @@ module Devise
|
|
448
453
|
warden_config.intercept_401 = false
|
449
454
|
|
450
455
|
Devise.mappings.each_value do |mapping|
|
451
|
-
warden_config.scope_defaults mapping.name, :
|
456
|
+
warden_config.scope_defaults mapping.name, strategies: mapping.strategies
|
452
457
|
|
453
458
|
warden_config.serialize_into_session(mapping.name) do |record|
|
454
459
|
mapping.to.serialize_into_session(record)
|
@@ -462,7 +467,7 @@ module Devise
|
|
462
467
|
end
|
463
468
|
end
|
464
469
|
|
465
|
-
@@
|
470
|
+
@@warden_config_blocks.map { |block| block.call Devise.warden_config }
|
466
471
|
true
|
467
472
|
end
|
468
473
|
end
|