-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration options for failure method redirects (#1002)
This introduces two new accessor values in the Configuration class: * url_after_destroy * url_after_denied_access_when_signed_out These both default to `nil` and their usage defaults to the prior value of `sign_in_url` so that this will be nicely backwards-compatible
- Loading branch information
Showing
6 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ Clearance.configure do |config| | |
config.mailer_sender = "[email protected]" | ||
config.password_strategy = Clearance::PasswordStrategies::BCrypt | ||
config.redirect_url = "/" | ||
config.url_after_destroy = nil | ||
config.url_after_denied_access_when_signed_out = nil | ||
config.rotate_csrf_on_sign_in = true | ||
config.same_site = nil | ||
config.secure_cookie = false | ||
|
@@ -222,8 +224,16 @@ These "failure" methods are called for signed out sessions: | |
- `application#url_after_denied_access_when_signed_out` | ||
- `sessions#url_after_destroy` | ||
|
||
They both default to `sign_in_url`. Override this method to change both of their | ||
behavior, or override them individually to just change one. | ||
You can override the appropriate method in your subclassed controller or you | ||
can set a configuration value for either of these URLs: | ||
|
||
- `Clearance.configuration.url_after_denied_access_when_signed_out` | ||
- `Clearance.configuration.url_after_destroy` | ||
|
||
Both configurations default to `nil` and if not set will default to | ||
`sign_in_url` in `sessions_controller.rb` and `authorization.rb` for backwards | ||
compatibility. | ||
|
||
|
||
### Views | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,20 @@ class Configuration | |
# @return [String] | ||
attr_accessor :redirect_url | ||
|
||
# The default path Clearance will redirect signed out users to. | ||
# Defaults to `nil` so that the controller will use `sign_in_url` | ||
# for backwards compatibility. This can be set here instead of overriding | ||
# the method via an overridden session controller. | ||
# @return [String] | ||
attr_accessor :url_after_destroy | ||
|
||
# The default path Clearance will redirect non-users to when denied access. | ||
# Defaults to `nil` so that the authorization module will use `sign_in_url` | ||
# for backwards compatibility. This can be set here instead of overriding | ||
# the method via an overridden authorization module. | ||
# @return [String] | ||
attr_accessor :url_after_denied_access_when_signed_out | ||
|
||
# Controls whether Clearance will rotate the CSRF token on sign in. | ||
# Defaults to `nil` which generates a warning. Will default to true in | ||
# Clearance 2.0. | ||
|
@@ -140,6 +154,8 @@ def initialize | |
@same_site = nil | ||
@mailer_sender = '[email protected]' | ||
@redirect_url = '/' | ||
@url_after_destroy = nil | ||
@url_after_denied_access_when_signed_out = nil | ||
@rotate_csrf_on_sign_in = true | ||
@routes = true | ||
@secure_cookie = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters