diff --git a/app/mailers/spree/user_mailer.rb b/app/mailers/spree/user_mailer.rb index 41f088ed4..33a7d7826 100644 --- a/app/mailers/spree/user_mailer.rb +++ b/app/mailers/spree/user_mailer.rb @@ -1,16 +1,22 @@ module Spree class UserMailer < BaseMailer def reset_password_instructions(user, token, *_args) - @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: Spree::Store.current.url) + @current_store = user&.current_store || Spree::Store.current + @locale = user&.current_store&.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) - mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]) + mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]) end def confirmation_instructions(user, token, _opts = {}) - @confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: Spree::Store.current.url) + @current_store = user&.current_store || Spree::Store.current + @locale = user&.current_store&.default_locale + I18n.locale = @locale if @locale.present? + @confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: @current_store.url) @email = user.email - mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions]) + mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions]) end end end diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index c2e3f87bb..b2ed4d0aa 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -19,6 +19,8 @@ class User < Spree::Base scope :admin, -> { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") } + belongs_to :current_store, foreign_key: :store_id, class_name: 'Spree::Store', optional: true + def self.admin_created? User.admin.exists? end diff --git a/app/views/spree/user_mailer/confirmation_instructions.text.erb b/app/views/spree/user_mailer/confirmation_instructions.text.erb index b788ac622..57c2d51ba 100644 --- a/app/views/spree/user_mailer/confirmation_instructions.text.erb +++ b/app/views/spree/user_mailer/confirmation_instructions.text.erb @@ -1,5 +1,5 @@ -Welcome <%= @email %>! +<%= Spree.t('confirmation_instructions.welcome', email: @email) %> -You can confirm your account email through the url below: +<%= Spree.t('confirmation_instructions.confirm') %> -<%= @confirmation_url %> \ No newline at end of file +<%= @confirmation_url %> diff --git a/app/views/spree/user_mailer/reset_password_instructions.text.erb b/app/views/spree/user_mailer/reset_password_instructions.text.erb index 148526cec..51345d08a 100644 --- a/app/views/spree/user_mailer/reset_password_instructions.text.erb +++ b/app/views/spree/user_mailer/reset_password_instructions.text.erb @@ -1,10 +1,5 @@ -A request to reset your password has been made. -If you did not make this request, simply ignore this email. - -If you did make this request just click the link below: +<%= Spree.t('user_mailer.reset_password_instructions.instructions_1') %> <%= @edit_password_reset_url %> -If the above URL does not work try copying and pasting it into your browser. -If you continue to have problems please feel free to contact us. - +<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 8e14add50..2c5a645d1 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -5,6 +5,13 @@ de: change_your_password: Kennwort zurücksetzen store_credits: credit_balance: Saldo des Guthabens + user_mailer: + reset_password_instructions: + instructions_1: "Es wurde eine Anfrage zum Zurücksetzen Ihres Passworts gestellt.\nWenn Sie diese Anfrage nicht gestellt haben, ignorieren Sie diese E-Mail.\n\nWenn Sie diese Anfrage gestellt haben, klicken Sie bitte auf den folgenden Link:" + instructions_2: "Falls die obige URL nicht funktioniert, bitte URL kopieren und in Ihren Browser einfügen\nWenn Sie weiterhin Probleme haben, können Sie sich gerne an uns wenden." + confirmation_instructions: + welcome: "Schön, dass Sie hier sind %{email}" + confirm: "Sie können Ihre Konto-E-Mail-Adresse über die folgende URL bestätigen:" devise: confirmations: confirmed: Ihr Konto wurde erfolgreich aktiviert. diff --git a/config/locales/en.yml b/config/locales/en.yml index 9982a089c..78c91041c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,13 @@ en: change_your_password: "Change your password" store_credits: credit_balance: Store Credit Balance + user_mailer: + reset_password_instructions: + instructions_1: "A request to reset your password has been made.\nIf you did not make this request, simply ignore this email.\n\nIf you did make this request just click the link below:" + instructions_2: "If the above URL does not work try copying and pasting it into your browser.\nIf you continue to have problems please feel free to contact us." + confirmation_instructions: + welcome: "Welcome %{email}!" + confirm: "You can confirm your account email through the url below:" devise: confirmations: confirmed: Your account was successfully confirmed. You are now signed in. diff --git a/db/migrate/20200702073908_add_store_to_user.rb b/db/migrate/20200702073908_add_store_to_user.rb new file mode 100644 index 000000000..7ed22a7b8 --- /dev/null +++ b/db/migrate/20200702073908_add_store_to_user.rb @@ -0,0 +1,7 @@ +class AddStoreToUser < ActiveRecord::Migration[6.0] + def change + unless column_exists?(:spree_users, :store_id) + add_column :spree_users, :store_id, :integer + end + end +end diff --git a/lib/spree/core/controller_helpers/store_decorator.rb b/lib/spree/core/controller_helpers/store_decorator.rb new file mode 100644 index 000000000..1b2c8488b --- /dev/null +++ b/lib/spree/core/controller_helpers/store_decorator.rb @@ -0,0 +1,22 @@ +module Spree + module Core + module ControllerHelpers + module StoreDecorator + def self.prepended(base) + base.included do + before_action :set_user_current_store + end + end + + def set_user_current_store + return if try_spree_current_user.nil? + + try_spree_current_user.current_store = current_store + try_spree_current_user.save + end + end + end + end +end + +Spree::Core::ControllerHelpers::Store.prepend Spree::Core::ControllerHelpers::StoreDecorator