-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
simon lehericey
committed
Oct 9, 2018
1 parent
cbb59f1
commit e5a1e8c
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace :'2018_10_03_fix_mailjet_mistakes' do | ||
task activation_emails: :environment do | ||
activation_file_path = ENV['ACTIVATION'] | ||
|
||
if File.file?(activation_file_path) | ||
rake_puts "loading #{activation_file_path} file for account activation" | ||
else | ||
rake_puts "no file #{activation_file_path} found" | ||
end | ||
|
||
emails = File.new(activation_file_path).readlines.map(&:strip) | ||
|
||
emails.each do |email| | ||
user = User.find_by(email: email) | ||
if user.present? | ||
rake_puts "sending activation mail for #{email}" | ||
if user.confirmed? | ||
UserMailer.new_account_warning(user).deliver_later | ||
else | ||
user.resend_confirmation_instructions | ||
end | ||
else | ||
rake_puts "user #{email} does not exist" | ||
end | ||
end | ||
end | ||
|
||
task password_emails: :environment do | ||
password_file_path = ENV['PASSWORD'] | ||
|
||
if File.file?(password_file_path) | ||
rake_puts "loading #{password_file_path} file for changing password" | ||
else | ||
rake_puts "no file #{password_file_path} found" | ||
end | ||
|
||
emails = File.new(password_file_path).readlines.map(&:strip) | ||
|
||
emails.each do |email| | ||
user = User.find_by(email: email) | ||
if user.present? | ||
rake_puts "sending changing password mail for #{email}" | ||
user.send_reset_password_instructions | ||
else | ||
rake_puts "user #{email} does not exist" | ||
end | ||
end | ||
end | ||
|
||
task notification_emails: :environment do | ||
notification_file_path = ENV['NOTIFICATION'] | ||
|
||
if File.file?(notification_file_path) | ||
rake_puts "loading #{notification_file_path} file for notification" | ||
else | ||
rake_puts "no file #{notification_file_path} found" | ||
end | ||
|
||
lines = File.new(notification_file_path).readlines.map(&:strip) | ||
|
||
lines.each do |line| | ||
email, *subject = line.split(',') | ||
subject = *subject.join | ||
|
||
user = User.find_by(email: email) | ||
|
||
body = <<-EOS | ||
Bonjour, | ||
Suite à un incident technique concernant les envois d'emails sur le site demarches-simplifiees.fr, nous n'avons pas pu vous remettre l'email intitulé #{subject}. | ||
Vous pouvez néanmoins le consulter directement dans la messagerie de votre dossier en vous connectant sur https://www.demarches-simplifiees.fr/users/sign_in . | ||
Veuillez nous excuser pour la gêne occasionnée. | ||
Cordialement, | ||
L'équipe de demarches-simplifiees.fr | ||
EOS | ||
|
||
if user.present? | ||
rake_puts "sending notification for #{email}" | ||
ActionMailer::Base.mail( | ||
from: "contact@demarches-simplifiees.fr", | ||
to: email, | ||
subject: subject, | ||
body: body | ||
).deliver_later | ||
else | ||
rake_puts "user #{email} does not exist" | ||
end | ||
end | ||
end | ||
end |