-
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.
feat(UserBundle): Added password-less public user creation and login …
…link
- Loading branch information
1 parent
fbe532f
commit c86889d
Showing
30 changed files
with
533 additions
and
102 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
bruno/Roadiz development app/api/users/Check a public login-link.bru
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,30 @@ | ||
meta { | ||
name: Check a public login-link | ||
type: http | ||
seq: 10 | ||
} | ||
|
||
post { | ||
url: {{baseUrl}}/api/users/login_link_check | ||
body: formUrlEncoded | ||
auth: none | ||
} | ||
|
||
params:query { | ||
_locale: fr | ||
} | ||
|
||
headers { | ||
x-g-recaptcha-response: test | ||
} | ||
|
||
body:form-urlencoded { | ||
user: [email protected] | ||
expires: 1726163298 | ||
hash: 63c1K5rt7Bswx5jCE-HpP3RI5Y843dgRtcCNiXrWrQ~PFGtvAdPfe7dCJ9ic6QyiGmN5sDG9nPnYZpqEykAmpQ~ | ||
} | ||
|
||
script:post-response { | ||
const data = res.getBody(); | ||
bru.setEnvVar("access_token", data.token); | ||
} |
35 changes: 35 additions & 0 deletions
35
bruno/Roadiz development app/api/users/Create a new public passwordless user.bru
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,35 @@ | ||
meta { | ||
name: Create a new public passwordless user | ||
type: http | ||
seq: 9 | ||
} | ||
|
||
post { | ||
url: {{baseUrl}}/api/users/signup?_locale=fr | ||
body: json | ||
auth: none | ||
} | ||
|
||
params:query { | ||
_locale: fr | ||
} | ||
|
||
headers { | ||
x-g-recaptcha-response: test | ||
} | ||
|
||
body:json { | ||
{ | ||
"email": "[email protected]", | ||
"firstName": "Ambroise", | ||
"lastName": "Maupate", | ||
"company": "Rezo Zero", | ||
"metadata": { | ||
"press": { | ||
"press": true, | ||
"educational": false | ||
}, | ||
"educational": false | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...t current user -JWT- information Copy.bru → ...sers/Get current user JWT information.bru
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
meta { | ||
name: Get current user -JWT- information Copy | ||
name: Get current user JWT information | ||
type: http | ||
seq: 3 | ||
} | ||
|
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
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
68 changes: 68 additions & 0 deletions
68
lib/RoadizCoreBundle/src/Security/LoginLink/EmailLoginLinkSender.php
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Security\LoginLink; | ||
|
||
use RZ\Roadiz\CoreBundle\Bag\Settings; | ||
use RZ\Roadiz\CoreBundle\Entity\User; | ||
use RZ\Roadiz\CoreBundle\Mailer\EmailManagerFactory; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Http\LoginLink\LoginLinkDetails; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
final readonly class EmailLoginLinkSender implements LoginLinkSenderInterface | ||
{ | ||
public function __construct( | ||
private Settings $settingsBag, | ||
private EmailManagerFactory $emailManagerFactory, | ||
private TranslatorInterface $translator, | ||
private string $htmlTemplate = '@RoadizCore/email/users/login_link_email.html.twig', | ||
private string $txtTemplate = '@RoadizCore/email/users/login_link_email.txt.twig' | ||
) { | ||
} | ||
|
||
public function sendLoginLink(UserInterface $user, LoginLinkDetails $loginLinkDetails,): void | ||
{ | ||
if ($user instanceof User && !$user->isEnabled()) { | ||
throw new \InvalidArgumentException('User must be enabled to send a login link.'); | ||
} | ||
|
||
if (!\method_exists($user, 'getEmail')) { | ||
throw new \InvalidArgumentException('User implementation must have getEmail method.'); | ||
} | ||
|
||
if (null === $user->getEmail()) { | ||
throw new \InvalidArgumentException('User must have an email to send a login link.'); | ||
} | ||
|
||
$emailManager = $this->emailManagerFactory->create(); | ||
$emailContact = $this->settingsBag->get('email_sender', null); | ||
if (!\is_string($emailContact)) { | ||
throw new \InvalidArgumentException('Email sender must be a string.'); | ||
} | ||
$siteName = $this->settingsBag->get('site_name', null); | ||
if (!\is_string($siteName)) { | ||
throw new \InvalidArgumentException('Site name must be a string.'); | ||
} | ||
|
||
$emailManager->setAssignation([ | ||
'loginLink' => $loginLinkDetails->getUrl(), | ||
'expiresAt' => $loginLinkDetails->getExpiresAt(), | ||
'user' => $user, | ||
'site' => $siteName, | ||
'mailContact' => $emailContact, | ||
]); | ||
$emailManager->setEmailTemplate($this->htmlTemplate); | ||
$emailManager->setEmailPlainTextTemplate($this->txtTemplate); | ||
$emailManager->setSubject($this->translator->trans( | ||
'login_link.request' | ||
)); | ||
|
||
$emailManager->setReceiver($user->getEmail()); | ||
$emailManager->setSender([$emailContact => $siteName]); | ||
|
||
// Send the message | ||
$emailManager->send(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
lib/RoadizCoreBundle/src/Security/LoginLink/LoginLinkSenderInterface.php
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Security\LoginLink; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Http\LoginLink\LoginLinkDetails; | ||
|
||
interface LoginLinkSenderInterface | ||
{ | ||
public function sendLoginLink( | ||
UserInterface $user, | ||
LoginLinkDetails $loginLinkDetails, | ||
): void; | ||
} |
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
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
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
Oops, something went wrong.