Skip to content

Commit

Permalink
Send mail to user at alias creation (Fixes: #108)
Browse files Browse the repository at this point in the history
  • Loading branch information
doobry-systemli committed Feb 21, 2019
1 parent e852007 commit 27a4d20
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 43 deletions.
9 changes: 9 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ services:
resource: '../src/Controller'
tags: ['controller.service_arguments']

App\Builder\AliasCreatedMessageBuilder:
arguments:
$appUrl: "%env(APP_URL)%"
$projectName: "%env(PROJECT_NAME)%"

App\Builder\RecoveryProcessMessageBuilder:
arguments:
$appUrl: "%env(APP_URL)%"
Expand Down Expand Up @@ -109,6 +114,10 @@ services:
App\Helper\PasswordUpdater:
public: true

App\EventListener\AliasCreationListener:
arguments:
$sendMail: "%env(SEND_MAIL)%"

App\EventListener\RecoveryProcessListener:
arguments:
$sendMail: "%env(SEND_MAIL)%"
Expand Down
45 changes: 34 additions & 11 deletions default_translations/de/messages.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@ recovery:
waiting-info: Die Wartezeit dient deiner eigenen Sicherheit und kann nicht verkürzt oder umgangen werden.
waiting-time: Der zweite Schritt ist möglich ab dem %time%.
reset-lead: Du kannst nun dein Passwort zurücksetzen
email-subject: Das Passwort zu deinem E-Mail-Account %email% wird zurückgesetzt
email-body: |
Hallo %email%,
Jemand (hoffentlich du selbst) hat versucht, dein Passwort zurückzusetzen. Dazu wurden deine E-Mail-Addresse und der zugehörige Wiederherstellungscode unter %app_url%/recovery eingegeben.
Nun startet die 48-stündige Wartezeit. Diese geht bis zum %time%. Anschließend kann in einem zweiten Schritt dein Passwort neu gesetzt werden.
Du hast das nicht selbst ausgelöst? Jemand anderes mit Zugang zu deinem Wiederherstellungscode versucht, Kontrolle über deinen Account zu bekommen. Gehe schnellstmöglich zu %app_url%/user/recovery_token und erstelle dir einen neuen Wiederherstellungscode. Dadurch wird der alte ungültig.
Weiterhin viel Spaß mit deinem Mailaccount, wünscht dir dein %project_name% Admin Team.

navbar_left:
about-us:
Expand Down Expand Up @@ -212,3 +201,37 @@ Bad credentials.: Fehlerhafte Zugangsdaten

custom: gewählten
random: zufälligen

mail:
welcome-subject: Willkommen bei %domain%
welcome-body: |
Lieber User, liebe Userin, willkommen an Bord.
Im Web findest du Anleitungen zur Einrichtung deines E-Mail Accounts mit verschiedenen Client Programmen.
Dein Postfachgröße beträgt 1GB. Sollte dein Postfach diese Größe überschreiten, kann es zu Einschränkungen der Funktionalität deines E-Mail Accounts kommen.
In einer Woche bekommst du drei Einladungscodes gutgeschrieben, die du unter %app_url% abrufen kannst. Diese kannst du an Freund*innen weiterleiten und sie so zu %project_name% einladen.
Viel Spaß mit deinem Mailaccount, wünscht dir dein %project_name% Admin Team.
recovery-subject: Das Passwort zu deinem E-Mail-Account %email% wird zurückgesetzt
recovery-body: |
Hallo %email%,
Jemand (hoffentlich du selbst) hat versucht, dein Passwort zurückzusetzen. Dazu wurden deine E-Mail-Addresse und der zugehörige Wiederherstellungscode unter %app_url%/recovery eingegeben.
Nun startet die 48-stündige Wartezeit. Diese geht bis zum %time%. Anschließend kann in einem zweiten Schritt dein Passwort neu gesetzt werden.
Du hast das nicht selbst ausgelöst? Jemand anderes mit Zugang zu deinem Wiederherstellungscode versucht, Kontrolle über deinen Account zu bekommen. Gehe schnellstmöglich zu %app_url%/user/recovery_token und erstelle dir einen neuen Wiederherstellungscode. Dadurch wird der alte ungültig.
Weiterhin viel Spaß mit deinem Mailaccount, wünscht dir dein %project_name% Admin Team.
alias-created-subject: Neue Alias-Adresse erstellt
alias-created-body: |
Hallo %email%,
Für deine E-Mail-Adresse %email% wurde ein neues Alias angelegt:
%alias%
Du kannst deine E-Mail-Aliase hier verwalten: %app_url%/alias
Weiterhin viel Spaß mit deinem Mailaccount, wünscht dir dein %project_name% Admin Team.
56 changes: 34 additions & 22 deletions default_translations/en/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ recovery:
waiting-info: The waiting period is for your own security and cannot be shortened or skipped.
waiting-time: Second step starts at %time%.
reset-lead: You're now allowed to reset your password
email-subject: The password for your email account %email% will be reset
email-body: |
Hello %email%,
Somebody (let's hope it was you) tried to reset your account password. To do so, they authenticated with your email address and corresponding recovery code at %app_url%/recovery.
The 48 hours waiting period started now and will end at %time%. Afterwards, in a second step, a new password can be set for your account.
You didn't trigger this yourself? Then somebody else with access to your recovery token tries to get hold of your account. You should go to %app_url%/user/recovery_token immediately and create a new recovery token. This will invalidate the current recovery token.
We hope you continue to enjoy your email account. Your %project_name% admin team.

navbar_left:
about-us:
Expand Down Expand Up @@ -134,17 +123,6 @@ welcome:
<h3>Ready to go</h3>
<p>In the web you can find guides for settting up your email-account with several client programs.</p>
<p>In one week you will receive three invite codes, which you can collect at <a href="%app_url%">%app_url%</a>. You can pass these on to friends and invite them to register with %project_name%.</p>
email: |
Hello new user, welcome on board.
In the web you can find guides for setting up your email-account with several client programs.
You get a mailbox with 1GB quota. If you exceed your quota limit, your email-account may not function properly.
In one week you will receive three invite codes, which you can collect at %app_url%. You can pass these on to friends and invite them to register with %project_name%.
Sincerly your %project_name% admin team
closed:
title: Registration closed
Expand Down Expand Up @@ -206,3 +184,37 @@ Bad credentials.: Wrong login details

custom: custom
random: random

mail:
welcome-subject: Welcome to %domain%
welcome-body: |
Hello new user, welcome on board.
In the web you can find guides for setting up your email-account with several client programs.
You get a mailbox with 1GB quota. If you exceed your quota limit, your email-account may not function properly.
In one week you will receive three invite codes, which you can collect at %app_url%. You can pass these on to friends and invite them to register with %project_name%.
Sincerly, your %project_name% admin team.
recovery-subject: The password for your email account %email% will be reset
recovery-body: |
Hello %email%,
Somebody (let's hope it was you) tried to reset your account password. To do so, they authenticated with your email address and corresponding recovery code at %app_url%/recovery.
The 48 hours waiting period started now and will end at %time%. Afterwards, in a second step, a new password can be set for your account.
You didn't trigger this yourself? Then somebody else with access to your recovery token tries to get hold of your account. You should go to %app_url%/user/recovery_token immediately and create a new recovery token. This will invalidate the current recovery token.
We hope you continue to enjoy your email account. Your %project_name% admin team.
alias-created-subject: New alias address created
alias-created:body: |
Hello %email%,

For your email address %email% a new alias has been added:
%alias%

Manage your email aliases here: %app_url%/alias

We hope you continue to enjoy your email account. Your %project_name% admin team.
79 changes: 79 additions & 0 deletions src/Builder/AliasCreatedMessageBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Builder;

use Symfony\Component\Translation\TranslatorInterface;

/**
* Class AliasCreatedMessageBuilder.
*
* @author doobry <[email protected]>
*/
class AliasCreatedMessageBuilder
{
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var string
*/
private $appUrl;
/**
* @var string
*/
private $projectName;

/**
* AliasCreatedMessageBuilder constructor.
*
* @param TranslatorInterface $translator
* @param string $appUrl
* @param string $projectName
*/
public function __construct(TranslatorInterface $translator, $appUrl, $projectName)
{
$this->translator = $translator;
$this->appUrl = $appUrl;
$this->projectName = $projectName;
}

/**
* @param string $locale
* @param string $email
* @param string $alias
*
* @return string
*/
public function buildBody(string $locale, string $email, string $alias)
{
$body = $this->translator->trans(
'mail.alias-created-body',
[
'%app_url%' => $this->appUrl,
'%project_name%' => $this->projectName,
'%email%' => $email,
'%alias%' => $alias,
],
null,
$locale
);

return $body;
}

/**
* @param string $locale
* @param string $email
*
* @return string
*/
public function buildSubject(string $locale, string $email)
{
$subject = $this->translator->trans(
'mail.alias-created-subject', ['%email%' => $email], null, $locale
);

return $subject;
}
}
7 changes: 4 additions & 3 deletions src/Builder/RecoveryProcessMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public function __construct(TranslatorInterface $translator, $appUrl, $projectNa
public function buildBody(string $locale, string $email, string $time)
{
$body = $this->translator->trans(
'recovery.email-body',
'mail.recovery-body',
[
'%app_url%' => $this->appUrl,
'%project_name%' => $this->projectName,
'%email%' => $email, '%time%' => $time,
'%email%' => $email,
'%time%' => $time,
],
null,
$locale
Expand All @@ -70,7 +71,7 @@ public function buildBody(string $locale, string $email, string $time)
public function buildSubject(string $locale, string $email)
{
$subject = $this->translator->trans(
'recovery.email-subject', ['%email%' => $email], null, $locale
'mail.recovery-subject', ['%email%' => $email], null, $locale
);

return $subject;
Expand Down
8 changes: 5 additions & 3 deletions src/Builder/WelcomeMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ public function __construct(TranslatorInterface $translator, $domain, $appUrl, $
*/
public function buildBody($locale)
{
$body = $this->translator->trans('welcome.email', ['%app_url%' => $this->appUrl, '%project_name%' => $this->projectName], null, $locale);
$body = $this->translator->trans('mail.welcome-body', ['%app_url%' => $this->appUrl, '%project_name%' => $this->projectName], null, $locale);

return $body;
}

/**
* @param $locale
*
* @return string
*/
public function buildSubject()
public function buildSubject($locale)
{
$subject = sprintf('Welcome to %s!', $this->domain);
$subject = $this->translator->trans('mail.welcome-subject', ['%domain%' => $this->domain], null, $locale);

return $subject;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Creator/AliasCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\Alias;
use App\Entity\User;
use App\Event\AliasCreatedEvent;
use App\Event\RandomAliasCreatedEvent;
use App\Factory\AliasFactory;

Expand All @@ -25,6 +26,7 @@ public function create(User $user, ?string $localPart): Alias
$localPart = (isset($localPart)) ? strtolower($localPart) : null;
$alias = AliasFactory::create($user, $localPart);

$this->eventDispatcher->dispatch(AliasCreatedEvent::NAME, new AliasCreatedEvent($alias));
if (null === $localPart) {
$this->eventDispatcher->dispatch(RandomAliasCreatedEvent::NAME, new RandomAliasCreatedEvent($alias));
}
Expand Down
27 changes: 27 additions & 0 deletions src/Event/AliasCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Event;

use App\Entity\Alias;
use App\Traits\AliasAwareTrait;
use Symfony\Component\EventDispatcher\Event;

/**
* Class AliasCreatedEvent.
*/
class AliasCreatedEvent extends Event
{
use AliasAwareTrait;

const NAME = 'alias.custom_created';

/**
* Constructor.
*
* @param Alias $alias
*/
public function __construct(Alias $alias)
{
$this->alias = $alias;
}
}
Loading

0 comments on commit 27a4d20

Please sign in to comment.