-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
46 changed files
with
377 additions
and
77 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
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,2 @@ | ||
imports: | ||
- { resource: "../../src/Monofony/Pack/FixturesPack/Recipe/config/packages/monofony_fixtures.yaml" } |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/Monofony/Bundle/CoreBundle/Recipe/src/Validator/Constraints/UniqueAppUserEmail.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,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of mz_067_s_ccpa_thermotool. | ||
* | ||
* (c) Mobizel | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
final class UniqueAppUserEmail extends Constraint | ||
{ | ||
/** @var string */ | ||
public $message = 'sylius.user.email.unique'; | ||
} |
51 changes: 51 additions & 0 deletions
51
...nofony/Bundle/CoreBundle/Recipe/src/Validator/Constraints/UniqueAppUserEmailValidator.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,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validator\Constraints; | ||
|
||
use Sylius\Component\User\Canonicalizer\CanonicalizerInterface; | ||
use Sylius\Component\User\Repository\UserRepositoryInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class UniqueAppUserEmailValidator extends ConstraintValidator | ||
{ | ||
private $canonicalizer; | ||
private $appUserRepository; | ||
|
||
public function __construct(CanonicalizerInterface $canonicalizer, UserRepositoryInterface $appUserRepository) | ||
{ | ||
$this->canonicalizer = $canonicalizer; | ||
$this->appUserRepository = $appUserRepository; | ||
} | ||
|
||
public function validate($value, Constraint $constraint): void | ||
{ | ||
if (null === $value) { | ||
return; | ||
} | ||
|
||
/* @var UniqueAppUserEmail $constraint */ | ||
Assert::isInstanceOf($constraint, UniqueAppUserEmail::class); | ||
|
||
$emailCanonical = $this->canonicalizer->canonicalize($value); | ||
$shopUser = $this->appUserRepository->findOneByEmail($emailCanonical); | ||
|
||
if (null === $shopUser) { | ||
return; | ||
} | ||
|
||
$this->context->addViolation($constraint->message); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/Monofony/Bundle/CoreBundle/Recipe/translations/validators.en.yaml
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,4 @@ | ||
sylius: | ||
user: | ||
email: | ||
unique: This email is already used. |
4 changes: 4 additions & 0 deletions
4
src/Monofony/Bundle/CoreBundle/Recipe/translations/validators.fr.yaml
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,4 @@ | ||
sylius: | ||
user: | ||
email: | ||
unique: Cet e-mail est déjà utilisé. |
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
src/Monofony/Pack/ApiPack/Recipe/config/api_platform/resources/register_app_user.yaml
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,12 @@ | ||
App\Message\RegisterAppUser: | ||
attributes: | ||
messenger: true | ||
output: false | ||
validation_groups: ["Default", "sylius"] | ||
itemOperations: [] | ||
collectionOperations: | ||
post: | ||
path: /register | ||
openapi_context: | ||
summary: Registers an app user | ||
validation_groups: ["Default", "sylius"] |
File renamed without changes.
77 changes: 77 additions & 0 deletions
77
src/Monofony/Pack/ApiPack/Recipe/src/Message/RegisterAppUser.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,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of mz_067_s_ccpa_thermotool. | ||
* | ||
* (c) Mobizel | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Message; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
use App\Validator\Constraints as CustomConstraints; | ||
|
||
final class RegisterAppUser | ||
{ | ||
/** | ||
* @var string | ||
* | ||
* @Assert\NotBlank(message="sylius.customer.first_name.not_blank") | ||
*/ | ||
public $firstName; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @Assert\NotBlank(message="sylius.customer.last_name.not_blank") | ||
*/ | ||
public $lastName; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @Assert\NotBlank(message="sylius.customer.email.not_blank") | ||
* @Assert\Email(mode="strict", message="sylius.customer.email.invalid") | ||
* @Assert\Length( | ||
* max=254, | ||
* maxMessage="sylius.customer.email.max" | ||
* ) | ||
* @CustomConstraints\UniqueAppUserEmail() | ||
*/ | ||
public $email; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @Assert\NotBlank(message="sylius.user.plainPassword.not_blank") | ||
* @Assert\Length( | ||
* min=4, | ||
* minMessage="sylius.user.password.min", | ||
* max=254, | ||
* maxMessage="sylius.user.password.max" | ||
* ) | ||
*/ | ||
public $password; | ||
|
||
/** @var string|null */ | ||
public $phoneNumber; | ||
|
||
public function __construct( | ||
string $firstName, | ||
string $lastName, | ||
string $email, | ||
string $password, | ||
?string $phoneNumber = null | ||
) { | ||
$this->firstName = $firstName; | ||
$this->lastName = $lastName; | ||
$this->email = $email; | ||
$this->password = $password; | ||
$this->phoneNumber = $phoneNumber; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Monofony/Pack/ApiPack/Recipe/src/MessageHandler/RegisterAppUserHandler.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,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of mz_067_s_ccpa_thermotool. | ||
* | ||
* (c) Mobizel | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\MessageHandler; | ||
|
||
use App\Message\RegisterAppUser; | ||
use App\Provider\CustomerProviderInterface; | ||
use Monofony\Component\Core\Model\User\AppUserInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | ||
|
||
final class RegisterAppUserHandler implements MessageHandlerInterface | ||
{ | ||
private $appUserFactory; | ||
private $appUserRepository; | ||
private $customerProvider; | ||
|
||
public function __construct( | ||
FactoryInterface $appUserFactory, | ||
RepositoryInterface $appUserRepository, | ||
CustomerProviderInterface $customerProvider | ||
) { | ||
$this->appUserFactory = $appUserFactory; | ||
$this->appUserRepository = $appUserRepository; | ||
$this->customerProvider = $customerProvider; | ||
} | ||
|
||
public function __invoke(RegisterAppUser $command): void | ||
{ | ||
/** @var AppUserInterface $user */ | ||
$user = $this->appUserFactory->createNew(); | ||
$user->setPlainPassword($command->password); | ||
|
||
$customer = $this->customerProvider->provide($command->email); | ||
if ($customer->getUser() !== null) { | ||
throw new \DomainException(sprintf('User with email "%s" is already registered.', $command->email)); | ||
} | ||
|
||
$customer->setFirstName($command->firstName); | ||
$customer->setLastName($command->lastName); | ||
$customer->setPhoneNumber($command->phoneNumber); | ||
$customer->setUser($user); | ||
|
||
$this->appUserRepository->add($user); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.