Skip to content

Commit 527d00a

Browse files
author
Bastian Heist
committed
TASK: remove own EmailService and use sandstorm/templatemailer email service instead.
1 parent 61832dd commit 527d00a

File tree

9 files changed

+57
-193
lines changed

9 files changed

+57
-193
lines changed

Classes/Controller/RegistrationController.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
namespace Sandstorm\UserManagement\Controller;
33

4+
use Sandstorm\TemplateMailer\Domain\Service\EmailService;
45
use Sandstorm\UserManagement\Domain\Model\RegistrationFlow;
56
use Sandstorm\UserManagement\Domain\Repository\RegistrationFlowRepository;
6-
use Sandstorm\UserManagement\Domain\Service\EmailService;
77
use Sandstorm\UserManagement\Domain\Service\UserCreationServiceInterface;
88
use Neos\Flow\Annotations as Flow;
99
use Neos\Flow\Mvc\Controller\ActionController;
@@ -32,18 +32,6 @@ class RegistrationController extends ActionController
3232
*/
3333
protected $emailService;
3434

35-
/**
36-
* @var string
37-
* @Flow\InjectConfiguration(path="email.senderAddress")
38-
*/
39-
protected $emailSenderAddress;
40-
41-
/**
42-
* @var string
43-
* @Flow\InjectConfiguration(path="email.senderName")
44-
*/
45-
protected $emailSenderName;
46-
4735
/**
4836
* @var string
4937
* @Flow\InjectConfiguration(path="email.subjectActivation")
@@ -78,18 +66,17 @@ public function registerAction(RegistrationFlow $registrationFlow)
7866
['token' => $registrationFlow->getActivationToken()],
7967
'Registration');
8068

81-
$this->emailService->sendTemplateBasedEmail(
69+
$this->emailService->sendTemplateEmail(
8270
'ActivationToken',
8371
$this->subjectActivation,
84-
[$this->emailSenderAddress => $this->emailSenderName],
8572
[$registrationFlow->getEmail()],
8673
[
8774
'activationLink' => $activationLink,
88-
'applicationName' => $this->emailSenderName,
8975
'registrationFlow' => $registrationFlow,
9076
// BaseUri can be used to embed resources (images) into the email
9177
'baseUri' => htmlspecialchars($this->controllerContext->getRequest()->getHttpRequest()->getBaseUri())
92-
]
78+
],
79+
'sandstorm_usermanagement_sender_email'
9380
);
9481

9582
$this->registrationFlowRepository->add($registrationFlow);

Classes/Controller/ResetPasswordController.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
namespace Sandstorm\UserManagement\Controller;
33

4+
use Neos\Flow\Property\TypeConverter\PersistentObjectConverter;
45
use Sandstorm\UserManagement\Domain\Model\ResetPasswordFlow;
56
use Sandstorm\UserManagement\Domain\Repository\ResetPasswordFlowRepository;
6-
use Sandstorm\UserManagement\Domain\Service\EmailService;
77
use Sandstorm\UserManagement\Domain\Service\UserCreationServiceInterface;
88
use Neos\Flow\Annotations as Flow;
99
use Neos\Flow\Mvc\Controller\ActionController;
@@ -35,22 +35,10 @@ class ResetPasswordController extends ActionController
3535

3636
/**
3737
* @Flow\Inject
38-
* @var EmailService
38+
* @var \Sandstorm\TemplateMailer\Domain\Service\EmailService
3939
*/
4040
protected $emailService;
4141

