Add welcome mail
This commit is contained in:
parent
75129b52c6
commit
057f3ec8ea
9 changed files with 92 additions and 1 deletions
|
@ -41,6 +41,17 @@ class Mailer < ActionMailer::Base
|
||||||
subject: I18n.t('mailer.upcoming_tasks.subject')
|
subject: I18n.t('mailer.upcoming_tasks.subject')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Sends a welcome email with instructions on how to reset the password.
|
||||||
|
# Assumes user.setResetPasswordToken has been successfully called already.
|
||||||
|
def welcome(user)
|
||||||
|
@user = user
|
||||||
|
@additional_text = additonal_welcome_text(user)
|
||||||
|
@link = new_password_url(id: @user.id, token: @user.reset_password_token)
|
||||||
|
|
||||||
|
mail to: user,
|
||||||
|
subject: I18n.t('mailer.welcome.subject')
|
||||||
|
end
|
||||||
|
|
||||||
# Sends order result for specific Ordergroup
|
# Sends order result for specific Ordergroup
|
||||||
def order_result(user, group_order)
|
def order_result(user, group_order)
|
||||||
@order = group_order.order
|
@order = group_order.order
|
||||||
|
@ -145,6 +156,10 @@ class Mailer < ActionMailer::Base
|
||||||
attachments['order.csv'] = OrderCsv.new(order, options).to_csv
|
attachments['order.csv'] = OrderCsv.new(order, options).to_csv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# separate method to allow plugins to mess with the text
|
||||||
|
def additonal_welcome_text(user)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def format_address(email, name)
|
def format_address(email, name)
|
||||||
|
|
|
@ -20,7 +20,7 @@ class User < ApplicationRecord
|
||||||
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
|
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
|
||||||
has_many :mail_delivery_status, :class_name => 'MailDeliveryStatus', :foreign_key => 'email', :primary_key => 'email'
|
has_many :mail_delivery_status, :class_name => 'MailDeliveryStatus', :foreign_key => 'email', :primary_key => 'email'
|
||||||
|
|
||||||
attr_accessor :create_ordergroup, :password, :settings_attributes
|
attr_accessor :create_ordergroup, :password, :send_welcome_mail, :settings_attributes
|
||||||
|
|
||||||
scope :deleted, -> { where.not(deleted_at: nil) }
|
scope :deleted, -> { where.not(deleted_at: nil) }
|
||||||
scope :undeleted, -> { where(deleted_at: nil) }
|
scope :undeleted, -> { where(deleted_at: nil) }
|
||||||
|
@ -52,6 +52,13 @@ class User < ApplicationRecord
|
||||||
settings.defaults['notify'] = { 'upcoming_tasks' => true } unless settings.notify
|
settings.defaults['notify'] = { 'upcoming_tasks' => true } unless settings.notify
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_save do
|
||||||
|
if send_welcome_mail?
|
||||||
|
self.reset_password_token = new_random_password(16)
|
||||||
|
self.reset_password_expires = Time.now.advance(days: 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
after_save do
|
after_save do
|
||||||
settings_attributes.each do |key, value|
|
settings_attributes.each do |key, value|
|
||||||
value.each do |k, v|
|
value.each do |k, v|
|
||||||
|
@ -70,6 +77,12 @@ class User < ApplicationRecord
|
||||||
og.memberships.build({user: self})
|
og.memberships.build({user: self})
|
||||||
og.save!
|
og.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Mailer.welcome(self).deliver_now if send_welcome_mail?
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_welcome_mail?
|
||||||
|
ActiveRecord::Type::Boolean.new.type_cast_from_user(send_welcome_mail)
|
||||||
end
|
end
|
||||||
|
|
||||||
# sorted by display name
|
# sorted by display name
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
= simple_form_for([:admin, @user]) do |f|
|
= simple_form_for([:admin, @user]) do |f|
|
||||||
= render 'shared/user_form_fields', f: f, password_autocomplete: false
|
= render 'shared/user_form_fields', f: f, password_autocomplete: false
|
||||||
|
= f.input :send_welcome_mail, as: :boolean, label: false, inline_label: t('.send_welcome_mail')
|
||||||
- unless @user.ordergroup
|
- unless @user.ordergroup
|
||||||
= f.input :create_ordergroup, as: :boolean, label: false, inline_label: t('.create_ordergroup')
|
= f.input :create_ordergroup, as: :boolean, label: false, inline_label: t('.create_ordergroup')
|
||||||
.form-actions
|
.form-actions
|
||||||
|
|
6
app/views/mailer/welcome.text.haml
Normal file
6
app/views/mailer/welcome.text.haml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
= raw t '.text0', user: show_user(@user)
|
||||||
|
- if @additional_text
|
||||||
|
\
|
||||||
|
= raw @additional_text
|
||||||
|
\
|
||||||
|
= raw t '.text1', link: @link, expires: I18n.l(@user.reset_password_expires), foodcoop: FoodsoftConfig[:name]
|
|
@ -341,6 +341,7 @@ de:
|
||||||
title: Benutzer/in bearbeiten
|
title: Benutzer/in bearbeiten
|
||||||
form:
|
form:
|
||||||
create_ordergroup: Bestellgruppe mit dem selben Namen erstellen und Benutzer_in hinzufügen.
|
create_ordergroup: Bestellgruppe mit dem selben Namen erstellen und Benutzer_in hinzufügen.
|
||||||
|
send_welcome_mail: Eine Willkommen-Nachricht an Benutzer_in senden.
|
||||||
index:
|
index:
|
||||||
first_paragraph: Hier kannst du Benutzer/innen %{url}, bearbeiten und natürlich auch löschen.
|
first_paragraph: Hier kannst du Benutzer/innen %{url}, bearbeiten und natürlich auch löschen.
|
||||||
new_user: Neue/n Benutzer/in anlegen
|
new_user: Neue/n Benutzer/in anlegen
|
||||||
|
@ -1264,6 +1265,19 @@ de:
|
||||||
Deine Aufgaben: %{user_tasks_url}
|
Deine Aufgaben: %{user_tasks_url}
|
||||||
|
|
||||||
|
|
||||||
|
Viele Grüße von %{foodcoop}
|
||||||
|
welcome:
|
||||||
|
subject: Willkommen in der Foodcoop
|
||||||
|
text0: |
|
||||||
|
Liebe(r) %{user},
|
||||||
|
|
||||||
|
für dich wure ein neuer Foodsoft-Zugang erstellt.
|
||||||
|
text1: |
|
||||||
|
Um ein neues Passwort einzugeben, gehe zu: %{link}
|
||||||
|
Dieser Link kann nur einmal aufgerufen werden und läuft am %{expires} ab.
|
||||||
|
Du kannst jederzeit "Passwort vergessen?" benutzen, um einen neuen Link zu erhalten.
|
||||||
|
|
||||||
|
|
||||||
Viele Grüße von %{foodcoop}
|
Viele Grüße von %{foodcoop}
|
||||||
messages_mailer:
|
messages_mailer:
|
||||||
foodsoft_message:
|
foodsoft_message:
|
||||||
|
|
|
@ -357,6 +357,7 @@ en:
|
||||||
title: Edit user
|
title: Edit user
|
||||||
form:
|
form:
|
||||||
create_ordergroup: Create ordergroup with the same name and add user.
|
create_ordergroup: Create ordergroup with the same name and add user.
|
||||||
|
send_welcome_mail: Send a welcome mail to the user.
|
||||||
index:
|
index:
|
||||||
first_paragraph: Here you can %{url}, edit and delete users.
|
first_paragraph: Here you can %{url}, edit and delete users.
|
||||||
new_user: Create new user
|
new_user: Create new user
|
||||||
|
@ -1303,6 +1304,19 @@ en:
|
||||||
My tasks: %{user_tasks_url}
|
My tasks: %{user_tasks_url}
|
||||||
|
|
||||||
|
|
||||||
|
Kind regards from %{foodcoop}.
|
||||||
|
welcome:
|
||||||
|
subject: Welcome to the Foodcoop
|
||||||
|
text0: |
|
||||||
|
Dear %{user},
|
||||||
|
|
||||||
|
a new Foodsoft account has been created for you.
|
||||||
|
text1: |
|
||||||
|
In order to choose a new password follow this link: %{link}
|
||||||
|
This link works only once and expires on %{expires}.
|
||||||
|
You can always use "Forgot password?" to get an new link.
|
||||||
|
|
||||||
|
|
||||||
Kind regards from %{foodcoop}.
|
Kind regards from %{foodcoop}.
|
||||||
messages_mailer:
|
messages_mailer:
|
||||||
foodsoft_message:
|
foodsoft_message:
|
||||||
|
|
|
@ -36,6 +36,10 @@ class Page < ApplicationRecord
|
||||||
where(permalink: "Public_frontpage").first
|
where(permalink: "Public_frontpage").first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.welcome_mail
|
||||||
|
where(permalink: "Welcome_mail").first
|
||||||
|
end
|
||||||
|
|
||||||
def set_permalink
|
def set_permalink
|
||||||
unless title.blank?
|
unless title.blank?
|
||||||
self.permalink = Page.count == 0 ? "Home" : Page.permalink(title)
|
self.permalink = Page.count == 0 ? "Home" : Page.permalink(title)
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'acts_as_versioned'
|
||||||
require 'diffy'
|
require 'diffy'
|
||||||
require 'content_for_in_controllers'
|
require 'content_for_in_controllers'
|
||||||
require 'foodsoft_wiki/engine'
|
require 'foodsoft_wiki/engine'
|
||||||
|
require 'foodsoft_wiki/mailer'
|
||||||
require 'foodsoft_wiki/wiki_parser'
|
require 'foodsoft_wiki/wiki_parser'
|
||||||
|
|
||||||
module FoodsoftWiki
|
module FoodsoftWiki
|
||||||
|
|
23
plugins/wiki/lib/foodsoft_wiki/mailer.rb
Normal file
23
plugins/wiki/lib/foodsoft_wiki/mailer.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
module FoodsoftWiki
|
||||||
|
|
||||||
|
module Mailer
|
||||||
|
def self.included(base) # :nodoc:
|
||||||
|
base.class_eval do
|
||||||
|
|
||||||
|
# modify user presentation link to writing a message for the user
|
||||||
|
def additonal_welcome_text(user)
|
||||||
|
if FoodsoftWiki.enabled? && (page = Page.welcome_mail)
|
||||||
|
page.body
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# modify existing helper
|
||||||
|
ActiveSupport.on_load(:after_initialize) do
|
||||||
|
Mailer.send :include, FoodsoftWiki::Mailer
|
||||||
|
end
|
Loading…
Reference in a new issue