-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Security: send registration confirmation email.
- Loading branch information
Showing
5 changed files
with
44 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Mime\Email; | ||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Uid\UuidV4; | ||
|
@@ -31,7 +33,7 @@ | |
class RegistrationController extends AbstractController | ||
{ | ||
#[Route('/register', name: 'app_register')] | ||
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, VerifyEmailHelperInterface $verifyEmailHelper): Response | ||
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, VerifyEmailHelperInterface $verifyEmailHelper, MailerInterface $mailer): Response | ||
{ | ||
$user = new User(); | ||
$form = $this->createForm(RegistrationFormType::class, $user); | ||
|
@@ -60,13 +62,10 @@ public function register(Request $request, UserPasswordHasherInterface $userPass | |
] | ||
); | ||
|
||
// TEMP: REMOVE LATER | ||
$this->addFlash('success', 'Confirm your email at: ' . $signatureComponent->getSignedUrl()); | ||
$this->sendConfirmationEmail($mailer, $signatureComponent->getSignedUrl(), $user->getEmail()); | ||
$this->addFlash('info', 'Please check your mail and confirm your email address!'); | ||
|
||
// do anything else you need here, like send an email | ||
//TODO SEND VERIFY MAIL | ||
|
||
return $this->redirectToRoute('app_index'); | ||
return $this->redirectToRoute('app_login'); | ||
} | ||
|
||
return $this->render('registration/register.html.twig', [ | ||
|
@@ -105,8 +104,22 @@ public function verifyUserEmail(Request $request, VerifyEmailHelperInterface $ve | |
} | ||
|
||
#[Route('/verify/resend', name: 'app_verify_resend_email')] | ||
public function resendVerifyEmail(): Response | ||
public function resendVerifyEmail(Request $request): Response | ||
{ | ||
//TODO: add form with email field | ||
return $this->render('registration/resend_verify_email.html.twig'); | ||
} | ||
|
||
private function sendConfirmationEmail(MailerInterface $mailer, string $signedUrl, string $userEmail): void | ||
{ | ||
$email = (new Email()) | ||
->from('[email protected]') | ||
->to($userEmail) | ||
->priority(Email::PRIORITY_HIGH) | ||
->subject('Auth oe-modules.com: please confirm your registration') | ||
->text('Confirm your email at: ' . $signedUrl) | ||
->html('<p> Confirm your email at: ' . $signedUrl . '</p>'); | ||
|
||
$mailer->send($email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% if app.request.hasPreviousSession %} | ||
<div class="container col-sm-auto col-6 mt-1 justify-content-center"> | ||
<div class="row"> | ||
{% for type, messages in app.flashes %} | ||
{% for message in messages %} | ||
{# Bootstrap alert, see https://getbootstrap.com/docs/5.3/components/alerts/ #} | ||
<div class="alert alert-dismissible alert-{{ type }} fade show" role="alert"> | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> | ||
|
||
</button> | ||
|
||
{{ message|trans }} | ||
</div> | ||
{% endfor %} | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters