mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:58:06 -05:00
Added translations according to unlock strategy
This commit is contained in:
committed by
Marcos Ferreira
parent
f48b6f1651
commit
afaad713ff
@@ -10,7 +10,11 @@ en:
|
||||
already_authenticated: "You are already signed in."
|
||||
inactive: "Your account is not activated yet."
|
||||
invalid: "Invalid %{authentication_keys} or password."
|
||||
locked: "Your account is locked."
|
||||
locked:
|
||||
none: "Your account is locked."
|
||||
email: "Your account is locked. An email has been sent with instructions on how to unlock your account."
|
||||
time: "Your account is locked. Your account will become available after a certain amount of time."
|
||||
both: "Your account is locked. An email has been sent with instructions on how to unlock your account, or wait a certain amount of time and try again."
|
||||
last_attempt: "You have one more attempt before your account is locked."
|
||||
not_found_in_database: "Invalid %{authentication_keys} or password."
|
||||
timeout: "Your session expired. Please sign in again to continue."
|
||||
|
||||
@@ -122,7 +122,15 @@ module Devise
|
||||
if Devise.paranoid
|
||||
super
|
||||
elsif access_locked? || (lock_strategy_enabled?(:failed_attempts) && attempts_exceeded?)
|
||||
:locked
|
||||
if unlock_strategy_enabled?(:both)
|
||||
'locked.both'.to_sym
|
||||
elsif unlock_strategy_enabled?(:email)
|
||||
'locked.email'.to_sym
|
||||
elsif unlock_strategy_enabled?(:time)
|
||||
'locked.time'.to_sym
|
||||
else
|
||||
'locked.none'.to_sym
|
||||
end
|
||||
elsif lock_strategy_enabled?(:failed_attempts) && last_attempt? && self.class.last_attempt_warning
|
||||
:last_attempt
|
||||
else
|
||||
|
||||
@@ -104,7 +104,7 @@ class LockTest < Devise::IntegrationTest
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, devise: {
|
||||
failure: {user: {locked: "You are locked!"}}
|
||||
failure: {user: {locked: { both: "You are locked!" }}}
|
||||
} do
|
||||
|
||||
user = create_user(locked: true)
|
||||
@@ -118,7 +118,7 @@ class LockTest < Devise::IntegrationTest
|
||||
|
||||
test "user should not be able to sign in when locked" do
|
||||
store_translations :en, devise: {
|
||||
failure: {user: {locked: "You are locked!"}}
|
||||
failure: {user: {locked: {both: "You are locked!"}}}
|
||||
} do
|
||||
|
||||
user = create_user(locked: true)
|
||||
|
||||
@@ -312,7 +312,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'should return last attempt message if user made next-to-last attempt of password entering' do
|
||||
swap Devise, last_attempt_warning: true, lock_strategy: :failed_attempts do
|
||||
swap Devise, last_attempt_warning: true, lock_strategy: :failed_attempts, unlock_strategy: :none do
|
||||
user = create_user
|
||||
user.failed_attempts = Devise.maximum_attempts - 2
|
||||
assert_equal :invalid, user.unauthenticated_message
|
||||
@@ -321,7 +321,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
assert_equal :last_attempt, user.unauthenticated_message
|
||||
|
||||
user.failed_attempts = Devise.maximum_attempts
|
||||
assert_equal :locked, user.unauthenticated_message
|
||||
assert_equal :'locked.none', user.unauthenticated_message
|
||||
end
|
||||
end
|
||||
|
||||
@@ -336,7 +336,22 @@ class LockableTest < ActiveSupport::TestCase
|
||||
test 'should return locked message if user was programatically locked' do
|
||||
user = create_user
|
||||
user.lock_access!
|
||||
assert_equal :locked, user.unauthenticated_message
|
||||
|
||||
swap Devise, unlock_strategy: :none do
|
||||
assert_equal :'locked.none', user.unauthenticated_message
|
||||
end
|
||||
|
||||
swap Devise, unlock_strategy: :both do
|
||||
assert_equal :'locked.both', user.unauthenticated_message
|
||||
end
|
||||
|
||||
swap Devise, unlock_strategy: :email do
|
||||
assert_equal :'locked.email', user.unauthenticated_message
|
||||
end
|
||||
|
||||
swap Devise, unlock_strategy: :time do
|
||||
assert_equal :'locked.time', user.unauthenticated_message
|
||||
end
|
||||
end
|
||||
|
||||
test 'unlock_strategy_enabled? should return true for both, email, and time strategies if :both is used' do
|
||||
|
||||
Reference in New Issue
Block a user