mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-08 22:37:57 -05:00
Pass locale with activatable / timeoutable hooks (#5815)
We need to explicitly pass the `locale` around from the options (passed to `warden.authenticate!` for instance) or the `I18n.locale` when logging out and redirecting the user via `throw :warden`, otherwise in a multi-locale app we'd lose the locale previously set / passed around and fallback to the default for that flash message. This is a follow-up of the fixes in #5567 where we implemented the locale passing logic down to the failure app, but it missed these places where we were using `throw :warden`. Closes #5812
This commit is contained in:
committed by
GitHub
parent
cd9c21a067
commit
051f94a498
@@ -136,6 +136,15 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
test 'not confirmed user redirect respects i18n locale set' do
|
||||
swap Devise, allow_unconfirmed_access_for: 0.days do
|
||||
sign_in_as_user(confirm: false, visit: new_user_session_path(locale: "pt-BR"))
|
||||
|
||||
assert_contain 'Você precisa confirmar seu email para continuar'
|
||||
assert_not warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
|
||||
swap Devise, allow_unconfirmed_access_for: 0.days do
|
||||
sign_in_as_user(confirm: false) do
|
||||
|
||||
@@ -167,6 +167,17 @@ class SessionTimeoutTest < Devise::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
test 'error message redirect respects i18n locale set' do
|
||||
user = sign_in_as_user
|
||||
|
||||
get expire_user_path(user)
|
||||
get root_path(locale: "pt-BR")
|
||||
follow_redirect!
|
||||
|
||||
assert_contain 'Sua sessão expirou. Por favor faça o login novamente para continuar.'
|
||||
assert_not warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'time out not triggered if remembered' do
|
||||
user = sign_in_as_user remember_me: true
|
||||
get expire_user_path(user)
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AdminsController < ApplicationController
|
||||
around_action :set_locale
|
||||
before_action :authenticate_admin!
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_locale
|
||||
I18n.with_locale(params[:locale] || I18n.default_locale) { yield }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,9 +5,20 @@
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
around_action :set_locale
|
||||
before_action :current_user, unless: :devise_controller?
|
||||
before_action :authenticate_user!, if: :devise_controller?
|
||||
respond_to(*Mime::SET.map(&:to_sym))
|
||||
|
||||
devise_group :commenter, contains: [:user, :admin]
|
||||
|
||||
private
|
||||
|
||||
def set_locale
|
||||
I18n.with_locale(params[:locale] || I18n.default_locale) { yield }
|
||||
end
|
||||
|
||||
def default_url_options
|
||||
{locale: params[:locale]}.compact
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,3 +3,5 @@ pt-BR:
|
||||
failure:
|
||||
invalid: "%{authentication_keys} ou senha inválidos."
|
||||
unauthenticated: "Para continuar, faça login ou registre-se."
|
||||
timeout: "Sua sessão expirou. Por favor faça o login novamente para continuar."
|
||||
unconfirmed: "Você precisa confirmar seu email para continuar."
|
||||
|
||||
Reference in New Issue
Block a user