clearance 1.17.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +8 -14
- data/Appraisals +11 -3
- data/Gemfile +3 -6
- data/Gemfile.lock +91 -87
- data/NEWS.md +233 -15
- data/README.md +54 -28
- data/app/controllers/clearance/base_controller.rb +8 -1
- data/app/controllers/clearance/passwords_controller.rb +35 -45
- data/app/controllers/clearance/sessions_controller.rb +3 -18
- data/app/controllers/clearance/users_controller.rb +2 -17
- data/clearance.gemspec +15 -9
- data/config/locales/clearance.en.yml +1 -0
- data/config/routes.rb +1 -1
- data/gemfiles/rails_5.0.gemfile +5 -6
- data/gemfiles/rails_5.1.gemfile +5 -6
- data/gemfiles/rails_5.2.gemfile +5 -6
- data/gemfiles/{rails_4.2.gemfile → rails_6.0.gemfile} +7 -7
- data/lib/clearance.rb +0 -8
- data/lib/clearance/authentication.rb +1 -9
- data/lib/clearance/authorization.rb +2 -11
- data/lib/clearance/back_door.rb +1 -1
- data/lib/clearance/configuration.rb +30 -19
- data/lib/clearance/password_strategies.rb +5 -4
- data/lib/clearance/password_strategies/argon2.rb +23 -0
- data/lib/clearance/password_strategies/bcrypt.rb +17 -11
- data/lib/clearance/rack_session.rb +5 -1
- data/lib/clearance/session.rb +40 -12
- data/lib/clearance/testing/deny_access_matcher.rb +10 -20
- data/lib/clearance/user.rb +3 -24
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/install/install_generator.rb +12 -12
- data/lib/generators/clearance/install/templates/README +10 -4
- data/lib/generators/clearance/install/templates/db/migrate/add_clearance_to_users.rb.erb +1 -1
- data/lib/generators/clearance/install/templates/db/migrate/create_users.rb.erb +1 -1
- data/lib/generators/clearance/routes/templates/routes.rb +1 -1
- data/spec/acceptance/clearance_installation_spec.rb +0 -4
- data/spec/app_templates/app/models/user.rb +1 -1
- data/spec/app_templates/testapp/app/controllers/home_controller.rb +1 -5
- data/spec/app_templates/testapp/app/views/layouts/application.html.erb +24 -0
- data/spec/clearance/back_door_spec.rb +12 -6
- data/spec/clearance/rack_session_spec.rb +2 -0
- data/spec/clearance/session_spec.rb +91 -47
- data/spec/clearance/testing/deny_access_matcher_spec.rb +32 -0
- data/spec/configuration_spec.rb +46 -15
- data/spec/controllers/apis_controller_spec.rb +1 -5
- data/spec/controllers/forgeries_controller_spec.rb +1 -5
- data/spec/controllers/passwords_controller_spec.rb +41 -5
- data/spec/controllers/permissions_controller_spec.rb +3 -7
- data/spec/controllers/sessions_controller_spec.rb +1 -1
- data/spec/dummy/app/controllers/application_controller.rb +1 -5
- data/spec/dummy/application.rb +7 -3
- data/spec/generators/clearance/install/install_generator_spec.rb +33 -15
- data/spec/generators/clearance/views/views_generator_spec.rb +0 -2
- data/spec/models/user_spec.rb +5 -5
- data/spec/password_strategies/argon2_spec.rb +79 -0
- data/spec/password_strategies/bcrypt_spec.rb +18 -1
- data/spec/requests/authentication_cookie_spec.rb +55 -0
- data/spec/requests/token_expiration_spec.rb +5 -0
- data/spec/spec_helper.rb +4 -7
- data/spec/support/generator_spec_helpers.rb +1 -9
- metadata +51 -33
- data/app/views/layouts/application.html.erb +0 -23
- data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +0 -77
- data/lib/clearance/password_strategies/blowfish.rb +0 -61
- data/lib/clearance/password_strategies/sha1.rb +0 -59
- data/lib/clearance/testing.rb +0 -11
- data/lib/clearance/testing/helpers.rb +0 -15
- data/spec/app_templates/app/models/rails5/user.rb +0 -5
- data/spec/password_strategies/bcrypt_migration_from_sha1_spec.rb +0 -122
- data/spec/password_strategies/blowfish_spec.rb +0 -61
- data/spec/password_strategies/sha1_spec.rb +0 -59
- data/spec/support/environment.rb +0 -12
- data/spec/support/http_method_shim.rb +0 -25
@@ -22,10 +22,23 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
22
22
|
|
23
23
|
expect(BCrypt::Password).to have_received(:create).with(
|
24
24
|
password,
|
25
|
-
cost: ::BCrypt::Engine::DEFAULT_COST
|
25
|
+
cost: ::BCrypt::Engine::DEFAULT_COST,
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
|
+
it "uses an explicity configured BCrypt cost" do
|
30
|
+
stub_bcrypt_cost(8)
|
31
|
+
bcrypt_password = BCrypt::Password.create(password, cost: nil)
|
32
|
+
|
33
|
+
expect(bcrypt_password.cost).to eq(8)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "uses the default BCrypt cost value implicitly" do
|
37
|
+
bcrypt_password = BCrypt::Password.create(password, cost: nil)
|
38
|
+
|
39
|
+
expect(bcrypt_password.cost).to eq(BCrypt::Engine::DEFAULT_COST)
|
40
|
+
end
|
41
|
+
|
29
42
|
it "encrypts with BCrypt using minimum cost in test environment" do
|
30
43
|
stub_bcrypt_password
|
31
44
|
model_instance = fake_model_with_bcrypt_strategy
|
@@ -42,6 +55,10 @@ describe Clearance::PasswordStrategies::BCrypt do
|
|
42
55
|
allow(BCrypt::Password).to receive(:create).and_return(encrypted_password)
|
43
56
|
end
|
44
57
|
|
58
|
+
def stub_bcrypt_cost(cost)
|
59
|
+
allow(BCrypt::Engine).to receive(:cost).and_return(cost)
|
60
|
+
end
|
61
|
+
|
45
62
|
def encrypted_password
|
46
63
|
@encrypted_password ||= double("encrypted password")
|
47
64
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class PagesController < ApplicationController
|
4
|
+
include Clearance::Controller
|
5
|
+
before_action :require_login, only: :private
|
6
|
+
|
7
|
+
# A page requiring user authentication
|
8
|
+
def private
|
9
|
+
head :ok
|
10
|
+
end
|
11
|
+
|
12
|
+
# A page that does not require user authentication
|
13
|
+
def public
|
14
|
+
head :ok
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Authentication cookies in the response" do
|
19
|
+
before do
|
20
|
+
draw_test_routes
|
21
|
+
create_user_and_sign_in
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
Rails.application.reload_routes!
|
26
|
+
end
|
27
|
+
|
28
|
+
it "are not present if the request does not authenticate" do
|
29
|
+
get public_path
|
30
|
+
|
31
|
+
expect(headers["Set-Cookie"]).to be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "are present if the request does authenticate" do
|
35
|
+
get private_path
|
36
|
+
|
37
|
+
expect(headers["Set-Cookie"]).to match(/remember_token=/)
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw_test_routes
|
41
|
+
Rails.application.routes.draw do
|
42
|
+
get "/private" => "pages#private", as: :private
|
43
|
+
get "/public" => "pages#public", as: :public
|
44
|
+
resource :session, controller: "clearance/sessions", only: [:create]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_user_and_sign_in
|
49
|
+
user = create(:user, password: "password")
|
50
|
+
|
51
|
+
post session_path, params: {
|
52
|
+
session: { email: user.email, password: "password" },
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
@@ -3,10 +3,15 @@ require "spec_helper"
|
|
3
3
|
describe "Token expiration" do
|
4
4
|
describe "after signing in" do
|
5
5
|
before do
|
6
|
+
Timecop.freeze
|
6
7
|
create_user_and_sign_in
|
7
8
|
@initial_cookies = remember_token_cookies
|
8
9
|
end
|
9
10
|
|
11
|
+
after do
|
12
|
+
Timecop.return
|
13
|
+
end
|
14
|
+
|
10
15
|
it "should have a remember_token cookie with a future expiration" do
|
11
16
|
expect(first_cookie.expires).to be_between(
|
12
17
|
1.years.from_now - 1.second,
|
data/spec/spec_helper.rb
CHANGED
@@ -29,12 +29,10 @@ RSpec.configure do |config|
|
|
29
29
|
|
30
30
|
config.before { restore_default_warning_free_config }
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
config.include Rails::Controller::Testing::Integration
|
37
|
-
end
|
32
|
+
require 'rails-controller-testing'
|
33
|
+
config.include Rails::Controller::Testing::TestProcess
|
34
|
+
config.include Rails::Controller::Testing::TemplateAssertions
|
35
|
+
config.include Rails::Controller::Testing::Integration
|
38
36
|
end
|
39
37
|
|
40
38
|
Shoulda::Matchers.configure do |config|
|
@@ -48,5 +46,4 @@ end
|
|
48
46
|
|
49
47
|
def restore_default_warning_free_config
|
50
48
|
Clearance.configuration = nil
|
51
|
-
Clearance.configure { |config| config.rotate_csrf_on_sign_in = true }
|
52
49
|
end
|
@@ -18,7 +18,7 @@ module GeneratorSpecHelpers
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def provide_existing_user_class
|
21
|
-
copy_to_generator_root("app/models",
|
21
|
+
copy_to_generator_root("app/models", "user.rb")
|
22
22
|
allow(File).to receive(:exist?).and_call_original
|
23
23
|
allow(File).to receive(:exist?).with("app/models/user.rb").and_return(true)
|
24
24
|
end
|
@@ -32,14 +32,6 @@ module GeneratorSpecHelpers
|
|
32
32
|
FileUtils.mkdir_p(destination)
|
33
33
|
FileUtils.cp(template_file, destination)
|
34
34
|
end
|
35
|
-
|
36
|
-
def versionize_template(template_file)
|
37
|
-
if Rails.version >= "5.0.0"
|
38
|
-
template_file = ["rails5", template_file].join("/")
|
39
|
-
end
|
40
|
-
|
41
|
-
template_file
|
42
|
-
end
|
43
35
|
end
|
44
36
|
|
45
37
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clearance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
@@ -22,10 +22,10 @@ authors:
|
|
22
22
|
- Jason Morrison
|
23
23
|
- Galen Frechette
|
24
24
|
- Josh Steiner
|
25
|
-
autorequire:
|
25
|
+
autorequire:
|
26
26
|
bindir: bin
|
27
27
|
cert_chain: []
|
28
|
-
date:
|
28
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|
@@ -33,85 +33,110 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 3.1.1
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 3.1.1
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: argon2
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2.0'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.0.2
|
44
64
|
- !ruby/object:Gem::Dependency
|
45
65
|
name: email_validator
|
46
66
|
requirement: !ruby/object:Gem::Requirement
|
47
67
|
requirements:
|
48
68
|
- - "~>"
|
49
69
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
70
|
+
version: '2.0'
|
51
71
|
type: :runtime
|
52
72
|
prerelease: false
|
53
73
|
version_requirements: !ruby/object:Gem::Requirement
|
54
74
|
requirements:
|
55
75
|
- - "~>"
|
56
76
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
77
|
+
version: '2.0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: railties
|
60
80
|
requirement: !ruby/object:Gem::Requirement
|
61
81
|
requirements:
|
62
82
|
- - ">="
|
63
83
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
84
|
+
version: '5.0'
|
65
85
|
type: :runtime
|
66
86
|
prerelease: false
|
67
87
|
version_requirements: !ruby/object:Gem::Requirement
|
68
88
|
requirements:
|
69
89
|
- - ">="
|
70
90
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
91
|
+
version: '5.0'
|
72
92
|
- !ruby/object:Gem::Dependency
|
73
93
|
name: activemodel
|
74
94
|
requirement: !ruby/object:Gem::Requirement
|
75
95
|
requirements:
|
76
96
|
- - ">="
|
77
97
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
98
|
+
version: '5.0'
|
79
99
|
type: :runtime
|
80
100
|
prerelease: false
|
81
101
|
version_requirements: !ruby/object:Gem::Requirement
|
82
102
|
requirements:
|
83
103
|
- - ">="
|
84
104
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
105
|
+
version: '5.0'
|
86
106
|
- !ruby/object:Gem::Dependency
|
87
107
|
name: activerecord
|
88
108
|
requirement: !ruby/object:Gem::Requirement
|
89
109
|
requirements:
|
90
110
|
- - ">="
|
91
111
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
112
|
+
version: '5.0'
|
93
113
|
type: :runtime
|
94
114
|
prerelease: false
|
95
115
|
version_requirements: !ruby/object:Gem::Requirement
|
96
116
|
requirements:
|
97
117
|
- - ">="
|
98
118
|
- !ruby/object:Gem::Version
|
99
|
-
version: '
|
119
|
+
version: '5.0'
|
100
120
|
- !ruby/object:Gem::Dependency
|
101
121
|
name: actionmailer
|
102
122
|
requirement: !ruby/object:Gem::Requirement
|
103
123
|
requirements:
|
104
124
|
- - ">="
|
105
125
|
- !ruby/object:Gem::Version
|
106
|
-
version: '
|
126
|
+
version: '5.0'
|
107
127
|
type: :runtime
|
108
128
|
prerelease: false
|
109
129
|
version_requirements: !ruby/object:Gem::Requirement
|
110
130
|
requirements:
|
111
131
|
- - ">="
|
112
132
|
- !ruby/object:Gem::Version
|
113
|
-
version: '
|
114
|
-
description:
|
133
|
+
version: '5.0'
|
134
|
+
description: |2
|
135
|
+
Clearance is built to support authentication and authorization via an
|
136
|
+
email/password sign-in mechanism in applications.
|
137
|
+
|
138
|
+
It provides some core classes commonly used for these features, along with
|
139
|
+
some opinionated defaults - but is intended to be easy to override.
|
115
140
|
email: support@thoughtbot.com
|
116
141
|
executables: []
|
117
142
|
extensions: []
|
@@ -137,7 +162,6 @@ files:
|
|
137
162
|
- app/mailers/clearance_mailer.rb
|
138
163
|
- app/views/clearance_mailer/change_password.html.erb
|
139
164
|
- app/views/clearance_mailer/change_password.text.erb
|
140
|
-
- app/views/layouts/application.html.erb
|
141
165
|
- app/views/passwords/create.html.erb
|
142
166
|
- app/views/passwords/edit.html.erb
|
143
167
|
- app/views/passwords/new.html.erb
|
@@ -154,10 +178,10 @@ files:
|
|
154
178
|
- config/routes.rb
|
155
179
|
- db/migrate/20110111224543_create_clearance_users.rb
|
156
180
|
- db/schema.rb
|
157
|
-
- gemfiles/rails_4.2.gemfile
|
158
181
|
- gemfiles/rails_5.0.gemfile
|
159
182
|
- gemfiles/rails_5.1.gemfile
|
160
183
|
- gemfiles/rails_5.2.gemfile
|
184
|
+
- gemfiles/rails_6.0.gemfile
|
161
185
|
- lib/clearance.rb
|
162
186
|
- lib/clearance/authentication.rb
|
163
187
|
- lib/clearance/authorization.rb
|
@@ -170,20 +194,16 @@ files:
|
|
170
194
|
- lib/clearance/default_sign_in_guard.rb
|
171
195
|
- lib/clearance/engine.rb
|
172
196
|
- lib/clearance/password_strategies.rb
|
197
|
+
- lib/clearance/password_strategies/argon2.rb
|
173
198
|
- lib/clearance/password_strategies/bcrypt.rb
|
174
|
-
- lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb
|
175
|
-
- lib/clearance/password_strategies/blowfish.rb
|
176
|
-
- lib/clearance/password_strategies/sha1.rb
|
177
199
|
- lib/clearance/rack_session.rb
|
178
200
|
- lib/clearance/rspec.rb
|
179
201
|
- lib/clearance/session.rb
|
180
202
|
- lib/clearance/session_status.rb
|
181
203
|
- lib/clearance/sign_in_guard.rb
|
182
204
|
- lib/clearance/test_unit.rb
|
183
|
-
- lib/clearance/testing.rb
|
184
205
|
- lib/clearance/testing/controller_helpers.rb
|
185
206
|
- lib/clearance/testing/deny_access_matcher.rb
|
186
|
-
- lib/clearance/testing/helpers.rb
|
187
207
|
- lib/clearance/testing/view_helpers.rb
|
188
208
|
- lib/clearance/token.rb
|
189
209
|
- lib/clearance/user.rb
|
@@ -210,12 +230,12 @@ files:
|
|
210
230
|
- lib/generators/clearance/views/views_generator.rb
|
211
231
|
- spec/acceptance/clearance_installation_spec.rb
|
212
232
|
- spec/app_templates/app/controllers/application_controller.rb
|
213
|
-
- spec/app_templates/app/models/rails5/user.rb
|
214
233
|
- spec/app_templates/app/models/user.rb
|
215
234
|
- spec/app_templates/config/initializers/clearance.rb
|
216
235
|
- spec/app_templates/config/routes.rb
|
217
236
|
- spec/app_templates/testapp/Gemfile
|
218
237
|
- spec/app_templates/testapp/app/controllers/home_controller.rb
|
238
|
+
- spec/app_templates/testapp/app/views/layouts/application.html.erb
|
219
239
|
- spec/app_templates/testapp/config/initializers/action_mailer.rb
|
220
240
|
- spec/app_templates/testapp/config/routes.rb
|
221
241
|
- spec/clearance/back_door_spec.rb
|
@@ -227,6 +247,7 @@ files:
|
|
227
247
|
- spec/clearance/session_spec.rb
|
228
248
|
- spec/clearance/sign_in_guard_spec.rb
|
229
249
|
- spec/clearance/testing/controller_helpers_spec.rb
|
250
|
+
- spec/clearance/testing/deny_access_matcher_spec.rb
|
230
251
|
- spec/clearance/testing/view_helpers_spec.rb
|
231
252
|
- spec/clearance/token_spec.rb
|
232
253
|
- spec/configuration_spec.rb
|
@@ -250,11 +271,10 @@ files:
|
|
250
271
|
- spec/helpers/helper_helpers_spec.rb
|
251
272
|
- spec/mailers/clearance_mailer_spec.rb
|
252
273
|
- spec/models/user_spec.rb
|
253
|
-
- spec/password_strategies/
|
274
|
+
- spec/password_strategies/argon2_spec.rb
|
254
275
|
- spec/password_strategies/bcrypt_spec.rb
|
255
|
-
- spec/password_strategies/blowfish_spec.rb
|
256
276
|
- spec/password_strategies/password_strategies_spec.rb
|
257
|
-
- spec/
|
277
|
+
- spec/requests/authentication_cookie_spec.rb
|
258
278
|
- spec/requests/cookie_options_spec.rb
|
259
279
|
- spec/requests/csrf_rotation_spec.rb
|
260
280
|
- spec/requests/password_maintenance_spec.rb
|
@@ -263,18 +283,16 @@ files:
|
|
263
283
|
- spec/spec_helper.rb
|
264
284
|
- spec/support/clearance.rb
|
265
285
|
- spec/support/cookies.rb
|
266
|
-
- spec/support/environment.rb
|
267
286
|
- spec/support/fake_model_with_password_strategy.rb
|
268
287
|
- spec/support/fake_model_without_password_strategy.rb
|
269
288
|
- spec/support/generator_spec_helpers.rb
|
270
|
-
- spec/support/http_method_shim.rb
|
271
289
|
- spec/support/request_with_remember_token.rb
|
272
290
|
- spec/views/view_helpers_spec.rb
|
273
291
|
homepage: https://github.com/thoughtbot/clearance
|
274
292
|
licenses:
|
275
293
|
- MIT
|
276
294
|
metadata: {}
|
277
|
-
post_install_message:
|
295
|
+
post_install_message:
|
278
296
|
rdoc_options:
|
279
297
|
- "--charset=UTF-8"
|
280
298
|
require_paths:
|
@@ -283,15 +301,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
301
|
requirements:
|
284
302
|
- - ">="
|
285
303
|
- !ruby/object:Gem::Version
|
286
|
-
version:
|
304
|
+
version: 2.4.0
|
287
305
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
306
|
requirements:
|
289
307
|
- - ">="
|
290
308
|
- !ruby/object:Gem::Version
|
291
309
|
version: '0'
|
292
310
|
requirements: []
|
293
|
-
rubygems_version: 3.
|
294
|
-
signing_key:
|
311
|
+
rubygems_version: 3.1.2
|
312
|
+
signing_key:
|
295
313
|
specification_version: 4
|
296
314
|
summary: Rails authentication & authorization with email & password.
|
297
315
|
test_files: []
|
@@ -1,23 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<%= csrf_meta_tag %>
|
5
|
-
</head>
|
6
|
-
<body>
|
7
|
-
<div id="header">
|
8
|
-
<% if signed_in? -%>
|
9
|
-
<%= button_to t(".sign_out"), sign_out_path, method: :delete %>
|
10
|
-
<% else -%>
|
11
|
-
<%= link_to t(".sign_in"), sign_in_path %>
|
12
|
-
<% end -%>
|
13
|
-
</div>
|
14
|
-
|
15
|
-
<div id="flash">
|
16
|
-
<% flash.each do |key, value| -%>
|
17
|
-
<div id="flash_<%= key %>"><%=h value %></div>
|
18
|
-
<% end %>
|
19
|
-
</div>
|
20
|
-
|
21
|
-
<%= yield %>
|
22
|
-
</body>
|
23
|
-
</html>
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module PasswordStrategies
|
3
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies` gem
|
4
|
-
module BCryptMigrationFromSHA1
|
5
|
-
DEPRECATION_MESSAGE = "[DEPRECATION] The BCryptMigrationFromSha1 " \
|
6
|
-
"password strategy has been deprecated and will be removed from " \
|
7
|
-
"Clearance 2.0. BCrypt is the only officially supported strategy, " \
|
8
|
-
"though you are free to provide your own. To continue using this " \
|
9
|
-
"strategy, add clearance-deprecated_password_strategies to your " \
|
10
|
-
"Gemfile."
|
11
|
-
|
12
|
-
# @api private
|
13
|
-
class BCryptUser
|
14
|
-
include Clearance::PasswordStrategies::BCrypt
|
15
|
-
|
16
|
-
def initialize(user)
|
17
|
-
@user = user
|
18
|
-
end
|
19
|
-
|
20
|
-
delegate :encrypted_password, :encrypted_password=, to: :@user
|
21
|
-
end
|
22
|
-
|
23
|
-
# @api private
|
24
|
-
class SHA1User
|
25
|
-
include Clearance::PasswordStrategies::SHA1
|
26
|
-
|
27
|
-
def initialize(user)
|
28
|
-
@user = user
|
29
|
-
end
|
30
|
-
|
31
|
-
delegate :salt, :salt=, :encrypted_password, :encrypted_password=, to: :@user
|
32
|
-
end
|
33
|
-
|
34
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
|
35
|
-
# gem
|
36
|
-
def authenticated?(password)
|
37
|
-
warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
|
38
|
-
authenticated_with_sha1?(password) || authenticated_with_bcrypt?(password)
|
39
|
-
end
|
40
|
-
|
41
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
|
42
|
-
# gem
|
43
|
-
def password=(new_password)
|
44
|
-
warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
|
45
|
-
@password = new_password
|
46
|
-
BCryptUser.new(self).password = new_password
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
# @api private
|
52
|
-
def authenticated_with_bcrypt?(password)
|
53
|
-
begin
|
54
|
-
BCryptUser.new(self).authenticated? password
|
55
|
-
rescue ::BCrypt::Errors::InvalidHash
|
56
|
-
false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @api private
|
61
|
-
def authenticated_with_sha1?(password)
|
62
|
-
if sha1_password?
|
63
|
-
if SHA1User.new(self).authenticated? password
|
64
|
-
self.password = password
|
65
|
-
self.save
|
66
|
-
true
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# @api private
|
72
|
-
def sha1_password?
|
73
|
-
self.encrypted_password =~ /^[a-f0-9]{40}$/
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|