-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect to the previous URL on timeout, closes #1596
- Loading branch information
Showing
3 changed files
with
39 additions
and
6 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
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 |
---|---|---|
|
@@ -53,14 +53,19 @@ def recall | |
|
||
def redirect | ||
store_location! | ||
flash[:alert] = i18n_message | ||
if flash[:timedout] && flash[:alert] | ||
flash.keep(:timedout) | ||
flash.keep(:alert) | ||
else | ||
flash[:alert] = i18n_message | ||
end | ||
redirect_to redirect_url | ||
end | ||
|
||
protected | ||
|
||
def i18n_message(default = nil) | ||
message = warden.message || warden_options[:message] || default || :unauthenticated | ||
message = warden_message || default || :unauthenticated | ||
|
||
if message.is_a?(Symbol) | ||
I18n.t(:"#{scope}.#{message}", :resource_name => scope, | ||
|
@@ -71,6 +76,15 @@ def i18n_message(default = nil) | |
end | ||
|
||
def redirect_url | ||
if warden_message == :timeout | ||
flash[:timedout] = true | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
josevalim
Author
Contributor
|
||
attempted_path || scope_path | ||
else | ||
scope_path | ||
end | ||
end | ||
|
||
def scope_path | ||
opts = {} | ||
route = :"new_#{scope}_session_path" | ||
opts[:format] = request_format unless skip_format? | ||
|
@@ -139,6 +153,10 @@ def warden_options | |
env['warden.options'] | ||
end | ||
|
||
def warden_message | ||
@message ||= warden.message || warden_options[:message] | ||
end | ||
|
||
def scope | ||
@scope ||= warden_options[:scope] || Devise.default_scope | ||
end | ||
|
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 line kind of tripped us up a bit when we upgraded to Devise 2.0. Evertime we visit a page after our session has timed out we have been receiving two flash messages. One that is expected "Your session expired, please sign in again to continue." and one that is not, just the word : "true". In our app we have a helper that displays flash messages, even non-standard ones, and this :timedout flash message was always displaying. Is it needed? Or do we need to remove that extra flash message handling from our app to fix the issue?