clearance 1.10.1 → 1.17.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.

Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +20 -8
  4. data/.yardopts +3 -0
  5. data/Appraisals +13 -16
  6. data/Gemfile +7 -5
  7. data/Gemfile.lock +124 -130
  8. data/NEWS.md +171 -2
  9. data/README.md +99 -42
  10. data/app/controllers/clearance/passwords_controller.rb +35 -21
  11. data/app/controllers/clearance/sessions_controller.rb +17 -3
  12. data/app/controllers/clearance/users_controller.rb +10 -4
  13. data/app/mailers/clearance_mailer.rb +2 -3
  14. data/app/views/clearance_mailer/change_password.text.erb +1 -1
  15. data/app/views/layouts/application.html.erb +0 -1
  16. data/bin/setup +6 -2
  17. data/clearance.gemspec +5 -2
  18. data/config/locales/clearance.en.yml +9 -0
  19. data/gemfiles/rails_4.2.gemfile +20 -0
  20. data/gemfiles/rails_5.0.gemfile +21 -0
  21. data/gemfiles/rails_5.1.gemfile +21 -0
  22. data/gemfiles/rails_5.2.gemfile +21 -0
  23. data/lib/clearance/authentication.rb +63 -3
  24. data/lib/clearance/authorization.rb +48 -5
  25. data/lib/clearance/back_door.rb +55 -6
  26. data/lib/clearance/configuration.rb +50 -10
  27. data/lib/clearance/constraints/signed_in.rb +21 -0
  28. data/lib/clearance/constraints/signed_out.rb +12 -0
  29. data/lib/clearance/constraints.rb +12 -0
  30. data/lib/clearance/controller.rb +13 -0
  31. data/lib/clearance/default_sign_in_guard.rb +17 -0
  32. data/lib/clearance/engine.rb +18 -5
  33. data/lib/clearance/password_strategies/bcrypt.rb +16 -21
  34. data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +10 -0
  35. data/lib/clearance/password_strategies/blowfish.rb +10 -1
  36. data/lib/clearance/password_strategies/sha1.rb +9 -0
  37. data/lib/clearance/password_strategies.rb +13 -0
  38. data/lib/clearance/rack_session.rb +13 -0
  39. data/lib/clearance/rspec.rb +15 -4
  40. data/lib/clearance/session.rb +62 -13
  41. data/lib/clearance/session_status.rb +7 -0
  42. data/lib/clearance/sign_in_guard.rb +65 -0
  43. data/lib/clearance/test_unit.rb +3 -3
  44. data/lib/clearance/testing/controller_helpers.rb +57 -0
  45. data/lib/clearance/testing/deny_access_matcher.rb +36 -2
  46. data/lib/clearance/testing/helpers.rb +9 -25
  47. data/lib/clearance/testing/view_helpers.rb +32 -0
  48. data/lib/clearance/token.rb +7 -0
  49. data/lib/clearance/user.rb +183 -4
  50. data/lib/clearance/version.rb +1 -1
  51. data/lib/generators/clearance/install/install_generator.rb +28 -9
  52. data/lib/generators/clearance/install/templates/README +1 -1
  53. data/lib/generators/clearance/install/templates/clearance.rb +1 -0
  54. data/lib/generators/clearance/install/templates/db/migrate/{add_clearance_to_users.rb → add_clearance_to_users.rb.erb} +3 -3
  55. data/lib/generators/clearance/install/templates/db/migrate/{create_users.rb → create_users.rb.erb} +2 -2
  56. data/lib/generators/clearance/install/templates/user.rb.erb +3 -0
  57. data/lib/generators/clearance/routes/routes_generator.rb +23 -0
  58. data/lib/generators/clearance/routes/templates/routes.rb +7 -7
  59. data/lib/generators/clearance/specs/templates/factories/clearance.rb +2 -2
  60. data/lib/generators/clearance/specs/templates/features/clearance/user_signs_out_spec.rb.tt +1 -1
  61. data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt +12 -3
  62. data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb.tt +3 -3
  63. data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_up_spec.rb.tt +1 -1
  64. data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb.tt +2 -2
  65. data/lib/generators/clearance/specs/templates/support/features/clearance_helpers.rb +2 -2
  66. data/spec/acceptance/clearance_installation_spec.rb +15 -7
  67. data/spec/app_templates/app/models/rails5/user.rb +5 -0
  68. data/spec/app_templates/config/initializers/clearance.rb +2 -0
  69. data/spec/app_templates/testapp/Gemfile +1 -1
  70. data/spec/app_templates/testapp/app/controllers/home_controller.rb +5 -1
  71. data/spec/clearance/back_door_spec.rb +70 -6
  72. data/spec/clearance/session_spec.rb +4 -16
  73. data/spec/clearance/testing/controller_helpers_spec.rb +38 -0
  74. data/spec/clearance/testing/view_helpers_spec.rb +37 -0
  75. data/spec/configuration_spec.rb +79 -86
  76. data/spec/controllers/apis_controller_spec.rb +6 -2
  77. data/spec/controllers/forgeries_controller_spec.rb +12 -3
  78. data/spec/controllers/passwords_controller_spec.rb +74 -38
  79. data/spec/controllers/permissions_controller_spec.rb +13 -3
  80. data/spec/controllers/sessions_controller_spec.rb +40 -11
  81. data/spec/controllers/users_controller_spec.rb +16 -8
  82. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  83. data/spec/dummy/application.rb +9 -11
  84. data/spec/factories.rb +5 -5
  85. data/spec/generators/clearance/install/install_generator_spec.rb +29 -3
  86. data/spec/generators/clearance/routes/routes_generator_spec.rb +5 -1
  87. data/spec/helpers/helper_helpers_spec.rb +10 -0
  88. data/spec/{user_spec.rb → models/user_spec.rb} +10 -1
  89. data/spec/password_strategies/blowfish_spec.rb +1 -1
  90. data/spec/requests/cookie_options_spec.rb +52 -0
  91. data/spec/requests/csrf_rotation_spec.rb +35 -0
  92. data/spec/requests/password_maintenance_spec.rb +18 -0
  93. data/spec/requests/token_expiration_spec.rb +54 -0
  94. data/spec/spec_helper.rb +22 -4
  95. data/spec/support/environment.rb +12 -0
  96. data/spec/support/generator_spec_helpers.rb +13 -1
  97. data/spec/support/http_method_shim.rb +25 -0
  98. data/spec/support/request_with_remember_token.rb +5 -0
  99. data/spec/views/view_helpers_spec.rb +10 -0
  100. metadata +69 -15
  101. data/gemfiles/rails3.2.gemfile +0 -18
  102. data/gemfiles/rails4.0.gemfile +0 -19
  103. data/gemfiles/rails4.1.gemfile +0 -18
  104. data/gemfiles/rails4.2.gemfile +0 -18
  105. data/lib/generators/clearance/install/templates/user.rb +0 -3
  106. data/spec/clearance/testing/helpers_spec.rb +0 -38
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/thoughtbot/clearance.svg)](http://travis-ci.org/thoughtbot/clearance?branch=master)
4
4
  [![Code Climate](https://codeclimate.com/github/thoughtbot/clearance.svg)](https://codeclimate.com/github/thoughtbot/clearance)
5
+ [![Documentation Quality](https://inch-ci.org/github/thoughtbot/clearance.svg?branch=master)](https://inch-ci.org/github/thoughtbot/clearance)
6
+ [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
5
7
 
6
8
  Rails authentication with email & password.
7
9
 
@@ -15,22 +17,30 @@ monitored by contributors.
15
17
  [GitHub Issues]: https://github.com/thoughtbot/clearance/issues
16
18
  [Stack Overflow]: http://stackoverflow.com/questions/tagged/clearance
17
19
 
18
- ## Install
20
+ ## Getting Started
19
21
 
20
22
  Clearance is a Rails engine tested against Rails `>= 3.2` and Ruby `>= 1.9.3`.
21
- To get started, add Clearance to your `Gemfile`, `bundle install`, and run the
22
- `install generator`:
23
+
24
+ You can add it to your Gemfile with:
25
+
26
+ ```sh
27
+ gem "clearance"
28
+ ```
29
+
30
+ Run the bundle command to install it.
31
+
32
+ After you install Clearance, you need to run the generator:
23
33
 
24
34
  ```sh
25
35
  $ rails generate clearance:install
26
36
  ```
27
37
 
28
- The generator:
38
+ The Clearance install generator:
29
39
 
30
40
  * Inserts `Clearance::User` into your `User` model
31
41
  * Inserts `Clearance::Controller` into your `ApplicationController`
32
- * Creates an initializer to allow further configuration.
33
- * Creates a migration that either creates a users table or adds any necessary
42
+ * Creates an initializer file to allow further configuration.
43
+ * Creates a migration file that either create a users table or adds any necessary
34
44
  columns to the existing table.
35
45
 
36
46
  ## Configure
@@ -40,21 +50,26 @@ Override any of these defaults in `config/initializers/clearance.rb`:
40
50
  ```ruby
41
51
  Clearance.configure do |config|
42
52
  config.allow_sign_up = true
43
- config.cookie_domain = '.example.com'
53
+ config.cookie_domain = ".example.com"
44
54
  config.cookie_expiration = lambda { |cookies| 1.year.from_now.utc }
45
- config.cookie_name = 'remember_token'
46
- config.cookie_path = '/'
55
+ config.cookie_name = "remember_token"
56
+ config.cookie_path = "/"
47
57
  config.routes = true
48
58
  config.httponly = false
49
- config.mailer_sender = 'reply@example.com'
59
+ config.mailer_sender = "reply@example.com"
50
60
  config.password_strategy = Clearance::PasswordStrategies::BCrypt
51
- config.redirect_url = '/'
61
+ config.redirect_url = "/"
62
+ config.rotate_csrf_on_sign_in = false
52
63
  config.secure_cookie = false
53
64
  config.sign_in_guards = []
54
65
  config.user_model = User
55
66
  end
56
67
  ```
57
68
 
69
+ The install generator will set `rotate_csrf_on_sign_in` to `true`, so new
70
+ installations will get this behavior from the start. This helps avoid session
71
+ fixation attacks, and will become the default in Clearance 2.0.
72
+
58
73
  ## Use
59
74
 
60
75
  ### Access Control
@@ -77,15 +92,15 @@ at the routing layer:
77
92
  ```ruby
78
93
  Blog::Application.routes.draw do
79
94
  constraints Clearance::Constraints::SignedIn.new { |user| user.admin? } do
80
- root to: 'admin/dashboards#show', as: :admin_root
95
+ root to: "admin/dashboards#show", as: :admin_root
81
96
  end
82
97
 
83
98
  constraints Clearance::Constraints::SignedIn.new do
84
- root to: 'dashboards#show', as: :signed_in_root
99
+ root to: "dashboards#show", as: :signed_in_root
85
100
  end
86
101
 
87
102
  constraints Clearance::Constraints::SignedOut.new do
88
- root to: 'marketing#index'
103
+ root to: "marketing#index"
89
104
  end
90
105
  end
91
106
  ```
@@ -111,7 +126,7 @@ should change the `mailer_sender` default, used in the email's "from" header:
111
126
 
112
127
  ```ruby
113
128
  Clearance.configure do |config|
114
- config.mailer_sender = 'reply@example.com'
129
+ config.mailer_sender = "reply@example.com"
115
130
  end
116
131
  ```
117
132
 
@@ -143,10 +158,17 @@ end
143
158
  See [config/routes.rb](/config/routes.rb) for the default set of routes.
144
159
 
145
160
  As of Clearance 1.5 it is recommended that you disable Clearance routes and take
146
- full control over routing and URL design.
161
+ full control over routing and URL design. This ensures that your app's URL design
162
+ won't be affected if the gem's routes and URL design are changed.
147
163
 
148
- To disable the routes, set `config.routes = false`. You can optionally run
149
- `rails generate clearance:routes` to dump a copy of the default routes into your
164
+ To disable the routes, change the `routes` configuration option to false:
165
+
166
+ ```ruby
167
+ Clearance.configure do |config|
168
+ config.routes = false
169
+ end
170
+ ```
171
+ You can optionally run `rails generate clearance:routes` to dump a copy of the default routes into your
150
172
  application for modification.
151
173
 
152
174
  ### Controllers
@@ -165,7 +187,9 @@ class UsersController < Clearance::UsersController
165
187
  ```
166
188
 
167
189
  ### Redirects
168
- All of these controller methods redirect to `'/'` by default:
190
+
191
+ All of these controller methods redirect to
192
+ `Clearance.configuration.redirect_url` (which is `/` by default):
169
193
 
170
194
  ```
171
195
  passwords#url_after_update
@@ -173,10 +197,13 @@ sessions#url_after_create
173
197
  sessions#url_for_signed_in_users
174
198
  users#url_after_create
175
199
  application#url_after_denied_access_when_signed_in
176
- application#url_after_denied_access_when_signed_out
177
200
  ```
178
201
 
179
202
  To override them all at once, change the global configuration of `redirect_url`.
203
+ To change individual URLs, override the appropriate method.
204
+
205
+ `application#url_after_denied_access_when_signed_out` defaults to `sign_in_url`.
206
+ Override this method to change this.
180
207
 
181
208
  ### Views
182
209
 
@@ -206,23 +233,26 @@ $ rails generate clearance:views
206
233
 
207
234
  By default, Clearance uses your application's default layout. If you would like
208
235
  to change the layout that Clearance uses when rendering its views, simply
209
- specify the layout in an initializer.
236
+ specify the layout in the `config/application.rb`
210
237
 
211
238
  ```ruby
212
- Clearance::PasswordsController.layout 'my_passwords_layout'
213
- Clearance::SessionsController.layout 'my_sessions_layout'
214
- Clearance::UsersController.layout 'my_admin_layout'
239
+ config.to_prepare do
240
+ Clearance::PasswordsController.layout "my_passwords_layout"
241
+ Clearance::SessionsController.layout "my_sessions_layout"
242
+ Clearance::UsersController.layout "my_admin_layout"
243
+ end
215
244
  ```
216
245
 
217
246
  ### Translations
218
247
 
219
- All flash messages and email subject lines are stored in [i18n translations]
220
- (http://guides.rubyonrails.org/i18n.html). Override them like any other
248
+ All flash messages and email subject lines are stored in [i18n translations](http://guides.rubyonrails.org/i18n.html). Override them like any other
221
249
  translation.
222
250
 
223
251
  See [config/locales/clearance.en.yml](/config/locales/clearance.en.yml) for the
224
252
  default behavior.
225
253
 
254
+ You can also install [clearance-i18n](https://github.com/thoughtbot/clearance-i18n)
255
+ for access to additional, user-contributed translations.
226
256
 
227
257
  ### User Model
228
258
 
@@ -324,11 +354,25 @@ Usage:
324
354
  visit root_path(as: user)
325
355
  ```
326
356
 
357
+ Additionally, if `User#to_param` is overridden, you can pass a block in
358
+ order to override the default behavior:
359
+
360
+ ```ruby
361
+ # config/environments/test.rb
362
+ MyRailsApp::Application.configure do
363
+ # ...
364
+ config.middleware.use Clearance::BackDoor do |username|
365
+ Clearance.configuration.user_model.find_by(username: username)
366
+ end
367
+ # ...
368
+ end
369
+ ```
370
+
327
371
  ### Ready Made Feature Specs
328
372
 
329
373
  If you're using RSpec, you can generate feature specs to help prevent
330
374
  regressions in Clearance's integration with your Rails app over time. These
331
- feature specs, will also require `factory_girl_rails`.
375
+ feature specs, will also require `factory_bot_rails`.
332
376
 
333
377
  To Generate the clearance specs, run:
334
378
 
@@ -338,22 +382,26 @@ $ rails generate clearance:specs
338
382
 
339
383
  ### Controller Test Helpers
340
384
 
341
- To test controller actions that are protected by `before_filter :require_login`,
385
+ To test controller actions that are protected by `before_action :require_login`,
342
386
  require Clearance's test helpers in your test suite.
343
387
 
344
388
  For `rspec`, add the following line to your `spec/rails_helper.rb` or
345
389
  `spec/spec_helper` if `rails_helper` does not exist:
346
390
 
347
391
  ```ruby
348
- require 'clearance/rspec'
392
+ require "clearance/rspec"
349
393
  ```
350
394
 
351
395
  For `test-unit`, add this line to your `test/test_helper.rb`:
352
396
 
353
397
  ```ruby
354
- require 'clearance/test_unit'
398
+ require "clearance/test_unit"
355
399
  ```
356
400
 
401
+ **Note for Rails 5:** the default generated controller tests are now
402
+ integration tests. You will need to use the
403
+ [backdoor middleware](#fast-feature-specs) instead.
404
+
357
405
  This will make `Clearance::Controller` methods work in your controllers
358
406
  during functional tests and provide access to helper methods like:
359
407
 
@@ -363,6 +411,23 @@ sign_in_as(user)
363
411
  sign_out
364
412
  ```
365
413
 
414
+ ### View and Helper Spec Helpers
415
+
416
+ Does the view or helper you're testing reference `signed_in?`, `signed_out?` or
417
+ `current_user`? If you `require 'clearance/rspec'`, you will have the following
418
+ helpers available in your view specs:
419
+
420
+ ```ruby
421
+ sign_in
422
+ sign_in_as(user)
423
+ ```
424
+
425
+ These will make the clearance view helpers work as expected by signing in either
426
+ a new instance of your user model (`sign_in`) or the object you pass to
427
+ `sign_in_as`. If you do not call one of these sign in helpers or otherwise set
428
+ `current_user` in your view specs, your view will behave as if there is no
429
+ current user: `signed_in?` will be false and `signed_out?` will be true.
430
+
366
431
  ## Contributing
367
432
 
368
433
  Please see [CONTRIBUTING.md].
@@ -371,31 +436,23 @@ Thank you, [contributors]!
371
436
  [CONTRIBUTING.md]: /CONTRIBUTING.md
372
437
  [contributors]: https://github.com/thoughtbot/clearance/graphs/contributors
373
438
 
374
- ## Need Help?
375
-
376
- We offer 1-on-1 coaching. We can help you set up Clearance, write authentication
377
- and authorization extensions for your application, and work out a permission and
378
- role model which works for you. [Get in touch][coaching].
379
-
380
439
  ## License
381
440
 
382
- Clearance is copyright © 2009 thoughtbot. It is free software, and may be
441
+ Clearance is copyright © 2009-2019 thoughtbot. It is free software, and may be
383
442
  redistributed under the terms specified in the [`LICENSE`] file.
384
443
 
385
444
  [`LICENSE`]: /LICENSE
386
445
 
387
446
  ## About thoughtbot
388
447
 
389
- ![thoughtbot](https://thoughtbot.com/logo.png)
448
+ ![thoughtbot](http://presskit.thoughtbot.com/images/thoughtbot-logo-for-readmes.svg)
390
449
 
391
450
  Clearance is maintained and funded by thoughtbot, inc.
392
451
  The names and logos for thoughtbot are trademarks of thoughtbot, inc.
393
452
 
394
453
  We love open source software!
395
- See [our other projects][community],
396
- [hire us][hire] to design, develop, and grow your product,
397
- or get in touch about [1-on-1 coaching][coaching].
454
+ See [our other projects][community] or
455
+ [hire us][hire] to design, develop, and grow your product.
398
456
 
399
457
  [community]: https://thoughtbot.com/community?utm_source=github
400
458
  [hire]: https://thoughtbot.com/hire-us?utm_source=github
401
- [coaching]: http://coaching.thoughtbot.com/rails/?utm_source=github
@@ -1,10 +1,23 @@
1
1
  require 'active_support/deprecation'
2
2
 
3
3
  class Clearance::PasswordsController < Clearance::BaseController
4
- skip_before_filter :require_login, only: [:create, :edit, :new, :update]
5
- skip_before_filter :authorize, only: [:create, :edit, :new, :update]
6
- before_filter :forbid_missing_token, only: [:edit, :update]
7
- before_filter :forbid_non_existent_user, only: [:edit, :update]
4
+ if respond_to?(:before_action)
5
+ skip_before_action :require_login,
6
+ only: [:create, :edit, :new, :update],
7
+ raise: false
8
+ skip_before_action :authorize,
9
+ only: [:create, :edit, :new, :update],
10
+ raise: false
11
+ before_action :ensure_existing_user, only: [:edit, :update]
12
+ else
13
+ skip_before_filter :require_login,
14
+ only: [:create, :edit, :new, :update],
15
+ raise: false
16
+ skip_before_filter :authorize,
17
+ only: [:create, :edit, :new, :update],
18
+ raise: false
19
+ before_filter :ensure_existing_user, only: [:edit, :update]
20
+ end
8
21
 
9
22
  def create
10
23
  if user = find_user_for_create
@@ -16,7 +29,13 @@ class Clearance::PasswordsController < Clearance::BaseController
16
29
 
17
30
  def edit
18
31
  @user = find_user_for_edit
19
- render template: 'passwords/edit'
32
+
33
+ if params[:token]
34
+ session[:password_reset_token] = params[:token]
35
+ redirect_to url_for
36
+ else
37
+ render template: 'passwords/edit'
38
+ end
20
39
  end
21
40
 
22
41
  def new
@@ -29,6 +48,7 @@ class Clearance::PasswordsController < Clearance::BaseController
29
48
  if @user.update_password password_reset_params
30
49
  sign_in @user
31
50
  redirect_to url_after_update
51
+ session[:password_reset_token] = nil
32
52
  else
33
53
  flash_failure_after_update
34
54
  render template: 'passwords/edit'
@@ -40,7 +60,7 @@ class Clearance::PasswordsController < Clearance::BaseController
40
60
  def deliver_email(user)
41
61
  mail = ::ClearanceMailer.change_password(user)
42
62
 
43
- if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.2.0")
63
+ if mail.respond_to?(:deliver_later)
44
64
  mail.deliver_later
45
65
  else
46
66
  mail.deliver
@@ -58,9 +78,10 @@ class Clearance::PasswordsController < Clearance::BaseController
58
78
 
59
79
  def find_user_by_id_and_confirmation_token
60
80
  user_param = Clearance.configuration.user_id_parameter
81
+ token = params[:token] || session[:password_reset_token]
61
82
 
62
83
  Clearance.configuration.user_model.
63
- find_by_id_and_confirmation_token params[user_param], params[:token].to_s
84
+ find_by_id_and_confirmation_token params[user_param], token.to_s
64
85
  end
65
86
 
66
87
  def find_user_for_create
@@ -76,6 +97,13 @@ class Clearance::PasswordsController < Clearance::BaseController
76
97
  find_user_by_id_and_confirmation_token
77
98
  end
78
99
 
100
+ def ensure_existing_user
101
+ unless find_user_by_id_and_confirmation_token
102
+ flash_failure_when_forbidden
103
+ render template: "passwords/new"
104
+ end
105
+ end
106
+
79
107
  def flash_failure_when_forbidden
80
108
  flash.now[:notice] = translate(:forbidden,
81
109
  scope: [:clearance, :controllers, :passwords],
@@ -88,20 +116,6 @@ class Clearance::PasswordsController < Clearance::BaseController
88
116
  default: t('flashes.failure_after_update'))
89
117
  end
90
118
 
91
- def forbid_missing_token
92
- if params[:token].to_s.blank?
93
- flash_failure_when_forbidden
94
- render template: 'passwords/new'
95
- end
96
- end
97
-
98
- def forbid_non_existent_user
99
- unless find_user_by_id_and_confirmation_token
100
- flash_failure_when_forbidden
101
- render template: 'passwords/new'
102
- end
103
- end
104
-
105
119
  def url_after_create
106
120
  sign_in_url
107
121
  end
@@ -1,7 +1,21 @@
1
1
  class Clearance::SessionsController < Clearance::BaseController
2
- before_filter :redirect_signed_in_users, only: [:new]
3
- skip_before_filter :require_login, only: [:create, :new, :destroy]
4
- skip_before_filter :authorize, only: [:create, :new, :destroy]
2
+ if respond_to?(:before_action)
3
+ before_action :redirect_signed_in_users, only: [:new]
4
+ skip_before_action :require_login,
5
+ only: [:create, :new, :destroy],
6
+ raise: false
7
+ skip_before_action :authorize,
8
+ only: [:create, :new, :destroy],
9
+ raise: false
10
+ else
11
+ before_filter :redirect_signed_in_users, only: [:new]
12
+ skip_before_filter :require_login,
13
+ only: [:create, :new, :destroy],
14
+ raise: false
15
+ skip_before_filter :authorize,
16
+ only: [:create, :new, :destroy],
17
+ raise: false
18
+ end
5
19
 
6
20
  def create
7
21
  @user = authenticate(params)
@@ -1,7 +1,13 @@
1
1
  class Clearance::UsersController < Clearance::BaseController
2
- before_filter :redirect_signed_in_users, only: [:create, :new]
3
- skip_before_filter :require_login, only: [:create, :new]
4
- skip_before_filter :authorize, only: [:create, :new]
2
+ if respond_to?(:before_action)
3
+ before_action :redirect_signed_in_users, only: [:create, :new]
4
+ skip_before_action :require_login, only: [:create, :new], raise: false
5
+ skip_before_action :authorize, only: [:create, :new], raise: false
6
+ else
7
+ before_filter :redirect_signed_in_users, only: [:create, :new]
8
+ skip_before_filter :require_login, only: [:create, :new], raise: false
9
+ skip_before_filter :authorize, only: [:create, :new], raise: false
10
+ end
5
11
 
6
12
  def new
7
13
  @user = user_from_params
@@ -50,6 +56,6 @@ class Clearance::UsersController < Clearance::BaseController
50
56
  end
51
57
 
52
58
  def user_params
53
- params[:user] || Hash.new
59
+ params[Clearance.configuration.user_parameter] || Hash.new
54
60
  end
55
61
  end
@@ -6,9 +6,8 @@ class ClearanceMailer < ActionMailer::Base
6
6
  to: @user.email,
7
7
  subject: I18n.t(
8
8
  :change_password,
9
- scope: [:clearance, :models, :clearance_mailer],
10
- default: "Change your password"
11
- )
9
+ scope: [:clearance, :models, :clearance_mailer]
10
+ ),
12
11
  )
13
12
  end
14
13
  end
@@ -1,4 +1,4 @@
1
- <%= t(".opening") %></p>
1
+ <%= t(".opening") %>
2
2
 
3
3
  <%= edit_user_password_url(@user, token: @user.confirmation_token.html_safe) %>
4
4
 
@@ -1,7 +1,6 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <%= javascript_include_tag 'application' %>
5
4
  <%= csrf_meta_tag %>
6
5
  </head>
7
6
  <body>
data/bin/setup CHANGED
@@ -4,8 +4,12 @@ set -e
4
4
 
5
5
  # Install required gems, including Appraisal, which helps us test against
6
6
  # multiple Rails versions
7
- bundle install
8
- bundle exec appraisal install
7
+ gem install bundler --conservative
8
+ bundle check || bundle install
9
+
10
+ if [ -z "$CI" ]; then
11
+ bundle exec appraisal install
12
+ fi
9
13
 
10
14
  # Set up database for the application that Clearance tests against
11
15
  RAILS_ENV=test bundle exec rake dummy:db:reset
data/clearance.gemspec CHANGED
@@ -5,7 +5,10 @@ require 'date'
5
5
  Gem::Specification.new do |s|
6
6
  s.add_dependency 'bcrypt'
7
7
  s.add_dependency 'email_validator', '~> 1.4'
8
- s.add_dependency 'rails', '>= 3.1'
8
+ s.add_dependency 'railties', '>= 3.1'
9
+ s.add_dependency 'activemodel', '>= 3.1'
10
+ s.add_dependency 'activerecord', '>= 3.1'
11
+ s.add_dependency 'actionmailer', '>= 3.1'
9
12
  s.authors = [
10
13
  'Dan Croak',
11
14
  'Eugene Bolshakov',
@@ -30,7 +33,7 @@ Gem::Specification.new do |s|
30
33
  s.email = 'support@thoughtbot.com'
31
34
  s.extra_rdoc_files = %w(LICENSE README.md)
32
35
  s.files = `git ls-files`.split("\n")
33
- s.homepage = 'http://github.com/thoughtbot/clearance'
36
+ s.homepage = 'https://github.com/thoughtbot/clearance'
34
37
  s.license = 'MIT'
35
38
  s.name = %q{clearance}
36
39
  s.rdoc_options = ['--charset=UTF-8']
@@ -1,5 +1,9 @@
1
1
  ---
2
2
  en:
3
+ clearance:
4
+ models:
5
+ clearance_mailer:
6
+ change_password: Change your password
3
7
  clearance_mailer:
4
8
  change_password:
5
9
  closing: If you didn't request this, ignore this email. Your password has
@@ -12,12 +16,17 @@ en:
12
16
  failure_after_update: Password can't be blank.
13
17
  failure_when_forbidden: Please double check the URL or try submitting
14
18
  the form again.
19
+ failure_when_not_signed_in: Please sign in to continue.
15
20
  helpers:
16
21
  label:
17
22
  password:
18
23
  email: Email address
19
24
  password_reset:
20
25
  password: Choose password
26
+ session:
27
+ password: Password
28
+ user:
29
+ password: Password
21
30
  submit:
22
31
  password:
23
32
  submit: Reset password
@@ -0,0 +1,20 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "addressable", "~> 2.6.0"
6
+ gem "appraisal"
7
+ gem "ammeter"
8
+ gem "bundler", "~> 1.3"
9
+ gem "capybara", ">= 2.6.2"
10
+ gem "database_cleaner", "~> 1.0"
11
+ gem "factory_bot_rails", "~> 5.0"
12
+ gem "nokogiri", "~> 1.10.0"
13
+ gem "rspec-rails", "~> 3.1"
14
+ gem "shoulda-matchers", "~> 4.0"
15
+ gem "sqlite3", "~> 1.3.13"
16
+ gem "timecop", "~> 0.6"
17
+ gem "pry", require: false
18
+ gem "railties", "~> 4.2.0"
19
+
20
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "addressable", "~> 2.6.0"
6
+ gem "appraisal"
7
+ gem "ammeter"
8
+ gem "bundler", "~> 1.3"
9
+ gem "capybara", ">= 2.6.2"
10
+ gem "database_cleaner", "~> 1.0"
11
+ gem "factory_bot_rails", "~> 5.0"
12
+ gem "nokogiri", "~> 1.10.0"
13
+ gem "rspec-rails", "~> 3.1"
14
+ gem "shoulda-matchers", "~> 4.0"
15
+ gem "sqlite3", "~> 1.3.13"
16
+ gem "timecop", "~> 0.6"
17
+ gem "pry", require: false
18
+ gem "railties", "~> 5.0.0"
19
+ gem "rails-controller-testing"
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "addressable", "~> 2.6.0"
6
+ gem "appraisal"
7
+ gem "ammeter"
8
+ gem "bundler", "~> 1.3"
9
+ gem "capybara", ">= 2.6.2"
10
+ gem "database_cleaner", "~> 1.0"
11
+ gem "factory_bot_rails", "~> 5.0"
12
+ gem "nokogiri", "~> 1.10.0"
13
+ gem "rspec-rails", "~> 3.1"
14
+ gem "shoulda-matchers", "~> 4.0"
15
+ gem "sqlite3", "~> 1.3.13"
16
+ gem "timecop", "~> 0.6"
17
+ gem "pry", require: false
18
+ gem "railties", "~> 5.1.0"
19
+ gem "rails-controller-testing"
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "addressable", "~> 2.6.0"
6
+ gem "appraisal"
7
+ gem "ammeter"
8
+ gem "bundler", "~> 1.3"
9
+ gem "capybara", ">= 2.6.2"
10
+ gem "database_cleaner", "~> 1.0"
11
+ gem "factory_bot_rails", "~> 5.0"
12
+ gem "nokogiri", "~> 1.10.0"
13
+ gem "rspec-rails", "~> 3.1"
14
+ gem "shoulda-matchers", "~> 4.0"
15
+ gem "sqlite3", "~> 1.3.13"
16
+ gem "timecop", "~> 0.6"
17
+ gem "pry", require: false
18
+ gem "railties", "~> 5.2.0"
19
+ gem "rails-controller-testing"
20
+
21
+ gemspec path: "../"