mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Move failure messages from devise.sessions to devise.failure.
This commit is contained in:
parent
23e608e27b
commit
b974b7bc78
11 changed files with 38 additions and 22 deletions
|
@ -17,6 +17,7 @@
|
|||
* TokenAuthenticatable now works with HTTP Basic Auth.
|
||||
* Allow :unlock_strategy to be :none and add :lock_strategy which can be :failed_attempts or none. Setting those values to :none means that you want to handle lock and unlocking by yourself.
|
||||
* No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3.
|
||||
* All messages under devise.sessions, except :signed_in and :signed_out, should be moved to devise.failure.
|
||||
|
||||
* bug fix
|
||||
* Do not allow unlockable strategies based on time to access a controller.
|
||||
|
@ -27,6 +28,7 @@
|
|||
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
|
||||
* Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead.
|
||||
* Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options.
|
||||
* All messages under devise.sessions, except :signed_in and :signed_out, should be moved to devise.failure.
|
||||
|
||||
== 1.0.5
|
||||
|
||||
|
|
|
@ -6,9 +6,7 @@ en:
|
|||
not_locked: "was not locked"
|
||||
|
||||
devise:
|
||||
sessions:
|
||||
signed_in: 'Signed in successfully.'
|
||||
signed_out: 'Signed out successfully.'
|
||||
failure:
|
||||
unauthenticated: 'You need to sign in or sign up before continuing.'
|
||||
unconfirmed: 'You have to confirm your account before continuing.'
|
||||
locked: 'Your account is locked.'
|
||||
|
@ -16,6 +14,9 @@ en:
|
|||
invalid_token: 'Invalid authentication token.'
|
||||
timeout: 'Your session expired, please sign in again to continue.'
|
||||
inactive: 'Your account was not activated yet.'
|
||||
sessions:
|
||||
signed_in: 'Signed in successfully.'
|
||||
signed_out: 'Signed out successfully.'
|
||||
passwords:
|
||||
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
||||
updated: 'Your password was changed successfully. You are now signed in.'
|
||||
|
|
|
@ -29,11 +29,10 @@ module Devise
|
|||
|
||||
# Constants which holds devise configuration for extensions. Those should
|
||||
# not be modified by the "end user".
|
||||
ALL = []
|
||||
CONTROLLERS = ActiveSupport::OrderedHash.new
|
||||
ROUTES = ActiveSupport::OrderedHash.new
|
||||
STRATEGIES = ActiveSupport::OrderedHash.new
|
||||
FLASH_MESSAGES = [:unauthenticated]
|
||||
ALL = []
|
||||
CONTROLLERS = ActiveSupport::OrderedHash.new
|
||||
ROUTES = ActiveSupport::OrderedHash.new
|
||||
STRATEGIES = ActiveSupport::OrderedHash.new
|
||||
|
||||
# True values used to check params
|
||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
||||
|
@ -189,11 +188,10 @@ module Devise
|
|||
#
|
||||
def self.add_module(module_name, options = {})
|
||||
ALL << module_name
|
||||
options.assert_valid_keys(:strategy, :model, :controller, :route, :flash)
|
||||
options.assert_valid_keys(:strategy, :model, :controller, :route)
|
||||
|
||||
config = {
|
||||
:strategy => STRATEGIES,
|
||||
:flash => FLASH_MESSAGES,
|
||||
:route => ROUTES,
|
||||
:controller => CONTROLLERS
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ module Devise
|
|||
|
||||
if message.is_a?(Symbol)
|
||||
I18n.t(:"#{scope}.#{message}", :resource_name => scope,
|
||||
:scope => [:devise, :sessions], :default => [message, message.to_s])
|
||||
:scope => "devise.failure", :default => [message, message.to_s])
|
||||
else
|
||||
message.to_s
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ require 'active_support/core_ext/object/with_options'
|
|||
Devise.with_options :model => true do |d|
|
||||
# Strategies first
|
||||
d.with_options :strategy => true do |s|
|
||||
s.add_module :database_authenticatable, :controller => :sessions, :flash => :invalid, :route => :session
|
||||
s.add_module :token_authenticatable, :controller => :sessions, :flash => :invalid_token, :route => :session
|
||||
s.add_module :database_authenticatable, :controller => :sessions, :route => :session
|
||||
s.add_module :token_authenticatable, :controller => :sessions, :route => :session
|
||||
s.add_module :rememberable
|
||||
end
|
||||
|
||||
|
@ -14,10 +14,10 @@ Devise.with_options :model => true do |d|
|
|||
d.add_module :validatable
|
||||
|
||||
# The ones which can sign out after
|
||||
d.add_module :activatable, :flash => :inactive
|
||||
d.add_module :confirmable, :controller => :confirmations, :flash => :unconfirmed, :route => :confirmation
|
||||
d.add_module :lockable, :controller => :unlocks, :flash => :locked, :route => :unlock
|
||||
d.add_module :timeoutable, :flash => :timeout
|
||||
d.add_module :activatable
|
||||
d.add_module :confirmable, :controller => :confirmations, :route => :confirmation
|
||||
d.add_module :lockable, :controller => :unlocks, :route => :unlock
|
||||
d.add_module :timeoutable
|
||||
|
||||
# Stats for last, so we make sure the user is really signed in
|
||||
d.add_module :trackable
|
||||
|
|
|
@ -16,5 +16,20 @@ module Devise
|
|||
initializer "devise.add_url_helpers" do |app|
|
||||
Devise::FailureApp.send :include, app.routes.url_helpers
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
I18n.available_locales
|
||||
flash = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
|
||||
|
||||
I18n.backend.send(:translations).each do |locale, translations|
|
||||
keys = flash & (translations[:devise][:sessions].keys) rescue []
|
||||
|
||||
if keys.any?
|
||||
ActiveSupport::Deprecation.warn "The following I18n messages in 'devise.sessions' " <<
|
||||
"for locale '#{locale}' are deprecated: #{keys.to_sentence}. Please move them to " <<
|
||||
"'devise.failure' instead."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -88,7 +88,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => {
|
||||
:sessions => { :user => { :unconfirmed => "Not confirmed user" } }
|
||||
:failure => { :user => { :unconfirmed => "Not confirmed user" } }
|
||||
} do
|
||||
sign_in_as_user(:confirm => false)
|
||||
assert_contain 'Not confirmed user'
|
||||
|
|
|
@ -134,7 +134,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => { :sessions => { :admin => { :invalid => "Invalid credentials" } } } do
|
||||
store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do
|
||||
sign_in_as_admin do
|
||||
fill_in 'password', :with => 'abcdef'
|
||||
end
|
||||
|
|
|
@ -93,7 +93,7 @@ class LockTest < ActionController::IntegrationTest
|
|||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => {
|
||||
:sessions => { :user => { :locked => "You are locked!" } }
|
||||
:failure => { :user => { :locked => "You are locked!" } }
|
||||
} do
|
||||
user = sign_in_as_user(:locked => true)
|
||||
assert_contain 'You are locked!'
|
||||
|
|
|
@ -54,7 +54,7 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|||
|
||||
test 'error message with i18n' do
|
||||
store_translations :en, :devise => {
|
||||
:sessions => { :user => { :timeout => 'Session expired!' } }
|
||||
:failure => { :user => { :timeout => 'Session expired!' } }
|
||||
} do
|
||||
user = sign_in_as_user
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
test 'does not authenticate with improper authentication token value' do
|
||||
store_translations :en, :devise => {:sessions => {:invalid_token => 'LOL, that was not a single character correct.'}} do
|
||||
store_translations :en, :devise => {:failure => {:invalid_token => 'LOL, that was not a single character correct.'}} do
|
||||
sign_in_as_new_user_with_token(:auth_token => '*** INVALID TOKEN ***')
|
||||
assert_equal new_user_session_path, @request.path
|
||||
|
||||
|
|
Loading…
Reference in a new issue