mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-12 08:17:59 -05:00
Compare commits
12 Commits
5-rc
...
mf-issue-5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f78eed69e9 | ||
|
|
885c61ece3 | ||
|
|
940b939791 | ||
|
|
406915cb78 | ||
|
|
c5de662454 | ||
|
|
0a6cd99d03 | ||
|
|
ffeb942699 | ||
|
|
f148c90fc7 | ||
|
|
d022fb8cc4 | ||
|
|
421ffc479f | ||
|
|
0f134f7030 | ||
|
|
5d73e1e3bb |
@@ -289,7 +289,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
|
||||
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
||||
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
|
||||
|
||||
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before filter in your `ApplicationController`:
|
||||
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
|
||||
|
||||
```ruby
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
@@ -112,7 +112,7 @@ MESSAGE
|
||||
end
|
||||
|
||||
if authenticated && resource = warden.user(resource_name)
|
||||
flash[:alert] = I18n.t("devise.failure.already_authenticated")
|
||||
set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')
|
||||
redirect_to after_sign_in_path_for(resource)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -305,6 +305,10 @@ module Devise
|
||||
defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
|
||||
end
|
||||
|
||||
def self.rails6_and_up?
|
||||
Rails.gem_version >= Gem::Version.new("6.0.x")
|
||||
end
|
||||
|
||||
# Default way to set up Devise. Run rails generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
|
||||
@@ -152,7 +152,8 @@ module Devise
|
||||
# # If the record is new or changed then delay the
|
||||
# # delivery until the after_commit callback otherwise
|
||||
# # send now because after_commit will not be called.
|
||||
# if new_record? || changed?
|
||||
# # For Rails < 6 is `changed?` instead of `saved_changes?`.
|
||||
# if new_record? || saved_changes?
|
||||
# pending_devise_notifications << [notification, args]
|
||||
# else
|
||||
# render_and_send_devise_message(notification, *args)
|
||||
|
||||
@@ -43,5 +43,11 @@ module Devise
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
initializer "devise.zeitwerk" do
|
||||
if Devise.rails6_and_up? && Rails.autoloaders.zeitwerk_enabled? && !Object.const_defined?(Devise.parent_mailer)
|
||||
Rails.autoloaders.main.ignore("#{__dir__}/app/mailers/devise/mailer.rb")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Assuming you have not yet modified this file, each configuration option below
|
||||
# is set to its default value. Note that some are commented out while others
|
||||
# are not: uncommented lines are intended to protect your configuration from
|
||||
# breaking changes in upgrades (i.e., in the event that future versions of
|
||||
# Devise change the default values for those options).
|
||||
#
|
||||
# Use this hook to configure devise mailer, warden hooks and so forth.
|
||||
# Many of these configuration options can be set straight in your model.
|
||||
Devise.setup do |config|
|
||||
|
||||
@@ -323,6 +323,14 @@ class AuthenticationRedirectTest < Devise::IntegrationTest
|
||||
visit new_user_session_path
|
||||
assert_equal flash[:alert], I18n.t("devise.failure.already_authenticated")
|
||||
end
|
||||
|
||||
test 'require_no_authentication should set the already_authenticated flash message as admin' do
|
||||
store_translations :en, devise: { failure: { admin: { already_authenticated: 'You are already signed in as admin.' } } } do
|
||||
sign_in_as_admin
|
||||
visit new_admin_session_path
|
||||
assert_equal flash[:alert], "You are already signed in as admin."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class AuthenticationSessionTest < Devise::IntegrationTest
|
||||
|
||||
@@ -44,7 +44,7 @@ class TrackableHooksTest < Devise::IntegrationTest
|
||||
assert_equal "127.0.0.1", user.last_sign_in_ip
|
||||
end
|
||||
|
||||
test "current remote ip returns original ip behind a non transparent proxy" do
|
||||
test "current and last sign in remote ip returns original ip behind a non transparent proxy" do
|
||||
user = create_user
|
||||
|
||||
arbitrary_ip = '200.121.1.69'
|
||||
@@ -53,6 +53,7 @@ class TrackableHooksTest < Devise::IntegrationTest
|
||||
end
|
||||
user.reload
|
||||
assert_equal arbitrary_ip, user.current_sign_in_ip
|
||||
assert_equal arbitrary_ip, user.last_sign_in_ip
|
||||
end
|
||||
|
||||
test "increase sign in count" do
|
||||
|
||||
@@ -49,5 +49,9 @@ module RailsApp
|
||||
if Devise::Test.rails52_and_up? && !Devise::Test.rails6?
|
||||
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
|
||||
end
|
||||
|
||||
if Devise.rails6_and_up?
|
||||
config.autoloader = :zeitwerk
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
require "omniauth-facebook"
|
||||
require "omniauth-openid"
|
||||
|
||||
# Assuming you have not yet modified this file, each configuration option below
|
||||
# is set to its default value. Note that some are commented out while others
|
||||
# are not: uncommented lines are intended to protect your configuration from
|
||||
# breaking changes in upgrades (i.e., in the event that future versions of
|
||||
# Devise change the default values for those options).
|
||||
#
|
||||
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
||||
# four configuration values can also be set straight in your models.
|
||||
Devise.setup do |config|
|
||||
|
||||
@@ -8,4 +8,24 @@ class RailsTest < ActiveSupport::TestCase
|
||||
assert_equal :load_config_initializers, initializer.after
|
||||
assert_equal :build_middleware_stack, initializer.before
|
||||
end
|
||||
|
||||
test 'ignore devise mailer loading when ActionMailer is not defined with zeitwerk' do
|
||||
if Devise.rails6_and_up?
|
||||
begin
|
||||
swap Devise, parent_mailer: 'NotDefinedParentMailer' do
|
||||
Devise::Engine.initializers.detect { |initializer| initializer.name == 'devise.zeitwerk' }.block.call
|
||||
assert Rails.autoloaders.main.ignored_glob_patterns.any? { |pattern| pattern.include?("mailer.rb") }
|
||||
end
|
||||
ensure
|
||||
Rails.autoloaders.main.instance_variable_set(:@ignored_glob_patterns, Set.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test 'load devise mailer file when Devise.parent_mailer is defined with zeitwerk' do
|
||||
if Devise.rails6_and_up?
|
||||
Devise::Engine.initializers.detect { |initializer| initializer.name == 'devise.zeitwerk' }.block.call
|
||||
refute Rails.autoloaders.main.ignored_glob_patterns.any? { |pattern| pattern.include?("mailer.rb") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user