42-
/**
43-
* @var string
44-
* @Flow\InjectConfiguration(path="email.senderAddress")
45-
*/
46-
protected $emailSenderAddress;
47-
48-
/**
49-
* @var string
50-
* @Flow\InjectConfiguration(path="email.senderName")
51-
*/
52-
protected $emailSenderName;
53-
5442
/**
5543
* @var string
5644
* @Flow\InjectConfiguration(path="email.subjectResetPassword")
@@ -70,8 +58,8 @@ public function initializeRequestTokenAction()
7058
$config = $this->arguments->getArgument('resetPasswordFlow')->getPropertyMappingConfiguration();
7159
$config->allowProperties('email');
7260
$config->setTypeConverterOption(
73-
\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::class,
74-
\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
61+
PersistentObjectConverter::class,
62+
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
7563
TRUE
7664
);
7765
}
@@ -98,20 +86,15 @@ public function requestTokenAction(ResetPasswordFlow $resetPasswordFlow)
9886
['token' => $resetPasswordFlow->getResetPasswordToken()],
9987
'ResetPassword');
10088

101-
$this->emailService->sendTemplateBasedEmail(
89+
$this->emailService->sendTemplateEmail(
10290
'ResetPasswordToken',
10391
$this->subjectResetPassword,
104-
[$this->emailSenderAddress => $this->emailSenderName],
10592
[$resetPasswordFlow->getEmail()],
10693
[
10794
'resetPasswordLink' => $resetPasswordLink,
108-
'applicationName' => $this->emailSenderName,
109-
'resetPasswordFlow' => $resetPasswordFlow,
110-
// BaseUri can be used to embed resources (images) into the email
111-
'baseUri' => htmlspecialchars($this->controllerContext->getRequest()
112-
->getHttpRequest()
113-
->getBaseUri())
114-
]
95+
'resetPasswordFlow' => $resetPasswordFlow
96+
],
97+
'sandstorm_usermanagement_sender_email'
11598
);
11699

117100
$this->resetPasswordFlowRepository->add($resetPasswordFlow);

Classes/Domain/Service/EmailService.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

Configuration/Settings.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,9 @@ Sandstorm:
1010
body: 'Sie haben ungültige Zugangsdaten eingegeben. Bitte versuchen Sie es noch einmal.'
1111
# Email settings
1212
email:
13-
# Sender Address
14-
senderAddress: 'test@example.com'
15-
# Sender name - will be merged with senderAddress to something
16-
# like "Sandstorm Usermanagement Package <test@example.com>"
17-
senderName: 'Sandstorm Usermanagement Package'
18-
# Subject line for the account confirmation email
1913
subjectActivation: 'Please confirm your account'
2014
# Subject line for the password reset email
2115
subjectResetPassword: 'Password reset'
22-
# Template package to read the email templates from - this can be used to override
23-
# e-mail templates. They are expected in the package given here, in the folder
24-
# <Package>/Resources/Private/EmailTemplates.
25-
templatePackage: 'Sandstorm.UserManagement'
2616
# An array of roles which are assigned to users after they activate their account.
2717
rolesForNewUsers: []
2818

@@ -44,6 +34,14 @@ Sandstorm:
4434
# controllerArguments:
4535
# yourAdditionalArgument: 'test1'
4636

37+
TemplateMailer:
38+
templatePackages:
39+
99999: 'Sandstorm.UserManagement'
40+
senderAddresses:
41+
'sandstorm_usermanagement_sender_email':
42+
name: 'Sandstorm Usermanagement Package'
43+
address: 'test@example.com'
44+
4745
Neos:
4846
Flow:
4947
mvc:

README.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,34 @@ This package works in Neos CMS and Flow and provides the following functionality
99
* "Forgotten password" with password reset e-mail
1010

1111
## Compatibility and Maintenance
12-
Sandstorm.UserManagement is currently being maintained for Neos 2.3 LTS and Neos 3.x. There is an older release for Neos 2.2,
13-
which is no longer maintained.
14-
15-
| Neos / Flow Version | Sandstorm.UserManagement Version | Maintained |
16-
|----------------------------|----------------------------------|------------|
17-
| Neos 3.x, Flow 4.x | 4.x | Yes |
18-
| Neos 2.3 LTS, Flow 3.3 LTS | 3.x | Yes |
19-
| Neos 2.2, Flow 3.2 | 1.x | No |
12+
Sandstorm.UserManagement is currently being maintained for Neos 2.3 LTS and Neos 3.x.
13+
14+
| Neos / Flow Version | Sandstorm.UserManagement Version | Maintained |
15+
|----------------------------|----------------------------------|-----------------|
16+
| Neos 3.x, Flow 4.x | 5.x | Yes |
17+
| Neos 2.3 LTS, Flow 3.3 LTS | 3.x | Bugfixes |
18+
| Neos 2.2, Flow 3.2 | 1.x | No |
19+
20+
## Breaking changes in Version 5.x
21+
Since I've removed the direct dependency to swiftmailer in favor of the Sandstorm/TemplateMailer package
22+
(which provides css inlining), the EmailService in this package was removed. This means that you will need
23+
to change some of your config options, because they are now set in the Sandstorm.TemplateMailer config path
24+
instead of inside the Sandstom.UserManagement path. Please refer to the [Sandstorm/TemplateMailer Documentation](https://github.com/sandstorm/TemplateMailer)
25+
for instructions on how to set the following configurations:
26+
27+
* senderAddress
28+
* senderName
29+
* templatePackage
30+
31+
Hint: to override the sender address for this package, you will need the following setting:
32+
```YAML
33+
Sandstorm:
34+
TemplateMailer:
35+
senderAddresses:
36+
sandstorm_usermanagement_sender_email: # You need to use this exact key to override the UserManagement defaults
37+
name: Your-App
38+
address: yoursenderemail@yourapp.de
39+
```
2040
2141
# Configuration
2242
@@ -42,27 +62,14 @@ Sandstorm:
4262
body: 'Sie haben ungültige Zugangsdaten eingegeben. Bitte versuchen Sie es noch einmal.'
4363
# Email settings
4464
email:
45-
# Sender Address
46-
senderAddress: 'test@example.com'
47-
# Sender name - will be merged with senderAddress to something
48-
# like "Sandstorm Usermanagement Package <test@example.com>"
49-
senderName: 'Sandstorm Usermanagement Package'
5065
# Subject line for the account confirmation email
5166
subjectActivation: 'Please confirm your account'
5267
# Subject line for the password reset email
5368
subjectResetPassword: 'Password reset'
54-
# Template package to read the email templates from - this can be used to override
55-
# e-mail templates. They are expected in the package given here, in the folder
56-
# <Package>/Resources/Private/EmailTemplates.
57-
templatePackage: 'Sandstorm.UserManagement'
5869
# An array of roles which are assigned to users after they activate their account.
5970
rolesForNewUsers: []
6071
```
6172
62-
## Configuring SwiftMailer
63-
The UserManagement package requires SwiftMailer to send out e-mails. Please check the swiftmailer package's
64-
configuration options (https://github.com/neos/swiftmailer) in order to configure SMTP credentials.
65-
6673
## Additional Settings for usage in Neos
6774
You should switch the implementation of the Redirect and User Creation Services to the Neos services. Add this to your `Objects.yaml`:
6875
```
@@ -219,7 +226,9 @@ argument to which you can pass the name of the Auth Provider you are using.
219226
You can change any template via the default method using `Views.yaml`. Please see
220227
http://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/ModelViewController.html#configuring-views-through-views-yaml.
221228
Here's an example how to plug your own login template:
229+
222230
```
231+
223232
-
224233
requestFilter: 'isPackage("Sandstorm.UserManagement") && isController("Login") && isAction("login")'
225234
options:
@@ -232,7 +241,7 @@ Here's an example how to plug your own login template:
232241
As documented in the configuration options above, overriding e-mail templates is easy:
233242
* Copy the `EmailTemplates` folder from the UserManagement's `Resources/Private` folder into your
234243
own package and modify the templates to your heart's desire.
235-
* Then, set the `email.templatePackage` configuration option to that package's name. Done!
244+
* Add your own package to the templatePackages config, as described in [Sandstorm/TemplateMailer Documentation](https://github.com/sandstorm/TemplateMailer).
236245
237246
## Changing the User model
238247
You might want to add additional information to the user model. This can be done by extending

Resources/Private/EmailTemplates/ActivationToken.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<body>
33
Dear User,<br />
44

5-
you signed up for an account at {applicationName}. To confirm your account,
5+
you signed up for an account at our service. To confirm your account,
66
please click the link below.
77
<br /><br />
88
<a href="{activationLink}">Click here to activate your account</a>
99
<br /><br />
10-
Thank you for your interest in {applicationName}!
10+
Thank you for your interest in our service!
1111
</body>
1212
</html>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Dear User,
22

3-
you signed up for an account at {applicationName}. To confirm your account,
3+
you signed up for an account at our service. To confirm your account,
44
please click the link below or copy it into your browser:
55

66
{activationLink}
77

8-
Thank you for your interest in {applicationName}!
8+
Thank you for your interest in our service!

Resources/Private/EmailTemplates/ResetPasswordToken.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<body>
33
Dear User,<br />
44

5-
you want to reset your password for {applicationName}. To continue,
5+
you want to reset your password for our service. To continue,
66
please click the link below:
77
<br /><br />
88
<a href="{resetPasswordLink}">Click here to reset your password</a>

0 commit comments

Comments
 (0)