devise 3.2.4 → 4.0.0
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 +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +33 -17
- data/CHANGELOG.md +57 -1033
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +5 -5
- data/Gemfile.lock +138 -115
- data/MIT-LICENSE +1 -1
- data/README.md +124 -65
- data/Rakefile +2 -1
- data/app/controllers/devise/confirmations_controller.rb +7 -3
- data/app/controllers/devise/omniauth_callbacks_controller.rb +8 -4
- data/app/controllers/devise/passwords_controller.rb +16 -6
- data/app/controllers/devise/registrations_controller.rb +22 -10
- data/app/controllers/devise/sessions_controller.rb +42 -14
- data/app/controllers/devise/unlocks_controller.rb +5 -2
- data/app/controllers/devise_controller.rb +63 -29
- data/app/mailers/devise/mailer.rb +4 -0
- data/app/views/devise/confirmations/new.html.erb +7 -3
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/passwords/edit.html.erb +14 -5
- data/app/views/devise/passwords/new.html.erb +7 -3
- data/app/views/devise/registrations/edit.html.erb +19 -9
- data/app/views/devise/registrations/new.html.erb +18 -7
- data/app/views/devise/sessions/new.html.erb +16 -7
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +2 -2
- data/app/views/devise/unlocks/new.html.erb +7 -3
- data/bin/test +13 -0
- data/config/locales/en.yml +19 -16
- data/devise.gemspec +3 -4
- data/gemfiles/{Gemfile.rails-3.2-stable → Gemfile.rails-4.1-stable} +6 -6
- data/gemfiles/Gemfile.rails-4.1-stable.lock +167 -0
- data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.2-stable} +6 -6
- data/gemfiles/Gemfile.rails-4.2-stable.lock +189 -0
- data/gemfiles/Gemfile.rails-5.0-beta +37 -0
- data/gemfiles/Gemfile.rails-5.0-beta.lock +199 -0
- data/lib/devise/controllers/helpers.rb +94 -27
- data/lib/devise/controllers/rememberable.rb +9 -2
- data/lib/devise/controllers/sign_in_out.rb +2 -9
- data/lib/devise/controllers/store_location.rb +11 -3
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +72 -23
- data/lib/devise/hooks/activatable.rb +3 -4
- data/lib/devise/hooks/csrf_cleaner.rb +3 -1
- data/lib/devise/hooks/timeoutable.rb +13 -8
- data/lib/devise/mailers/helpers.rb +1 -1
- data/lib/devise/mapping.rb +6 -2
- data/lib/devise/models/authenticatable.rb +32 -28
- data/lib/devise/models/confirmable.rb +55 -22
- data/lib/devise/models/database_authenticatable.rb +32 -19
- data/lib/devise/models/lockable.rb +5 -5
- data/lib/devise/models/recoverable.rb +44 -20
- data/lib/devise/models/rememberable.rb +54 -27
- data/lib/devise/models/timeoutable.rb +0 -6
- data/lib/devise/models/trackable.rb +5 -3
- data/lib/devise/models/validatable.rb +3 -3
- data/lib/devise/models.rb +1 -1
- data/lib/devise/omniauth/url_helpers.rb +62 -4
- data/lib/devise/parameter_sanitizer.rb +176 -61
- data/lib/devise/rails/routes.rb +76 -59
- data/lib/devise/rails/warden_compat.rb +1 -10
- data/lib/devise/rails.rb +2 -11
- data/lib/devise/strategies/authenticatable.rb +15 -6
- data/lib/devise/strategies/database_authenticatable.rb +5 -4
- data/lib/devise/strategies/rememberable.rb +13 -3
- data/lib/devise/test_helpers.rb +12 -7
- data/lib/devise/token_generator.rb +1 -41
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +150 -58
- data/lib/generators/active_record/devise_generator.rb +28 -4
- data/lib/generators/active_record/templates/migration.rb +3 -3
- data/lib/generators/active_record/templates/migration_existing.rb +3 -3
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/install_generator.rb +15 -0
- data/lib/generators/devise/orm_helpers.rb +1 -18
- data/lib/generators/devise/views_generator.rb +14 -3
- data/lib/generators/templates/README +1 -1
- 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 +36 -28
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- 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 +1 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/custom_strategy_test.rb +7 -5
- data/test/controllers/helper_methods_test.rb +22 -0
- data/test/controllers/helpers_test.rb +41 -1
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +19 -15
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +5 -4
- data/test/controllers/sessions_controller_test.rb +24 -21
- data/test/controllers/url_helpers_test.rb +7 -1
- data/test/devise_test.rb +48 -8
- data/test/failure_app_test.rb +107 -19
- data/test/generators/active_record_generator_test.rb +6 -26
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/install_generator_test.rb +14 -3
- data/test/generators/views_generator_test.rb +8 -1
- data/test/helpers/devise_helper_test.rb +10 -12
- data/test/integration/authenticatable_test.rb +37 -21
- data/test/integration/confirmable_test.rb +54 -14
- data/test/integration/database_authenticatable_test.rb +12 -1
- data/test/integration/http_authenticatable_test.rb +4 -5
- data/test/integration/lockable_test.rb +10 -9
- data/test/integration/omniauthable_test.rb +13 -11
- data/test/integration/recoverable_test.rb +28 -15
- data/test/integration/registerable_test.rb +41 -33
- data/test/integration/rememberable_test.rb +51 -7
- data/test/integration/timeoutable_test.rb +23 -22
- data/test/integration/trackable_test.rb +3 -3
- data/test/mailers/confirmation_instructions_test.rb +10 -10
- data/test/mailers/reset_password_instructions_test.rb +8 -8
- data/test/mailers/unlock_instructions_test.rb +8 -8
- data/test/mapping_test.rb +7 -0
- data/test/models/authenticatable_test.rb +11 -1
- data/test/models/confirmable_test.rb +91 -42
- data/test/models/database_authenticatable_test.rb +26 -6
- data/test/models/lockable_test.rb +29 -17
- data/test/models/recoverable_test.rb +74 -7
- data/test/models/rememberable_test.rb +68 -94
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +9 -17
- data/test/models_test.rb +15 -6
- data/test/omniauth/url_helpers_test.rb +4 -7
- data/test/orm/active_record.rb +6 -1
- data/test/parameter_sanitizer_test.rb +103 -53
- data/test/rails_app/app/active_record/user.rb +1 -0
- 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_controller.rb +1 -6
- 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 +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +5 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +3 -3
- data/test/rails_app/app/controllers/users_controller.rb +6 -6
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +0 -9
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- 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/config/application.rb +3 -3
- data/test/rails_app/config/boot.rb +4 -4
- data/test/rails_app/config/environments/production.rb +6 -2
- data/test/rails_app/config/environments/test.rb +13 -3
- data/test/rails_app/config/initializers/devise.rb +15 -16
- data/test/rails_app/config/initializers/secret_token.rb +1 -6
- data/test/rails_app/config/routes.rb +23 -3
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
- data/test/rails_app/lib/shared_user.rb +1 -1
- 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 +33 -16
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +13 -6
- data/test/support/http_method_compatibility.rb +51 -0
- data/test/support/integration.rb +4 -4
- data/test/support/webrat/integrations/rails.rb +9 -0
- data/test/test_helper.rb +7 -0
- data/test/test_helpers_test.rb +43 -38
- data/test/test_models.rb +3 -3
- metadata +77 -23
- data/gemfiles/Gemfile.rails-4.0-stable +0 -29
@@ -0,0 +1,199 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rails/activemodel-serializers-xml.git
|
3
|
+
revision: f380ea5ddefcb9a37f4fbc47606ed6fbecdb2b2a
|
4
|
+
specs:
|
5
|
+
activemodel-serializers-xml (1.0.0)
|
6
|
+
activemodel (> 5.x)
|
7
|
+
activerecord (> 5.x)
|
8
|
+
activesupport (> 5.x)
|
9
|
+
builder (~> 3.1)
|
10
|
+
|
11
|
+
PATH
|
12
|
+
remote: ..
|
13
|
+
specs:
|
14
|
+
devise (4.0.0.rc2)
|
15
|
+
bcrypt (~> 3.0)
|
16
|
+
orm_adapter (~> 0.1)
|
17
|
+
railties (>= 4.1.0, < 5.1)
|
18
|
+
responders
|
19
|
+
warden (~> 1.2.3)
|
20
|
+
|
21
|
+
GEM
|
22
|
+
remote: https://rubygems.org/
|
23
|
+
specs:
|
24
|
+
actioncable (5.0.0.beta3)
|
25
|
+
actionpack (= 5.0.0.beta3)
|
26
|
+
nio4r (~> 1.2)
|
27
|
+
websocket-driver (~> 0.6.1)
|
28
|
+
actionmailer (5.0.0.beta3)
|
29
|
+
actionpack (= 5.0.0.beta3)
|
30
|
+
actionview (= 5.0.0.beta3)
|
31
|
+
activejob (= 5.0.0.beta3)
|
32
|
+
mail (~> 2.5, >= 2.5.4)
|
33
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
34
|
+
actionpack (5.0.0.beta3)
|
35
|
+
actionview (= 5.0.0.beta3)
|
36
|
+
activesupport (= 5.0.0.beta3)
|
37
|
+
rack (~> 2.x)
|
38
|
+
rack-test (~> 0.6.3)
|
39
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
40
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
41
|
+
actionview (5.0.0.beta3)
|
42
|
+
activesupport (= 5.0.0.beta3)
|
43
|
+
builder (~> 3.1)
|
44
|
+
erubis (~> 2.7.0)
|
45
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
46
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
47
|
+
activejob (5.0.0.beta3)
|
48
|
+
activesupport (= 5.0.0.beta3)
|
49
|
+
globalid (>= 0.3.6)
|
50
|
+
activemodel (5.0.0.beta3)
|
51
|
+
activesupport (= 5.0.0.beta3)
|
52
|
+
activerecord (5.0.0.beta3)
|
53
|
+
activemodel (= 5.0.0.beta3)
|
54
|
+
activesupport (= 5.0.0.beta3)
|
55
|
+
arel (~> 7.0)
|
56
|
+
activesupport (5.0.0.beta3)
|
57
|
+
concurrent-ruby (~> 1.0)
|
58
|
+
i18n (~> 0.7)
|
59
|
+
minitest (~> 5.1)
|
60
|
+
tzinfo (~> 1.1)
|
61
|
+
arel (7.0.0)
|
62
|
+
bcrypt (3.1.11)
|
63
|
+
builder (3.2.2)
|
64
|
+
concurrent-ruby (1.0.1)
|
65
|
+
erubis (2.7.0)
|
66
|
+
faraday (0.9.2)
|
67
|
+
multipart-post (>= 1.2, < 3)
|
68
|
+
globalid (0.3.6)
|
69
|
+
activesupport (>= 4.1.0)
|
70
|
+
hashie (3.4.3)
|
71
|
+
i18n (0.7.0)
|
72
|
+
json (1.8.3)
|
73
|
+
jwt (1.5.1)
|
74
|
+
loofah (2.0.3)
|
75
|
+
nokogiri (>= 1.5.9)
|
76
|
+
mail (2.6.4)
|
77
|
+
mime-types (>= 1.16, < 4)
|
78
|
+
metaclass (0.0.4)
|
79
|
+
method_source (0.8.2)
|
80
|
+
mime-types (3.0)
|
81
|
+
mime-types-data (~> 3.2015)
|
82
|
+
mime-types-data (3.2016.0221)
|
83
|
+
mini_portile2 (2.0.0)
|
84
|
+
minitest (5.8.4)
|
85
|
+
mocha (1.1.0)
|
86
|
+
metaclass (~> 0.0.1)
|
87
|
+
multi_json (1.11.2)
|
88
|
+
multi_xml (0.5.5)
|
89
|
+
multipart-post (2.0.0)
|
90
|
+
nio4r (1.2.1)
|
91
|
+
nokogiri (1.6.7.2)
|
92
|
+
mini_portile2 (~> 2.0.0.rc2)
|
93
|
+
oauth2 (1.1.0)
|
94
|
+
faraday (>= 0.8, < 0.10)
|
95
|
+
jwt (~> 1.0, < 1.5.2)
|
96
|
+
multi_json (~> 1.3)
|
97
|
+
multi_xml (~> 0.5)
|
98
|
+
rack (>= 1.2, < 3)
|
99
|
+
omniauth (1.3.1)
|
100
|
+
hashie (>= 1.2, < 4)
|
101
|
+
rack (>= 1.0, < 3)
|
102
|
+
omniauth-facebook (3.0.0)
|
103
|
+
omniauth-oauth2 (~> 1.2)
|
104
|
+
omniauth-oauth2 (1.4.0)
|
105
|
+
oauth2 (~> 1.0)
|
106
|
+
omniauth (~> 1.2)
|
107
|
+
omniauth-openid (1.0.1)
|
108
|
+
omniauth (~> 1.0)
|
109
|
+
rack-openid (~> 1.3.1)
|
110
|
+
orm_adapter (0.5.0)
|
111
|
+
rack (2.0.0.alpha)
|
112
|
+
json
|
113
|
+
rack-openid (1.3.1)
|
114
|
+
rack (>= 1.1.0)
|
115
|
+
ruby-openid (>= 2.1.8)
|
116
|
+
rack-test (0.6.3)
|
117
|
+
rack (>= 1.0)
|
118
|
+
rails (5.0.0.beta3)
|
119
|
+
actioncable (= 5.0.0.beta3)
|
120
|
+
actionmailer (= 5.0.0.beta3)
|
121
|
+
actionpack (= 5.0.0.beta3)
|
122
|
+
actionview (= 5.0.0.beta3)
|
123
|
+
activejob (= 5.0.0.beta3)
|
124
|
+
activemodel (= 5.0.0.beta3)
|
125
|
+
activerecord (= 5.0.0.beta3)
|
126
|
+
activesupport (= 5.0.0.beta3)
|
127
|
+
bundler (>= 1.3.0, < 2.0)
|
128
|
+
railties (= 5.0.0.beta3)
|
129
|
+
sprockets-rails (>= 2.0.0)
|
130
|
+
rails-controller-testing (0.1.1)
|
131
|
+
actionpack (~> 5.x)
|
132
|
+
actionview (~> 5.x)
|
133
|
+
activesupport (~> 5.x)
|
134
|
+
rails-deprecated_sanitizer (1.0.3)
|
135
|
+
activesupport (>= 4.2.0.alpha)
|
136
|
+
rails-dom-testing (1.0.7)
|
137
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
138
|
+
nokogiri (~> 1.6.0)
|
139
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
140
|
+
rails-html-sanitizer (1.0.3)
|
141
|
+
loofah (~> 2.0)
|
142
|
+
railties (5.0.0.beta3)
|
143
|
+
actionpack (= 5.0.0.beta3)
|
144
|
+
activesupport (= 5.0.0.beta3)
|
145
|
+
method_source
|
146
|
+
rake (>= 0.8.7)
|
147
|
+
thor (>= 0.18.1, < 2.0)
|
148
|
+
rake (11.1.2)
|
149
|
+
rdoc (4.2.2)
|
150
|
+
json (~> 1.4)
|
151
|
+
responders (2.1.2)
|
152
|
+
railties (>= 4.2.0, < 5.1)
|
153
|
+
ruby-openid (2.7.0)
|
154
|
+
sprockets (3.6.0)
|
155
|
+
concurrent-ruby (~> 1.0)
|
156
|
+
rack (> 1, < 3)
|
157
|
+
sprockets-rails (3.0.4)
|
158
|
+
actionpack (>= 4.0)
|
159
|
+
activesupport (>= 4.0)
|
160
|
+
sprockets (>= 3.0.0)
|
161
|
+
sqlite3 (1.3.11)
|
162
|
+
thor (0.19.1)
|
163
|
+
thread_safe (0.3.5)
|
164
|
+
tzinfo (1.2.2)
|
165
|
+
thread_safe (~> 0.1)
|
166
|
+
warden (1.2.6)
|
167
|
+
rack (>= 1.0)
|
168
|
+
webrat (0.7.3)
|
169
|
+
nokogiri (>= 1.2.0)
|
170
|
+
rack (>= 1.0)
|
171
|
+
rack-test (>= 0.5.3)
|
172
|
+
websocket-driver (0.6.3)
|
173
|
+
websocket-extensions (>= 0.1.0)
|
174
|
+
websocket-extensions (0.1.2)
|
175
|
+
|
176
|
+
PLATFORMS
|
177
|
+
ruby
|
178
|
+
|
179
|
+
DEPENDENCIES
|
180
|
+
activemodel-serializers-xml!
|
181
|
+
activerecord-jdbc-adapter
|
182
|
+
activerecord-jdbcsqlite3-adapter
|
183
|
+
devise!
|
184
|
+
jruby-openssl
|
185
|
+
mocha (~> 1.1)
|
186
|
+
oauth2
|
187
|
+
omniauth (~> 1.3)
|
188
|
+
omniauth-facebook
|
189
|
+
omniauth-oauth2 (>= 1.2.0, < 1.5.0)
|
190
|
+
omniauth-openid (~> 1.0.1)
|
191
|
+
rails (= 5.0.0.beta3)
|
192
|
+
rails-controller-testing
|
193
|
+
rdoc
|
194
|
+
responders (~> 2.1.1)
|
195
|
+
sqlite3
|
196
|
+
webrat (= 0.7.3)
|
197
|
+
|
198
|
+
BUNDLED WITH
|
199
|
+
1.11.2
|
@@ -7,10 +7,76 @@ module Devise
|
|
7
7
|
include Devise::Controllers::StoreLocation
|
8
8
|
|
9
9
|
included do
|
10
|
-
|
10
|
+
if respond_to?(:helper_method)
|
11
|
+
helper_method :warden, :signed_in?, :devise_controller?
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
module ClassMethods
|
16
|
+
# Define authentication filters and accessor helpers for a group of mappings.
|
17
|
+
# These methods are useful when you are working with multiple mappings that
|
18
|
+
# share some functionality. They are pretty much the same as the ones
|
19
|
+
# defined for normal mappings.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
#
|
23
|
+
# inside BlogsController (or any other controller, it doesn't matter which):
|
24
|
+
# devise_group :blogger, contains: [:user, :admin]
|
25
|
+
#
|
26
|
+
# Generated methods:
|
27
|
+
# authenticate_blogger! # Redirects unless user or admin are signed in
|
28
|
+
# blogger_signed_in? # Checks whether there is either a user or an admin signed in
|
29
|
+
# current_blogger # Currently signed in user or admin
|
30
|
+
# current_bloggers # Currently signed in user and admin
|
31
|
+
#
|
32
|
+
# Use:
|
33
|
+
# before_action :authenticate_blogger! # Redirects unless either a user or an admin are authenticated
|
34
|
+
# before_action ->{ authenticate_blogger! :admin } # Redirects to the admin login page
|
35
|
+
# current_blogger :user # Preferably returns a User if one is signed in
|
36
|
+
#
|
37
|
+
def devise_group(group_name, opts={})
|
38
|
+
mappings = "[#{ opts[:contains].map { |m| ":#{m}" }.join(',') }]"
|
39
|
+
|
40
|
+
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
41
|
+
def authenticate_#{group_name}!(favourite=nil, opts={})
|
42
|
+
unless #{group_name}_signed_in?
|
43
|
+
mappings = #{mappings}
|
44
|
+
mappings.unshift mappings.delete(favourite.to_sym) if favourite
|
45
|
+
mappings.each do |mapping|
|
46
|
+
opts[:scope] = mapping
|
47
|
+
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def #{group_name}_signed_in?
|
53
|
+
#{mappings}.any? do |mapping|
|
54
|
+
warden.authenticate?(scope: mapping)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def current_#{group_name}(favourite=nil)
|
59
|
+
mappings = #{mappings}
|
60
|
+
mappings.unshift mappings.delete(favourite.to_sym) if favourite
|
61
|
+
mappings.each do |mapping|
|
62
|
+
current = warden.authenticate(scope: mapping)
|
63
|
+
return current if current
|
64
|
+
end
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def current_#{group_name.to_s.pluralize}
|
69
|
+
#{mappings}.map do |mapping|
|
70
|
+
warden.authenticate(scope: mapping)
|
71
|
+
end.compact
|
72
|
+
end
|
73
|
+
|
74
|
+
if respond_to?(:helper_method)
|
75
|
+
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
|
76
|
+
end
|
77
|
+
METHODS
|
78
|
+
end
|
79
|
+
|
14
80
|
def log_process_action(payload)
|
15
81
|
payload[:status] ||= 401 unless payload[:exception]
|
16
82
|
super
|
@@ -18,7 +84,7 @@ module Devise
|
|
18
84
|
end
|
19
85
|
|
20
86
|
# Define authentication filters and accessor helpers based on mappings.
|
21
|
-
# These filters should be used inside the controllers as
|
87
|
+
# These filters should be used inside the controllers as before_actions,
|
22
88
|
# so you can control the scope of the user who should be signed in to
|
23
89
|
# access that specific controller/action.
|
24
90
|
# Example:
|
@@ -38,8 +104,8 @@ module Devise
|
|
38
104
|
# admin_session # Session data available only to the admin scope
|
39
105
|
#
|
40
106
|
# Use:
|
41
|
-
#
|
42
|
-
#
|
107
|
+
# before_action :authenticate_user! # Tell devise to use :user map
|
108
|
+
# before_action :authenticate_admin! # Tell devise to use :admin map
|
43
109
|
#
|
44
110
|
def self.define_helpers(mapping) #:nodoc:
|
45
111
|
mapping = mapping.name
|
@@ -64,7 +130,9 @@ module Devise
|
|
64
130
|
METHODS
|
65
131
|
|
66
132
|
ActiveSupport.on_load(:action_controller) do
|
67
|
-
|
133
|
+
if respond_to?(:helper_method)
|
134
|
+
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
|
135
|
+
end
|
68
136
|
end
|
69
137
|
end
|
70
138
|
|
@@ -77,20 +145,16 @@ module Devise
|
|
77
145
|
# the controllers defined inside devise. Useful if you want to apply a before
|
78
146
|
# filter to all controllers, except the ones in devise:
|
79
147
|
#
|
80
|
-
#
|
148
|
+
# before_action :my_filter, unless: :devise_controller?
|
81
149
|
def devise_controller?
|
82
150
|
is_a?(::DeviseController)
|
83
151
|
end
|
84
152
|
|
85
|
-
#
|
153
|
+
# Set up a param sanitizer to filter parameters using strong_parameters. See
|
86
154
|
# lib/devise/parameter_sanitizer.rb for more info. Override this
|
87
155
|
# method in your application controller to use your own parameter sanitizer.
|
88
156
|
def devise_parameter_sanitizer
|
89
|
-
@devise_parameter_sanitizer ||=
|
90
|
-
Devise::ParameterSanitizer.new(resource_class, resource_name, params)
|
91
|
-
else
|
92
|
-
Devise::BaseSanitizer.new(resource_class, resource_name, params)
|
93
|
-
end
|
157
|
+
@devise_parameter_sanitizer ||= Devise::ParameterSanitizer.new(resource_class, resource_name, params)
|
94
158
|
end
|
95
159
|
|
96
160
|
# Tell warden that params authentication is allowed for that specific page.
|
@@ -102,9 +166,16 @@ module Devise
|
|
102
166
|
# tries to find a resource_root_path, otherwise it uses the root_path.
|
103
167
|
def signed_in_root_path(resource_or_scope)
|
104
168
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
169
|
+
router_name = Devise.mappings[scope].router_name
|
170
|
+
|
105
171
|
home_path = "#{scope}_root_path"
|
106
|
-
|
107
|
-
|
172
|
+
|
173
|
+
context = router_name ? send(router_name) : self
|
174
|
+
|
175
|
+
if context.respond_to?(home_path, true)
|
176
|
+
context.send(home_path)
|
177
|
+
elsif context.respond_to?(:root_path)
|
178
|
+
context.root_path
|
108
179
|
elsif respond_to?(:root_path)
|
109
180
|
root_path
|
110
181
|
else
|
@@ -121,10 +192,10 @@ module Devise
|
|
121
192
|
# root path. For a user scope, you can define the default url in
|
122
193
|
# the following way:
|
123
194
|
#
|
124
|
-
#
|
195
|
+
# get '/users' => 'users#index', as: :user_root # creates user_root_path
|
125
196
|
#
|
126
|
-
#
|
127
|
-
#
|
197
|
+
# namespace :user do
|
198
|
+
# root 'users#index' # creates user_root_path
|
128
199
|
# end
|
129
200
|
#
|
130
201
|
# If the resource root path is not defined, root_path is used. However,
|
@@ -150,7 +221,10 @@ module Devise
|
|
150
221
|
#
|
151
222
|
# By default it is the root_path.
|
152
223
|
def after_sign_out_path_for(resource_or_scope)
|
153
|
-
|
224
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
225
|
+
router_name = Devise.mappings[scope].router_name
|
226
|
+
context = router_name ? send(router_name) : self
|
227
|
+
context.respond_to?(:root_path) ? context.root_path : "/"
|
154
228
|
end
|
155
229
|
|
156
230
|
# Sign in a user and tries to redirect first to the stored location and
|
@@ -176,10 +250,9 @@ module Devise
|
|
176
250
|
# Overwrite Rails' handle unverified request to sign out all scopes,
|
177
251
|
# clear run strategies and remove cached variables.
|
178
252
|
def handle_unverified_request
|
179
|
-
|
253
|
+
super # call the default behaviour which resets/nullifies/raises
|
180
254
|
request.env["devise.skip_storage"] = true
|
181
|
-
|
182
|
-
super # call the default behaviour which resets the session
|
255
|
+
sign_out_all_scopes(false)
|
183
256
|
end
|
184
257
|
|
185
258
|
def request_format
|
@@ -198,12 +271,6 @@ module Devise
|
|
198
271
|
|
199
272
|
private
|
200
273
|
|
201
|
-
def expire_session_data_after_sign_in!
|
202
|
-
ActiveSupport::Deprecation.warn "expire_session_data_after_sign_in! is deprecated " \
|
203
|
-
"in favor of expire_data_after_sign_in!"
|
204
|
-
expire_data_after_sign_in!
|
205
|
-
end
|
206
|
-
|
207
274
|
def expire_data_after_sign_out!
|
208
275
|
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
|
209
276
|
super
|
@@ -2,18 +2,25 @@ module Devise
|
|
2
2
|
module Controllers
|
3
3
|
# A module that may be optionally included in a controller in order
|
4
4
|
# to provide remember me behavior. Useful when signing in is done
|
5
|
-
# through a callback, like in
|
5
|
+
# through a callback, like in OmniAuth.
|
6
6
|
module Rememberable
|
7
7
|
# Return default cookie values retrieved from session options.
|
8
8
|
def self.cookie_values
|
9
9
|
Rails.configuration.session_options.slice(:path, :domain, :secure)
|
10
10
|
end
|
11
11
|
|
12
|
+
def remember_me_is_active?(resource)
|
13
|
+
return false unless resource.respond_to?(:remember_me)
|
14
|
+
scope = Devise::Mapping.find_scope!(resource)
|
15
|
+
_, token, generated_at = cookies.signed[remember_key(resource, scope)]
|
16
|
+
resource.remember_me?(token, generated_at)
|
17
|
+
end
|
18
|
+
|
12
19
|
# Remembers the given resource by setting up a cookie
|
13
20
|
def remember_me(resource)
|
14
21
|
return if env["devise.skip_storage"]
|
15
22
|
scope = Devise::Mapping.find_scope!(resource)
|
16
|
-
resource.remember_me!
|
23
|
+
resource.remember_me!
|
17
24
|
cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
|
18
25
|
end
|
19
26
|
|
@@ -6,7 +6,7 @@ module Devise
|
|
6
6
|
# Return true if the given scope is signed in session. If no scope given, return
|
7
7
|
# true if any scope is signed in. Does not run authentication hooks.
|
8
8
|
def signed_in?(scope=nil)
|
9
|
-
[
|
9
|
+
[scope || Devise.mappings.keys].flatten.any? do |_scope|
|
10
10
|
warden.authenticate?(scope: _scope)
|
11
11
|
end
|
12
12
|
end
|
@@ -72,7 +72,6 @@ module Devise
|
|
72
72
|
def sign_out_all_scopes(lock=true)
|
73
73
|
users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
|
74
74
|
|
75
|
-
warden.raw_session.inspect
|
76
75
|
warden.logout
|
77
76
|
expire_data_after_sign_out!
|
78
77
|
warden.clear_strategies_cache!
|
@@ -91,13 +90,7 @@ module Devise
|
|
91
90
|
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
|
92
91
|
end
|
93
92
|
|
94
|
-
|
95
|
-
# session.keys will return an empty array if the session is not yet loaded.
|
96
|
-
# This is a bug in both Rack and Rails.
|
97
|
-
# A call to #empty? forces the session to be loaded.
|
98
|
-
session.empty?
|
99
|
-
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
|
100
|
-
end
|
93
|
+
alias :expire_data_after_sign_out! :expire_data_after_sign_in!
|
101
94
|
end
|
102
95
|
end
|
103
96
|
end
|
@@ -33,14 +33,22 @@ module Devise
|
|
33
33
|
#
|
34
34
|
def store_location_for(resource_or_scope, location)
|
35
35
|
session_key = stored_location_key_for(resource_or_scope)
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
uri = parse_uri(location)
|
37
|
+
if uri
|
38
|
+
path = [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?')
|
39
|
+
path = [path, uri.fragment].compact.join('#')
|
40
|
+
session[session_key] = path
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
private
|
43
45
|
|
46
|
+
def parse_uri(location)
|
47
|
+
location && URI.parse(location)
|
48
|
+
rescue URI::InvalidURIError
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
44
52
|
def stored_location_key_for(resource_or_scope)
|
45
53
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
46
54
|
"#{scope}_return_to"
|
@@ -42,14 +42,14 @@ module Devise
|
|
42
42
|
[:path, :url].each do |path_or_url|
|
43
43
|
actions.each do |action|
|
44
44
|
action = action ? "#{action}_" : ""
|
45
|
-
method = "#{action}#{module_name}_#{path_or_url}"
|
45
|
+
method = :"#{action}#{module_name}_#{path_or_url}"
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
define_method method do |resource_or_scope, *args|
|
48
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
49
|
+
router_name = Devise.mappings[scope].router_name
|
50
|
+
context = router_name ? send(router_name) : _devise_route_context
|
51
|
+
context.send("#{action}#{scope}_#{module_name}_#{path_or_url}", *args)
|
52
|
+
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bcrypt'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Encryptor
|
5
|
+
def self.digest(klass, password)
|
6
|
+
if klass.pepper.present?
|
7
|
+
password = "#{password}#{klass.pepper}"
|
8
|
+
end
|
9
|
+
::BCrypt::Password.create(password, cost: klass.stretches).to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.compare(klass, hashed_password, password)
|
13
|
+
return false if hashed_password.blank?
|
14
|
+
bcrypt = ::BCrypt::Password.new(hashed_password)
|
15
|
+
if klass.pepper.present?
|
16
|
+
password = "#{password}#{klass.pepper}"
|
17
|
+
end
|
18
|
+
password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)
|
19
|
+
Devise.secure_compare(password, hashed_password)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|