Permalink
Browse files

Move failure messages from devise.sessions to devise.failure.

  • Loading branch information...
1 parent 23e608e commit b974b7bc78e990bb16beba932eb3918a9d99452c @josevalim josevalim committed Apr 3, 2010
View
@@ -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
View
@@ -6,16 +6,17 @@ 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.'
invalid: 'Invalid email or password.'
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.'
View
@@ -29,11 +29,10 @@ module Strategies
# 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 @@ def self.register(resource, options)
#
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 @@ def i18n_message(default = nil)
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
View
@@ -3,8 +3,8 @@
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 @@
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
View
@@ -16,5 +16,20 @@ class Engine < ::Rails::Engine
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 @@ def visit_user_confirmation_with_token(confirmation_token)
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 @@ def visit_user_unlock_with_token(unlock_token)
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 @@ def last_request_at
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

0 comments on commit b974b7b

Please sign in to comment.