Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/Controller/Admin/InvitationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace Softspring\UserBundle\Controller\Admin;

use Exception;
use Softspring\Component\Events\DispatchGetResponseTrait;
use Softspring\UserBundle\Event\GetResponseUserEvent;
use Softspring\UserBundle\Mailer\UserMailerInterface;
use Softspring\UserBundle\Manager\UserInvitationManagerInterface;
use Softspring\UserBundle\SfsUserEvents;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class InvitationsController extends AbstractController
Expand Down Expand Up @@ -34,12 +38,22 @@ public function pendingCountWidget(): Response
]);
}

public function resendEmail(mixed $invitation): Response
public function resendEmail(mixed $invitation, Request $request): Response
{
$invitation = $this->invitationsManager->findInvitationBy(['id' => $invitation]);

if (!$invitation->getAcceptedAt() && $this->userMailer) {
$this->userMailer->sendInvitationEmail($invitation);
try {
$invitation = $this->invitationsManager->findInvitationBy(['id' => $invitation]);
$user = $invitation->getUser();

if (!$invitation->getAcceptedAt() && $this->userMailer) {
$this->userMailer->sendInvitationEmail($invitation);
if ($response = $this->dispatchGetResponse(SfsUserEvents::ADMIN_INVITATIONS_RESEND_SUCCESS, new GetResponseUserEvent($user, $request))) {
return $response;
}
}
} catch (Exception $e) {
if ($response = $this->dispatchGetResponse(SfsUserEvents::ADMIN_INVITATIONS_RESEND_ERROR, new GetResponseUserEvent($user, $request))) {
return $response;
}
}

return $this->redirectToRoute('sfs_user_admin_invitations_details', ['invitation' => $invitation]);
Expand Down
17 changes: 14 additions & 3 deletions src/Controller/Settings/ConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Softspring\UserBundle\Controller\Settings;

use Exception;
use Softspring\Component\Events\DispatchGetResponseTrait;
use Softspring\UserBundle\Event\GetResponseUserEvent;
use Softspring\UserBundle\Mailer\UserMailerInterface;
use Softspring\UserBundle\Manager\UserManagerInterface;
use Softspring\UserBundle\Model\ConfirmableInterface;
use Softspring\UserBundle\Model\UserInterface;
use Softspring\UserBundle\SfsUserEvents;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -33,9 +36,17 @@ public function resendConfirmation(Request $request): Response
{
/** @var UserInterface $user */
$user = $this->getUser();

if ($user instanceof ConfirmableInterface && !$user->isConfirmed()) {
$this->userMailer->sendRegisterConfirmationEmail($user);
try {
if ($user instanceof ConfirmableInterface && !$user->isConfirmed()) {
$this->userMailer->sendRegisterConfirmationEmail($user);
if ($response = $this->dispatchGetResponse(SfsUserEvents::ADMIN_USERS_RESEND_CONFIRMATION_SUCCESS, new GetResponseUserEvent($user, $request))) {
return $response;
}
}
} catch (Exception $e) {
if ($response = $this->dispatchGetResponse(SfsUserEvents::ADMIN_USERS_RESEND_CONFIRMATION_ERROR, new GetResponseUserEvent($user, $request))) {
return $response;
}
}

return $this->redirect($request->server->get('HTTP_REFERER') ?? $this->generateUrl('sfs_user_preferences'));
Expand Down
24 changes: 24 additions & 0 deletions src/EventListener/Admin/FlashMessagesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static function getSubscribedEvents(): array
SfsUserEvents::ADMIN_USERS_RESEND_CONFIRMATION_SUCCESS => 'onResendConfirmationSuccess',
SfsUserEvents::ADMIN_USERS_RESEND_CONFIRMATION_ERROR => 'onResendConfirmationError',
SfsUserEvents::ADMIN_USERS_RESEND_CONFIRMATION_ALREADY_CONFIRMED => 'onResendConfirmationAlready',
SfsUserEvents::ADMIN_INVITATIONS_RESEND_SUCCESS => 'onResendInvitationsSuccess',
SfsUserEvents::ADMIN_INVITATIONS_RESEND_ERROR => 'onResendInvitationsError',
];
}

Expand Down Expand Up @@ -63,6 +65,28 @@ public function onResendConfirmationAlready(GetResponseUserEvent $event): void
], 'sfs_user', $locale);
}

public function onResendInvitationsSuccess(GetResponseUserEvent $event): void
{
$user = $event->getUser();
$locale = $event->getRequest()->getLocale();

$this->addFlash('success', 'admin_users.resend_invitaion.messages.success', [
'%username%' => $user->getDisplayName(),
'%email%' => $user instanceof UserWithEmailInterface ? $user->getEmail() : $user->getDisplayName(),
], 'sfs_user', $locale);
}

public function onResendInvitationsError(GetResponseUserEvent $event): void
{
$user = $event->getUser();
$locale = $event->getRequest()->getLocale();

$this->addFlash('error', 'admin_users.resend_invitaion.messages.error', [
'%username%' => $user->getDisplayName(),
'%email%' => $user instanceof UserWithEmailInterface ? $user->getEmail() : $user->getDisplayName(),
], 'sfs_user', $locale);
}

protected function addFlash(string $type, string $trans, array $transParams = [], string $domain = 'sfs_user', string $locale = 'en'): void
{
if (!$this->flashBag) {
Expand Down
8 changes: 6 additions & 2 deletions src/EventListener/EmailInvitationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\UserBundle\EventListener;

use Exception;
use Softspring\UserBundle\Event\UserInvitationEvent;
use Softspring\UserBundle\Mailer\UserMailerInterface;
use Softspring\UserBundle\SfsUserEvents;
Expand All @@ -25,8 +26,11 @@ public static function getSubscribedEvents(): array

public function onInvitation(UserInvitationEvent $event): void
{
$invitation = $event->getInvitation();
try {
$invitation = $event->getInvitation();

$this->mailer->sendInvitationEmail($invitation);
$this->mailer->sendInvitationEmail($invitation);
} catch (Exception $e) {
}
}
}
16 changes: 10 additions & 6 deletions src/EventListener/SendResetPasswordEmailListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Softspring\UserBundle\EventListener;

use DateTime;
use Exception;
use Softspring\Component\Events\GetResponseFormEvent;
use Softspring\UserBundle\Mailer\UserMailerInterface;
use Softspring\UserBundle\Manager\UserManagerInterface;
Expand Down Expand Up @@ -57,13 +58,16 @@ public function onResetRequestCheckToken(GetResponseFormEvent $event): void

public function sendResetEmail(GetResponseFormEvent $event): void
{
/** @var UserInterface $user */
$user = $this->userManager->findUserBy(['email' => $event->getForm()->get('email')->getData()]);
try {
/** @var UserInterface $user */
$user = $this->userManager->findUserBy(['email' => $event->getForm()->get('email')->getData()]);

if (!$user instanceof PasswordRequestInterface) {
return;
}
if (!$user instanceof PasswordRequestInterface) {
return;
}

$this->mailer->sendResettingEmail($user);
$this->mailer->sendResettingEmail($user);
} catch (Exception $e) {
}
}
}
18 changes: 11 additions & 7 deletions src/EventListener/UserRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\UserBundle\EventListener;

use Exception;
use Softspring\UserBundle\Event\GetResponseUserEvent;
use Softspring\UserBundle\Mailer\UserMailerInterface;
use Softspring\UserBundle\Manager\UserManagerInterface;
Expand Down Expand Up @@ -34,14 +35,17 @@ public static function getSubscribedEvents(): array

public function onRegisterSendConfirmationEmail(GetResponseUserEvent $event): void
{
$user = $event->getUser();
if (!$user instanceof ConfirmableInterface) {
return;
}
try {
$user = $event->getUser();
if (!$user instanceof ConfirmableInterface) {
return;
}

$user->setConfirmationToken($this->tokenGenerator->generateToken());
$this->userManager->saveEntity($user);
$user->setConfirmationToken($this->tokenGenerator->generateToken());
$this->userManager->saveEntity($user);

$this->mailer->sendRegisterConfirmationEmail($user);
$this->mailer->sendRegisterConfirmationEmail($user);
} catch (Exception $e) {
}
}
}
2 changes: 2 additions & 0 deletions src/SfsUserEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ class SfsUserEvents
public const ADMIN_INVITATIONS_CREATE_SUCCESS = 'sfs_user.admin.invitations.create_success';
public const ADMIN_INVITATIONS_CREATE_FORM_INVALID = 'sfs_user.admin.invitations.create_form_invalid';
public const ADMIN_INVITATIONS_CREATE_VIEW = 'sfs_user.admin.invitations.create_view';
public const ADMIN_INVITATIONS_RESEND_SUCCESS = 'sfs_user.admin.invitations.resend_success';
public const ADMIN_INVITATIONS_RESEND_ERROR = 'sfs_user.admin.invitations.resend__error';

/** @Event("Softspring\Component\Events\GetResponseRequestEvent") */
public const ADMIN_ACCESS_HISTORY_LIST_INITIALIZE = 'sfs_user.admin.access_history.list_initialize';
Expand Down
6 changes: 6 additions & 0 deletions translations/sfs_user.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ admin_users:
error: "An error has occurred sending the confirmation email, try it again. If the problem persist contact to support."
already_confirmed: "The email has not been send, user %username% is already confirmed"

resend_invitation:
messages:
success: "The invitation email has been sent to %email%"
error: "An error has occurred sending the invitation email, try it again. If the problem persist contact to support."


admin_administrators:
list:
meta.title: "Administrators"
Expand Down
4 changes: 4 additions & 0 deletions translations/sfs_user.es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ admin_users:
success: "El email de confirmación se ha enviado a %email%"
error: "Se ha producido un error enviando el correo de confirmación, intentalo de nuevo. Si el problema persiste contacta con el soporte."
already_confirmed: "No se ha enviado el email de confirmación, el usuario %username% ya está confirmado"
resend_invitation:
messages:
success: "El email de invitación se ha enviado a %email%"
error: "Se ha producido un error enviando el correo de invitación, intentalo de nuevo. Si el problema persiste contacta con el soporte."

admin_administrators:
list:
Expand Down
Loading