-
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.
- Loading branch information
roadiz-ci
committed
Jun 21, 2024
1 parent
5eb9968
commit 006143a
Showing
41 changed files
with
990 additions
and
760 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 |
---|---|---|
@@ -0,0 1,14 @@ | ||
language: php | ||
php: | ||
- '8.0' | ||
- '8.1' | ||
- 'nightly' | ||
jobs: | ||
allow_failures: | ||
- php: 'nightly' | ||
install: | ||
- composer install --dev --no-scripts --no-suggest | ||
|
||
script: | ||
- vendor/bin/phpcs -p ./src | ||
- vendor/bin/phpstan analyse -c phpstan.neon |
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,117 1,105 @@ | ||
--- | ||
RZ\Roadiz\CoreBundle\Entity\User: | ||
operations: | ||
api_user_signup: | ||
class: ApiPlatform\Metadata\Post | ||
iri: User | ||
shortName: User | ||
attributes: | ||
cache_headers: | ||
public: false | ||
max_age: 0 | ||
collectionOperations: | ||
signup: | ||
method: 'POST' | ||
uriTemplate: '/users/signup' | ||
processor: RZ\Roadiz\UserBundle\State\UserSignupProcessor | ||
path: '/users/signup' | ||
controller: RZ\Roadiz\UserBundle\Controller\SignupController | ||
input: RZ\Roadiz\UserBundle\Api\Dto\UserInput | ||
output: RZ\Roadiz\UserBundle\Api\Dto\VoidOutput | ||
validation_groups: | ||
- no_empty_password | ||
openapiContext: | ||
openapi_context: | ||
summary: Create a new public user | ||
parameters: | ||
- in: header | ||
name: x-g-recaptcha-response | ||
schema: | ||
type: string | ||
required: true | ||
- in: header | ||
name: x-g-recaptcha-response | ||
schema: | ||
type: string | ||
required: true | ||
description: | | ||
Create a new public user. User won't be validated and will not be granted with any role. | ||
This operation may require a *Google Recaptcha* response to protect against flooding. | ||
api_user_password_request: | ||
class: ApiPlatform\Metadata\Post | ||
password_request: | ||
method: 'POST' | ||
uriTemplate: '/users/password_request' | ||
processor: RZ\Roadiz\UserBundle\State\UserPasswordRequestProcessor | ||
path: '/users/password_request' | ||
controller: RZ\Roadiz\UserBundle\Controller\PasswordRequestController | ||
input: RZ\Roadiz\UserBundle\Api\Dto\UserPasswordRequestInput | ||
output: RZ\Roadiz\UserBundle\Api\Dto\VoidOutput | ||
openapiContext: | ||
# Password request must not call WriteListener to let PasswordRequestController persist changes. | ||
write: false | ||
validate: false | ||
openapi_context: | ||
summary: Request a public user new password | ||
parameters: | ||
- in: header | ||
name: x-g-recaptcha-response | ||
schema: | ||
type: string | ||
required: true | ||
- in: header | ||
name: x-g-recaptcha-response | ||
schema: | ||
type: string | ||
required: true | ||
description: | | ||
Initiate a public user new password request (forgot my password). This operation may | ||
require a *Google Recaptcha* response to protect against flooding. | ||
api_user_validation_request: | ||
class: ApiPlatform\Metadata\Post | ||
validation_request: | ||
method: 'POST' | ||
uriTemplate: '/users/validation_request' | ||
processor: RZ\Roadiz\UserBundle\State\UserValidationRequestProcessor | ||
path: '/users/validation_request' | ||
controller: RZ\Roadiz\UserBundle\Controller\ValidationRequestController | ||
input: RZ\Roadiz\UserBundle\Api\Dto\UserValidationRequestInput | ||
output: RZ\Roadiz\UserBundle\Api\Dto\VoidOutput | ||
openapiContext: | ||
# Validation request must not call WriteListener to let ValidationRequestController persist changes. | ||
write: false | ||
validate: false | ||
openapi_context: | ||
summary: Request a public user email validation token | ||
description: | | ||
Initiate a public user validation request (to verify user email address) | ||
api_user_password_reset: | ||
itemOperations: | ||
information: | ||
method: 'GET' | ||
read: false | ||
path: '/users/me' | ||
controller: RZ\Roadiz\UserBundle\Controller\InformationController | ||
output: RZ\Roadiz\UserBundle\Api\Dto\UserOutput | ||
openapi_context: | ||
summary: Get current user (JWT) information | ||
description: | | ||
Get current user (JWT) information | ||
password_reset: | ||
method: 'PUT' | ||
class: ApiPlatform\Metadata\Put | ||
uriTemplate: '/users/password_reset' | ||
processor: RZ\Roadiz\UserBundle\State\UserPasswordResetProcessor | ||
path: '/users/password_reset' | ||
controller: RZ\Roadiz\UserBundle\Controller\PasswordResetController | ||
input: RZ\Roadiz\UserBundle\Api\Dto\UserPasswordTokenInput | ||
output: RZ\Roadiz\UserBundle\Api\Dto\VoidOutput | ||
# Password reset must not call ReadListener to let DataTransformer provide User. | ||
read: false | ||
validate: false | ||
validation_groups: | ||
- no_empty_password | ||
openapiContext: | ||
openapi_context: | ||
summary: Reset a public user password | ||
parameters: ~ | ||
description: | | ||
Change a public user password against a unique temporary token (forgot my password) | ||
api_user_validate: | ||
class: ApiPlatform\Metadata\Put | ||
validate: | ||
method: 'PUT' | ||
uriTemplate: '/users/validate' | ||
processor: RZ\Roadiz\UserBundle\State\UserValidationTokenProcessor | ||
input: RZ\Roadiz\UserBundle\Api\Dto\UserValidationTokenInput | ||
path: '/users/validate' | ||
controller: RZ\Roadiz\UserBundle\Controller\ValidateController | ||
input: RZ\Roadiz\UserBundle\Api\Dto\UserTokenInput | ||
output: RZ\Roadiz\UserBundle\Api\Dto\VoidOutput | ||
read: false | ||
validate: false | ||
openapiContext: | ||
openapi_context: | ||
summary: Validate a public user email | ||
description: | | ||
Validate a public user email with a unique and temporary token | ||
ApiPlatform\Metadata\Get: | ||
method: 'GET' | ||
security: "is_granted('ROLE_ACCESS_USERS') or object == user" | ||
normalizationContext: | ||
groups: ['user', 'user_personal', 'user_security'] | ||
enable_max_depth: true | ||
|
||
ApiPlatform\Metadata\GetCollection: | ||
method: 'GET' | ||
security: "is_granted('ROLE_ACCESS_USERS')" | ||
normalizationContext: | ||
groups: [ 'user', 'user_personal' ] | ||
enable_max_depth: true | ||
|
||
# Current user information operation MUST be declared AFTER ApiPlatform\Metadata\Get | ||
# to avoid conflict with IRI generation. | ||
api_user_information: | ||
method: 'GET' | ||
class: ApiPlatform\Metadata\Get | ||
# Path must be different from item operation to avoid conflict | ||
uriTemplate: '/me' | ||
provider: RZ\Roadiz\UserBundle\State\UserTokenProvider | ||
output: RZ\Roadiz\UserBundle\Api\Dto\UserOutput | ||
normalizationContext: | ||
groups: ['user', 'user_personal', 'user_security'] | ||
enable_max_depth: true | ||
openapiContext: | ||
summary: Get current user (JWT) information | ||
description: | | ||
Get current user (JWT) information |
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\UserBundle\Api\DataTransformer; | ||
|
||
use ApiPlatform\Core\DataTransformer\DataTransformerInterface; | ||
use RZ\Roadiz\CoreBundle\Bag\Roles; | ||
use RZ\Roadiz\CoreBundle\Entity\User; | ||
use RZ\Roadiz\UserBundle\Api\Dto\UserInput; | ||
use RZ\Roadiz\UserBundle\Manager\UserMetadataManagerInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
final class UserInputDataTransformer implements DataTransformerInterface | ||
{ | ||
private UserMetadataManagerInterface $userMetadataManager; | ||
private Roles $rolesBag; | ||
private string $publicUserRoleName; | ||
|
||
public function __construct(UserMetadataManagerInterface $userMetadataManager, Roles $rolesBag, string $publicUserRoleName) | ||
{ | ||
$this->rolesBag = $rolesBag; | ||
$this->publicUserRoleName = $publicUserRoleName; | ||
$this->userMetadataManager = $userMetadataManager; | ||
} | ||
|
||
public function transform($object, string $to, array $context = []): User | ||
{ | ||
if (!$object instanceof UserInput) { | ||
throw new \RuntimeException(sprintf('Cannot transform %s to %s', get_class($object), $to)); | ||
} | ||
|
||
$user = new User(); | ||
$user->setEmail($object->email); | ||
$user->setUsername($object->email); | ||
$user->setFirstName($object->firstName); | ||
$user->setPublicName($object->publicName); | ||
$user->setLastName($object->lastName); | ||
$user->setPhone($object->phone); | ||
$user->setCompany($object->company); | ||
$user->setJob($object->job); | ||
$user->setBirthday($object->birthday); | ||
$user->setPlainPassword($object->plainPassword); | ||
$user->addRoleEntity($this->rolesBag->get($this->publicUserRoleName)); | ||
$user->sendCreationConfirmationEmail(true); | ||
|
||
if (null !== $object->metadata) { | ||
$userMetadata = $this->userMetadataManager->createMetadataForUser($user); | ||
$userMetadata->setMetadata($object->metadata); | ||
} | ||
|
||
return $user; | ||
} | ||
|
||
public function supportsTransformation($data, string $to, array $context = []): bool | ||
{ | ||
if ($data instanceof UserInterface) { | ||
return false; | ||
} | ||
|
||
return User::class === $to && UserInput::class === ($context['input']['class'] ?? null); | ||
} | ||
} |
Oops, something went wrong.