add APIToken expiration mailer
This commit is contained in:
parent
d909e2c8ea
commit
6353c10955
3 changed files with 58 additions and 0 deletions
18
app/mailers/api_token_mailer.rb
Normal file
18
app/mailers/api_token_mailer.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Preview all emails at http://localhost:3000/rails/mailers/api_token_mailer
|
||||||
|
class APITokenMailer < ApplicationMailer
|
||||||
|
helper MailerHelper
|
||||||
|
|
||||||
|
layout 'mailers/layout'
|
||||||
|
|
||||||
|
def expiration(api_token)
|
||||||
|
@api_token = api_token
|
||||||
|
user = api_token.administrateur.user
|
||||||
|
subject = "Votre jeton d'accès à la plateforme #{APPLICATION_NAME} expire le #{l(@api_token.expires_at, format: :long)}"
|
||||||
|
|
||||||
|
mail(to: user.email, subject:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.critical_email?(action_name)
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
17
app/views/api_token_mailer/expiration.html.haml
Normal file
17
app/views/api_token_mailer/expiration.html.haml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
- content_for(:title, "Expiration de votre jeton « #{@api_token.name} »")
|
||||||
|
|
||||||
|
%p
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
%p Vous recevez ce courriel car vous êtes le propriétaire du jeton « #{@api_token.name} ».
|
||||||
|
|
||||||
|
%p
|
||||||
|
%strong Ce jeton expirera le #{l(@api_token.expires_at, format: :long)}.
|
||||||
|
%br
|
||||||
|
L'accès à l'API de #{APPLICATION_NAME} sera alors bloqué pour ce jeton.
|
||||||
|
|
||||||
|
%p
|
||||||
|
Pour le renouveler, rendez-vous sur votre page de profil, dans la section « Jetons d’identification de l’API » :
|
||||||
|
= link_to profil_url, profil_url
|
||||||
|
|
||||||
|
= render partial: "layouts/mailers/signature"
|
23
spec/mailers/previews/api_token_mailer_preview.rb
Normal file
23
spec/mailers/previews/api_token_mailer_preview.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
class APITokenMailerPreview < ActionMailer::Preview
|
||||||
|
def expiration
|
||||||
|
APITokenMailer.expiration(api_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def api_token
|
||||||
|
APIToken.new(
|
||||||
|
administrateur: administrateur,
|
||||||
|
expires_at: 1.week.from_now,
|
||||||
|
name: 'My API token'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def administrateur
|
||||||
|
Administrateur.new(user:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def user
|
||||||
|
User.new(email: 'admin@a.com')
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue