Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from smartbooster/33_send_account_creation_ema…
Browse files Browse the repository at this point in the history
…il_trait

#33 Add SendAccountCreationEmailTrait
  • Loading branch information
mathieu-ducrot authored Jul 6, 2021
2 parents 1cd8ca4 + 841aaaa commit 6dabeff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG for 1.x
===================

## v1.1.3 - (2021-07-06)

### Added

- [[#33](https://github.com/smartbooster/authentication-bundle/issues/33)] Add a ControllerTrait for the admin.extension.action_send_account_creation_email

## v1.1.2 - (2021-05-04)

### Added
Expand Down
43 changes: 43 additions & 0 deletions src/Controller/CRUD/SendAccountCreationEmailTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Smart\AuthenticationBundle\Controller\CRUD;

use Smart\AuthenticationBundle\Email\AccountCreationEmail;
use Smart\AuthenticationBundle\Security\SmartUserInterface;
use Smart\AuthenticationBundle\Security\Token;
use Smart\SonataBundle\Admin\AbstractAdmin;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Yokai\SecurityTokenBundle\Manager\TokenManagerInterface;

/**
* @author Mathieu Ducrot <[email protected]>
* @property AbstractAdmin $admin
*/
trait SendAccountCreationEmailTrait
{
public function sendAccountCreationEmailAction(TokenManagerInterface $tokenManager, MailerInterface $mailer, TranslatorInterface $translator): Response
{
/** @var SmartUserInterface $subject */
$subject = $this->admin->getSubject();

$token = $tokenManager->create(Token::RESET_PASSWORD, $subject);
$context = 'admin';

$mailer->send(new AccountCreationEmail([
'from' => $this->getParameter('app.mail_from'),
'subject' => $translator->trans('security.user_created.subject', [], 'email'),
'context' => $context,
'token' => $token->getValue(),
'domain' => $context . '.' . $this->getParameter('domain'),
'security_reset_password_route' => $context . '_security_reset_password'
], $subject->getEmail()));

$this->addFlash('success', $translator->trans('send_account_creation_email.success', [
'{email}' => $subject->getEmail()
], 'admin'));

return $this->redirect($this->admin->generateUrl('list'));
}
}

0 comments on commit 6dabeff

Please sign in to comment.