diff --git a/app/mailers/spree/user_mailer.rb b/app/mailers/spree/user_mailer.rb deleted file mode 100644 index 0413acbc5..000000000 --- a/app/mailers/spree/user_mailer.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Spree - class UserMailer < defined?(Spree::BaseMailer) ? Spree::BaseMailer : ActionMailer::Base - def reset_password_instructions(user, token, *_args) - current_store_id = _args.inject(:merge)[:current_store_id] - @current_store = Spree::Store.find(current_store_id) || Spree::Store.current - @locale = @current_store.has_attribute?(:default_locale) ? @current_store.default_locale : I18n.default_locale - I18n.locale = @locale if @locale.present? - @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @current_store.url) - @user = user - - mail to: user.email, from: @current_store.mail_from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]), store_url: @current_store.url - end - - def confirmation_instructions(user, token, _opts = {}) - current_store_id = _opts[:current_store_id] - @current_store = Spree::Store.find(current_store_id) || Spree::Store.current - @confirmation_url = spree.confirmation_url(confirmation_token: token, host: Spree::Store.current.url) - @email = user.email - - mail to: user.email, from: @current_store.mail_from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions]), store_url: @current_store.url - end - end -end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index b940f737c..baaffe842 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -6,7 +6,7 @@ config.mailer_sender = 'please-change-me@config-initializers-devise.com' # Configure the class responsible to send e-mails. - config.mailer = 'Spree::UserMailer' + config.mailer = 'Spree::UserMailer' if defined?(Spree::Emails) # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and diff --git a/lib/mailers/spree/user_mailer.rb b/lib/mailers/spree/user_mailer.rb new file mode 100644 index 000000000..c8f6e9567 --- /dev/null +++ b/lib/mailers/spree/user_mailer.rb @@ -0,0 +1,25 @@ +module Spree + class UserMailer < BaseMailer + def reset_password_instructions(user, token, *args) + current_store_id = args.inject(:merge)[:current_store_id] + @current_store = Spree::Store.find_by(id: current_store_id) || Spree::Store.current + @locale = @current_store.has_attribute?(:default_locale) ? @current_store.default_locale : I18n.default_locale + I18n.locale = @locale if @locale.present? + @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @current_store.url) + @user = user + + mail to: user.email, from: from_address, reply_to: reply_to_address, + subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]), store_url: @current_store.url + end + + def confirmation_instructions(user, token, opts = {}) + current_store_id = opts[:current_store_id] + @current_store = Spree::Store.find_by(id: current_store_id) || Spree::Store.current + @confirmation_url = spree.confirmation_url(confirmation_token: token, host: @current_store.url) + @email = user.email + + mail to: user.email, from: from_address, reply_to: reply_to_address, + subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions]), store_url: @current_store.url + end + end +end diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index cf7dfa3e3..61b7665fc 100644 --- a/lib/spree/auth/engine.rb +++ b/lib/spree/auth/engine.rb @@ -64,6 +64,10 @@ def self.api_available? @@api_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Api::Engine') end + def self.emails_available? + @@emails_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Emails::Engine') + end + if backend_available? paths["app/controllers"] << "lib/controllers/backend" paths["app/views"] << "lib/views/backend" @@ -78,6 +82,11 @@ def self.api_available? paths["app/controllers"] << "lib/controllers/api" end + if emails_available? + paths["app/views"] << "lib/views/emails" + paths["app/mailers"] << "lib/mailers" + end + config.to_prepare &method(:activate).to_proc end end diff --git a/app/views/spree/user_mailer/confirmation_instructions.html.erb b/lib/views/emails/spree/user_mailer/confirmation_instructions.html.erb similarity index 100% rename from app/views/spree/user_mailer/confirmation_instructions.html.erb rename to lib/views/emails/spree/user_mailer/confirmation_instructions.html.erb diff --git a/app/views/spree/user_mailer/confirmation_instructions.text.erb b/lib/views/emails/spree/user_mailer/confirmation_instructions.text.erb similarity index 100% rename from app/views/spree/user_mailer/confirmation_instructions.text.erb rename to lib/views/emails/spree/user_mailer/confirmation_instructions.text.erb diff --git a/app/views/spree/user_mailer/reset_password_instructions.html.erb b/lib/views/emails/spree/user_mailer/reset_password_instructions.html.erb similarity index 100% rename from app/views/spree/user_mailer/reset_password_instructions.html.erb rename to lib/views/emails/spree/user_mailer/reset_password_instructions.html.erb diff --git a/app/views/spree/user_mailer/reset_password_instructions.text.erb b/lib/views/emails/spree/user_mailer/reset_password_instructions.text.erb similarity index 100% rename from app/views/spree/user_mailer/reset_password_instructions.text.erb rename to lib/views/emails/spree/user_mailer/reset_password_instructions.text.erb diff --git a/spree_auth_devise.gemspec b/spree_auth_devise.gemspec index e75337abc..2c7b6ace2 100644 --- a/spree_auth_devise.gemspec +++ b/spree_auth_devise.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_dependency 'devise', '~> 4.7' s.add_dependency 'devise-encryptable', '0.2.0' - spree_version = '>= 4.3.0.rc1' + spree_version = '>= 5.0.0.alpha' s.add_dependency 'spree_core', spree_version s.add_dependency 'spree_extension'