Skip to content

Commit

Permalink
Use emails only when spree_emails is available (#556)
Browse files Browse the repository at this point in the history
* Use emails only when spree_emails is available

* fix
  • Loading branch information
damianlegawiec authored Dec 29, 2021
1 parent 27a451a commit 7fe5424
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 25 deletions.
23 changes: 0 additions & 23 deletions app/mailers/spree/user_mailer.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
config.mailer_sender = '[email protected]'

# 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
Expand Down
25 changes: 25 additions & 0 deletions lib/mailers/spree/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions lib/spree/auth/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spree_auth_devise.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit 7fe5424

Please sign in to comment.