Skip to content

Commit

Permalink
fixes platform emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Oct 6, 2023
1 parent 9e15d8d commit c00fff8
Show file tree
Hide file tree
Showing 30 changed files with 374 additions and 375 deletions.
23 changes: 8 additions & 15 deletions src/main/app/Manager/PdfManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,14 @@

class PdfManager
{
/** @var Environment */
private $templating;
/** @var TempFileManager */
private $tempFileManager;
/** @var PlatformManager */
private $platformManager;

public function __construct(
Environment $templating,
TempFileManager $tempFileManager,
PlatformManager $platformManager
private Environment $templating,
private TempFileManager $tempFileManager,
private PlatformManager $platformManager
) {
$this->templating = $templating;
$this->tempFileManager = $tempFileManager;
$this->platformManager = $platformManager;
}

public function fromHtml(string $htmlContent): ?string
public function fromHtml(string $htmlContent, string $title = null): ?string
{
$domPdf = new Dompdf([
'isHtml5ParserEnabled' => true,
Expand All @@ -35,8 +25,11 @@ public function fromHtml(string $htmlContent): ?string
'fontCache' => $this->tempFileManager->getDirectory(),
]);

$domPdf->loadHtml($this->templating->render('@ClarolineApp/pdf.html.twig', [
$domPdf->setBasePath($this->platformManager->getUrl().'/');

$domPdf->loadHtml($this->templating->render('@ClarolineApp/external.html.twig', [
'baseUrl' => $this->platformManager->getUrl(),
'title' => $title,
'content' => $htmlContent,
]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {FormData} from '#/main/app/content/form/containers/data'
import {selectors} from '#/main/app/security/password/reset/store/selectors'

const ResetPasswordForm = (props) =>
<div className="card login-container">
<div className="card login-container mx-auto">
<div className="authentication-column account-authentication-column">
<FormData
name={selectors.FORM_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {FormData} from '#/main/app/content/form/containers/data'
import {selectors} from '#/main/app/security/password/send/store/selectors'

const SendPasswordForm = (props) =>
<div className="card login-container">
<div className="card login-container mx-auto">
<div className="authentication-column account-authentication-column">
<p className="authentication-help">{trans('send_password_help')}</p>

Expand All @@ -35,6 +35,7 @@ const SendPasswordForm = (props) =>
className="w-100"
variant="btn"
size="lg"
htmlType="submit"
type={CALLBACK_BUTTON}
label={trans('send_password')}
callback={() => props.reset(props.form.data.email, () => {
Expand All @@ -44,7 +45,7 @@ const SendPasswordForm = (props) =>
/>

<Button
className="w-100"
className="w-100 mt-1"
variant="btn"
type={LINK_BUTTON}
label={trans('login', {}, 'actions')}
Expand Down
23 changes: 0 additions & 23 deletions src/main/app/Resources/modules/security/registration/index.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/app/Resources/views/external.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{#
Template used to print content outside of the claroline app.
This is used to print PDFs and Emails.
#}

<!DOCTYPE html>

<html lang="{{ app.request.locale }}" class="claroline-app {{ config.getParameter('theme') }}" data-bs-theme="light">
<head>
<meta charset="utf-8" />
{% if title is not empty %}
<title>{{ title }}</title>
{% endif %}

{# This is required in order to correctly manage relative path (mostly for tinyMce contents) #}
<base href="{{ baseUrl ~ '/' }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

{# We will need to load a specific stylesheets later #}
<link rel="stylesheet" type="text/css" href="{{ absolute_url(themeAsset('bootstrap.css')) }}" media="all" />
</head>

<body>
{{ content | raw }}
</body>
</html>
24 changes: 0 additions & 24 deletions src/main/app/Resources/views/pdf.html.twig

This file was deleted.

107 changes: 107 additions & 0 deletions src/main/authentication/Manager/MailManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <consortium@claroline.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\AuthenticationBundle\Manager;

use Claroline\AppBundle\Event\StrictDispatcher;
use Claroline\CoreBundle\Entity\User;
use Claroline\CoreBundle\Event\CatalogEvents\SecurityEvents;
use Claroline\CoreBundle\Event\Security\ForgotPasswordEvent;
use Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler;
use Claroline\CoreBundle\Manager\LocaleManager;
use Claroline\CoreBundle\Manager\MailManager as BaseMailManager;
use Claroline\CoreBundle\Manager\Template\TemplateManager;
use Claroline\CoreBundle\Manager\UserManager;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class MailManager
{
public function __construct(
private TranslatorInterface $translator,
private UrlGeneratorInterface $router,
private StrictDispatcher $dispatcher,
private PlatformConfigurationHandler $config,
private BaseMailManager $mailManager,
private LocaleManager $localeManager,
private TemplateManager $templateManager,
private UserManager $userManager
) {
}

public function sendForgotPassword(User $user): bool
{
$this->dispatcher->dispatch(SecurityEvents::FORGOT_PASSWORD, ForgotPasswordEvent::class, [$user]);

$locale = $this->localeManager->getLocale($user);
$placeholders = [
'first_name' => $user->getFirstName(),
'last_name' => $user->getLastName(),
'username' => $user->getUsername(),
];

if (!$user->isEnabled()) {
$subject = $this->templateManager->getTemplate('user_disabled', $placeholders, $locale, 'title');
$body = $this->templateManager->getTemplate('user_disabled', $placeholders, $locale);

return $this->mailManager->send($subject, $body, [$user], null, [], true);
}

$this->userManager->initializePassword($user); // should not be done here (only manage email sending here)

$placeholders['password_reset_link'] = $this->router->generate(
'claro_index',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)."#/newpassword/{$user->getResetPasswordHash()}";

$subject = $this->templateManager->getTemplate('forgotten_password', $placeholders, $locale, 'title');
$body = $this->templateManager->getTemplate('forgotten_password', $placeholders, $locale);

return $this->mailManager->send($subject, $body, [$user], null, [], true);
}

public function sendInitPassword(User $user): bool
{
$this->userManager->initializePassword($user); // should not be done here (only manage email sending here)

$link = $this->router->generate(
'claro_index',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)."#/newpassword/{$user->getResetPasswordHash()}";
$locale = $this->localeManager->getLocale($user);
$placeholders = [
'first_name' => $user->getFirstName(),
'last_name' => $user->getLastName(),
'username' => $user->getUsername(),
'password_initialization_link' => $link,
];
$subject = $this->templateManager->getTemplate('password_initialization', $placeholders, $locale, 'title');
$body = $this->templateManager->getTemplate('password_initialization', $placeholders, $locale);

return $this->mailManager->send($subject, $body, [$user], null, [], true);
}

// TODO : move in Privacy plugin when available
public function sendRequestToDPO(User $user): bool
{
$name = $user->getFullName();
$idUser = $user->getId();
$dpoEmail = $this->config->getParameter('privacy.dpo.email');
$locale = $user->getLocale();

$subject = $this->translator->trans('account_deletion.subject', [], 'privacy', $locale);
$content = $this->translator->trans('account_deletion.body', ['%name%' => $name, '%id%' => $idUser], 'privacy', $locale);
$body = $this->templateManager->getTemplate('email_layout', ['content' => $content], $locale);

return $this->mailManager->send($subject, $body, [], null, ['to' => [$dpoEmail]]);
}
}
15 changes: 12 additions & 3 deletions src/main/authentication/Resources/config/services/manager.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
services:
_defaults:
autowire: false
autoconfigure: false
public: true
public: true # should not be public

Claroline\AuthenticationBundle\Manager\OauthManager:
arguments:
Expand All @@ -14,6 +12,17 @@ services:
tags:
- { name: kernel.event_listener, event: refresh_cache, method: refreshCache } # TODO : create a listener for that

Claroline\AuthenticationBundle\Manager\MailManager:
arguments:
- '@translator'
- '@router'
- '@Claroline\AppBundle\Event\StrictDispatcher'
- '@Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler'
- '@Claroline\CoreBundle\Manager\MailManager'
- '@Claroline\CoreBundle\Manager\LocaleManager'
- '@Claroline\CoreBundle\Manager\Template\TemplateManager'
- '@Claroline\CoreBundle\Manager\UserManager'

Claroline\AuthenticationBundle\Manager\AuthenticationManager:
arguments:
- '@Claroline\AppBundle\Persistence\ObjectManager'
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const ParametersModal = props =>
title={props.isNew ? trans('new_ip', {}, 'security') : trans('parameters')}
subtitle={!props.isNew && props.ip ? props.ip.ip : ''}
onEntering={() => props.loadIp(props.ip)}
size="lg"
>
<FormData
flush={true}
name={selectors.STORE_NAME}
sections={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const ParametersModal = props =>
title={props.isNew ? trans('new_token', {}, 'security') : trans('parameters')}
subtitle={!props.isNew && props.token ? props.token.description || props.token.token : ''}
onEntering={() => props.load(props.token)}
size="lg"
>
<FormData
flush={true}
name={selectors.STORE_NAME}
sections={[
{
Expand Down
12 changes: 3 additions & 9 deletions src/main/community/Controller/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

use Claroline\AppBundle\Annotations\ApiDoc;
use Claroline\AppBundle\Controller\AbstractCrudController;
use Claroline\AuthenticationBundle\Manager\MailManager;
use Claroline\CoreBundle\Controller\APINew\Model\HasOrganizationsTrait;
use Claroline\CoreBundle\Controller\APINew\Model\HasRolesTrait;
use Claroline\CoreBundle\Controller\APINew\Model\HasUsersTrait;
use Claroline\CoreBundle\Entity\Group;
use Claroline\CoreBundle\Entity\Organization\Organization;
use Claroline\CoreBundle\Manager\MailManager;
use Claroline\CoreBundle\Security\PermissionCheckerTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -37,14 +37,8 @@ class GroupController extends AbstractCrudController
use HasOrganizationsTrait;
use PermissionCheckerTrait;

/** @var TokenStorageInterface */
private $tokenStorage;

/** @var AuthorizationCheckerInterface */
private $authorization;

/** @var MailManager */
private $mailManager;
private TokenStorageInterface $tokenStorage;
private MailManager $mailManager;

public function __construct(
TokenStorageInterface $tokenStorage,
Expand Down
Loading

0 comments on commit c00fff8

Please sign in to comment.