From f8bf789cf824071c9b04725ed9a7f44831511894 Mon Sep 17 00:00:00 2001 From: rusikf Date: Thu, 17 Mar 2016 18:29:40 +0200 Subject: [PATCH] fix devise error --- config/initializers/devise.rb | 6 ++++++ config/routes.rb | 2 +- lib/devise/custom_failure.rb | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 lib/devise/custom_failure.rb diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 7d3695225..a323bbaf7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,5 +1,7 @@ # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. + +require 'devise/custom_failure' Devise.setup do |config| @@ -257,6 +259,10 @@ # If you want to use other strategies, that are not supported by Devise, or # change the failure app, you can configure them inside the config.warden block. # + config.warden do |manager| + manager.failure_app = CustomFailure + end + # config.warden do |manager| # manager.intercept_401 = false # manager.default_strategies(scope: :user).unshift :some_external_strategy diff --git a/config/routes.rb b/config/routes.rb index 697398b75..c02fb7639 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ root to: "locales#redirect_on_locale" - devise_for :users, skip: [:session, :password, :registration, :confirmation], controllers: { omniauth_callbacks: 'omniauth_callbacks' } + devise_for :users, skip: [:password, :registration, :confirmation], controllers: { omniauth_callbacks: 'omniauth_callbacks' } localized do diff --git a/lib/devise/custom_failure.rb b/lib/devise/custom_failure.rb new file mode 100644 index 000000000..60ba64f76 --- /dev/null +++ b/lib/devise/custom_failure.rb @@ -0,0 +1,14 @@ +class CustomFailure < Devise::FailureApp + def redirect_url + I18n.locale = params[:locale] + new_user_session_path + end + + def respond + if http_auth? + http_auth + else + redirect + end + end +end