Skip to content

Commit

Permalink
Allow to set a custom reset password page
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Dec 9, 2024
1 parent 6edef05 commit 30638f9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@
'eval' => ['fieldType' => 'radio'],
'sql' => ['type' => 'integer', 'default' => 0, 'unsigned' => true],
];
$GLOBALS['TL_DCA']['tl_module']['fields']['nc_lost_password_jumpTo'] = [
'exclude' => true,
'inputType' => 'pageTree',
'foreignKey' => 'tl_page.title',
'relation' => ['type' => 'hasOne', 'load' => 'lazy'],
'eval' => ['fieldType' => 'radio'],
'sql' => ['type' => 'integer', 'default' => 0, 'unsigned' => true],
];
8 changes: 8 additions & 0 deletions contao/languages/de/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<source>Allows you to configure a different redirect page after successful activation.</source>
<target>Ermöglicht es Ihnen, eine andere Weiterleitungsseite nach erfolgreicher Aktivierung zu konfigurieren.</target>
</trans-unit>
<trans-unit id="tl_module.nc_lost_password_jumpTo.0">
<source>Reset password page</source>
<target>Seite zum Zurücksetzen des Passworts</target>
</trans-unit>
<trans-unit id="tl_module.nc_lost_password_jumpTo.1">
<source>It allows you to configure a different page for password resets. By default, the reset link redirects to the same page. However, you can specify a different page here, enabling you to use unique content elements. Ensure you include this module again on the specified page.</source>
<target>Es ermöglicht Ihnen, eine andere Seite für das Zurücksetzen des Passworts zu konfigurieren. Standardmäßig führt der Zurücksetzungslink zur gleichen Seite. Sie können jedoch hier eine andere Seite angeben, wodurch Sie einzigartige Inhaltselemente verwenden können. Stellen Sie sicher, dass Sie dieses Modul auf der angegebenen Seite erneut einfügen.</target>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions contao/languages/en/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<source>Allows you to configure a different redirect page after successful activation.</source>
<target>Allows you to configure a different redirect page after successful activation.</target>
</trans-unit>
<trans-unit id="tl_module.nc_lost_password_jumpTo.0">
<source>Reset password page</source>
<target>Reset password page</target>
</trans-unit>
<trans-unit id="tl_module.nc_lost_password_jumpTo.1">
<source>It allows you to configure a different page for password resets. By default, the reset link redirects to the same page. However, you can specify a different page here, enabling you to use unique content elements. Ensure you include this module again on the specified page.</source>
<target>It allows you to configure a different page for password resets. By default, the reset link redirects to the same page. However, you can specify a different page here, enabling you to use unique content elements. Ensure you include this module again on the specified page.</target>
</trans-unit>
</body>
</file>
</xliff>
11 changes: 10 additions & 1 deletion src/Controller/FrontendModule/LostPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

use Codefog\HasteBundle\Formatter;
use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule;
use Contao\CoreBundle\Routing\ContentUrlGenerator;
use Contao\Environment;
use Contao\Idna;
use Contao\ModuleModel;
use Contao\PageModel;
use Contao\System;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Terminal42\NotificationCenterBundle\Legacy\LostPasswordModule;
use Terminal42\NotificationCenterBundle\NotificationCenter;
use Terminal42\NotificationCenterBundle\Receipt\Receipt;
Expand All @@ -20,6 +22,7 @@
class LostPasswordController extends LostPasswordModule
{
public function __construct(
private readonly ContentUrlGenerator $contentUrlGenerator,
private readonly NotificationCenter $notificationCenter,
private readonly Formatter $formatter,
) {
Expand All @@ -40,10 +43,16 @@ protected function sendPasswordLink($objMember): void
// Prepare the simple tokens
$tokens = [];
$tokens['domain'] = Idna::decode(Environment::get('host'));
$tokens['link'] = Idna::decode(Environment::get('url')).Environment::get('requestUri').(str_contains((string) Environment::get('requestUri'), '?') ? '&' : '?').'token='.$optInToken->getIdentifier();
$tokens['token'] = $optInToken->getIdentifier();
$tokens['recipient_email'] = $objMember->email;

// Generate a custom target link URL, if any
if ($this->nc_lost_password_jumpTo && null !== ($targetPage = PageModel::findPublishedById($this->nc_lost_password_jumpTo))) {
$tokens['link'] = $this->contentUrlGenerator->generate($targetPage, ['token' => $optInToken->getIdentifier()], UrlGeneratorInterface::ABSOLUTE_URL);
} else {
$tokens['link'] = Idna::decode(Environment::get('url')).Environment::get('requestUri').(str_contains((string) Environment::get('requestUri'), '?') ? '&' : '?').'token='.$optInToken->getIdentifier();
}

// Add member tokens
foreach ($objMember->row() as $k => $v) {
$tokens['member_'.$k] = $this->formatter->dcaValue('tl_member', $k, $v);
Expand Down
1 change: 1 addition & 0 deletions src/EventListener/Backend/DataContainer/ModuleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private function handleLostPasswordModule(): void

PaletteManipulator::create()
->addField('nc_notification', 'reg_password', PaletteManipulator::POSITION_BEFORE)
->addField('nc_lost_password_jumpTo', 'email_legend', PaletteManipulator::POSITION_PREPEND)
->removeField('reg_password')
->applyToPalette('lostPasswordNotificationCenter', 'tl_module')
;
Expand Down

0 comments on commit 30638f9

Please sign in to comment.