Skip to content

Commit

Permalink
Merge pull request #545 from binarylogic/issue_98
Browse files Browse the repository at this point in the history
Allow users to customize invalid session error message
  • Loading branch information
jaredbeck committed Feb 20, 2017
2 parents f77166b + f0bc47f commit 000f9c0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,10 @@
* maintain_sessions config has been removed. It has been split into 2 new options:
log_in_after_create & log_in_after_password_change (@lucasminissale)

* Added
* [#98](https://github.com/binarylogic/authlogic/issues/98)
I18n for invalid session error message. (@eugenebolshakov)

* Fixed
* Random.friendly_token (used for e.g. perishable token) now returns strings
of consistent length, and conforms better to RFC-4648
Expand Down
1 change: 1 addition & 0 deletions lib/authlogic/i18n.rb
Expand Up @@ -46,6 +46,7 @@ module Authlogic
# not_approved: Your account is not approved
# no_authentication_details: You did not provide any details for authentication.
# general_credentials_error: Login/Password combination is not valid
# session_invalid: Your session is invalid and has the following errors:
# models:
# user_session: UserSession (or whatever name you are using)
# attributes:
Expand Down
7 changes: 6 additions & 1 deletion lib/authlogic/session/existence.rb
Expand Up @@ -4,7 +4,12 @@ module Session
module Existence
class SessionInvalidError < ::StandardError # :nodoc:
def initialize(session)
super("Your session is invalid and has the following errors: #{session.errors.full_messages.to_sentence}")
message = I18n.t(
'error_messages.session_invalid',
default: "Your session is invalid and has the following errors:"
)
message += " #{session.errors.full_messages.to_sentence}"
super message
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/session_test/existence_test.rb
Expand Up @@ -71,5 +71,16 @@ def test_destroy
refute session.record
end
end

class SessionInvalidErrorTest < ActiveSupport::TestCase
def test_message
session = UserSession.new
assert !session.valid?
error = Authlogic::Session::Existence::SessionInvalidError.new(session)
message = "Your session is invalid and has the following errors: " +
session.errors.full_messages.to_sentence
assert_equal message, error.message
end
end
end
end

0 comments on commit 000f9c0

Please sign in to comment.