-
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): Extract common logic between UserInput and Password…
…lessUserInput
- Loading branch information
1 parent
c86889d
commit bd11480
Showing
11 changed files
with
137 additions
and
80 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
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
# see api_resources/user.yaml for API Platform auto routing | ||
# | ||
# Use Passwordless users with login link | ||
# | ||
#public_login_link_check: | ||
# path: /api/users/login_link_check | ||
# methods: [POST] |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\UserBundle\Api\Dto; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
abstract class AbstractUserInput | ||
{ | ||
#[Assert\Email] | ||
#[Assert\NotNull] | ||
public string $email = ''; | ||
public ?string $firstName = null; | ||
public ?string $lastName = null; | ||
public ?string $publicName = null; | ||
public ?string $phone = null; | ||
public ?string $company = null; | ||
public ?string $job = null; | ||
public ?\DateTime $birthday = null; | ||
public ?array $metadata = null; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\UserBundle\State; | ||
|
||
use RZ\Roadiz\CoreBundle\Entity\User; | ||
use RZ\Roadiz\UserBundle\Api\Dto\AbstractUserInput; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; | ||
use Symfony\Component\RateLimiter\RateLimiterFactory; | ||
|
||
trait SignupProcessorTrait | ||
{ | ||
abstract protected function getSecurity(): Security; | ||
abstract protected function getUserSignupLimiter(): RateLimiterFactory; | ||
|
||
protected function validateRequest(?Request $request): void | ||
{ | ||
if ($this->getSecurity()->isGranted('ROLE_USER')) { | ||
throw new AccessDeniedHttpException('Cannot sign-up: you\'re already authenticated.'); | ||
} | ||
|
||
if (null !== $request) { | ||
$limiter = $this->getUserSignupLimiter()->create($request->getClientIp()); | ||
$limit = $limiter->consume(); | ||
if (false === $limit->isAccepted()) { | ||
throw new TooManyRequestsHttpException($limit->getRetryAfter()->getTimestamp()); | ||
} | ||
} | ||
} | ||
|
||
protected function createUser(AbstractUserInput $data): User | ||
{ | ||
$user = new User(); | ||
$user->setEmail($data->email); | ||
$user->setUsername($data->email); | ||
$user->setFirstName($data->firstName); | ||
$user->setLastName($data->lastName); | ||
$user->setPublicName($data->publicName); | ||
$user->setPhone($data->phone); | ||
$user->setCompany($data->company); | ||
$user->setJob($data->job); | ||
$user->setBirthday($data->birthday); | ||
|
||
return $user; | ||
} | ||
} |
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