lib/devise/multi_email/models/confirmable.rb in devise-multi_email-1.0.5 vs lib/devise/multi_email/models/confirmable.rb in devise-multi_email-2.0.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'devise/multi_email/parent_model_extensions'
+
module Devise
module Models
module EmailConfirmable
extend ActiveSupport::Concern
@@ -9,31 +11,38 @@
extend ClassReplacementMethods
end
module ClassReplacementMethods
def allow_unconfirmed_access_for
- 0.day
+ 0.days
end
end
end
module MultiEmailConfirmable
extend ActiveSupport::Concern
included do
+ include Devise::MultiEmail::ParentModelExtensions
+
devise :confirmable
- include InstanceReplacementMethods
- extend ClassReplacementMethods
- email_class.send :include, EmailConfirmable
+ include ConfirmableExtensions
end
def self.required_fields(klass)
[]
end
- module InstanceReplacementMethods
+ module ConfirmableExtensions
+ extend ActiveSupport::Concern
+
+ included do
+ multi_email_association.include_module(EmailConfirmable)
+ end
+
+ # delegate before creating overriding methods
delegate :skip_confirmation!, :skip_confirmation_notification!, :skip_reconfirmation!, :confirmation_required?,
:confirmation_token, :confirmed_at, :confirmation_sent_at, :confirm, :confirmed?, :unconfirmed_email,
:reconfirmation_required?, :pending_reconfirmation?, to: :primary_email_record, allow_nil: true
# This need to be forwarded to the email that the user logged in with
@@ -56,11 +65,11 @@
else
super
end
end
- protected
+ protected
# Overrides Devise::Models::Confirmable#postpone_email_change?
def postpone_email_change?
false
end
@@ -75,30 +84,20 @@
# Email will send confirmation instructions.
def send_on_create_confirmation_instructions
end
- private
+ private
def current_login_email_record
if respond_to?(:current_login_email) && current_login_email
- send(self.class::EMAILS_ASSOCIATION).find_by(email: current_login_email)
+ multi_email.emails.find_by(email: current_login_email)
end
end
- end
- module ClassReplacementMethods
- # Overrides Devise::Models::Confirmable.confirm_by_token
- # Forward the logic to email.
- def confirm_by_token(token)
- email_class.confirm_by_token(token)
+ module ClassMethods
+ delegate :confirm_by_token, :send_confirmation_instructions, to: 'multi_email_association.model_class', allow_nil: false
end
-
- # Overrides Devise::Models::Confirmable.send_confirmation_instructions
- # Forward the logic to email.
- def send_confirmation_instructions(params)
- email_class.send_confirmation_instructions(params)
- end
end
end
end
-end
\ No newline at end of file
+end