Commit 617a9f37 authored by Dominique Merle's avatar Dominique Merle 💬
Browse files

Implement basic registration.

Not very robust, but it passes the tests.
parent a12e6607
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "c3a5a6dd3b6d04fdb6fe602cd50be684",
"content-hash": "8b0b87b053c743ead503b74f63298f08",
"packages": [
{
"name": "api-platform/api-pack",
......@@ -3254,6 +3254,90 @@
"description": "Composer plugin for Symfony",
"time": "2019-09-19T14:55:57+00:00"
},
{
"name": "symfony/form",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/form.git",
"reference": "eba11fd575e791d72030cb59215a9948791f1e74"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/form/zipball/eba11fd575e791d72030cb59215a9948791f1e74",
"reference": "eba11fd575e791d72030cb59215a9948791f1e74",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/event-dispatcher": "^4.3",
"symfony/intl": "^4.3",
"symfony/options-resolver": "~4.3",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/property-access": "~3.4|~4.0",
"symfony/service-contracts": "~1.1"
},
"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/console": "<4.3",
"symfony/dependency-injection": "<3.4",
"symfony/doctrine-bridge": "<3.4",
"symfony/framework-bundle": "<3.4",
"symfony/http-kernel": "<4.3",
"symfony/intl": "<4.3",
"symfony/translation": "<4.2",
"symfony/twig-bridge": "<3.4.5|<4.0.5,>=4.0"
},
"require-dev": {
"doctrine/collections": "~1.0",
"symfony/config": "~3.4|~4.0",
"symfony/console": "^4.3",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/http-foundation": "~3.4|~4.0",
"symfony/http-kernel": "~4.3",
"symfony/security-csrf": "~3.4|~4.0",
"symfony/translation": "~4.2",
"symfony/validator": "^3.4.31|^4.3.4",
"symfony/var-dumper": "^4.3"
},
"suggest": {
"symfony/security-csrf": "For protecting forms against CSRF attacks.",
"symfony/twig-bridge": "For templating with Twig.",
"symfony/validator": "For form validation."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Form\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Form Component",
"homepage": "https://symfony.com",
"time": "2019-08-26T08:55:16+00:00"
},
{
"name": "symfony/framework-bundle",
"version": "v4.3.4",
......@@ -3582,6 +3666,81 @@
],
"time": "2019-08-06T18:44:23+00:00"
},
{
"name": "symfony/intl",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/intl.git",
"reference": "8db5505703c5bdb23d524fd994dad2f781966538"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/intl/zipball/8db5505703c5bdb23d524fd994dad2f781966538",
"reference": "8db5505703c5bdb23d524fd994dad2f781966538",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/polyfill-intl-icu": "~1.0"
},
"require-dev": {
"symfony/filesystem": "~3.4|~4.0"
},
"suggest": {
"ext-intl": "to use the component with locales other than \"en\""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Intl\\": ""
},
"classmap": [
"Resources/stubs"
],
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
},
{
"name": "Eriksen Costa",
"email": "eriksen.costa@infranology.com.br"
},
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A PHP replacement layer for the C intl extension that includes additional data from the ICU library.",
"homepage": "https://symfony.com",
"keywords": [
"i18n",
"icu",
"internationalization",
"intl",
"l10n",
"localization"
],
"time": "2019-08-26T08:26:39+00:00"
},
{
"name": "symfony/messenger",
"version": "v4.3.4",
......@@ -3715,6 +3874,118 @@
],
"time": "2019-08-22T08:16:11+00:00"
},
{
"name": "symfony/options-resolver",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "81c2e120522a42f623233968244baebd6b36cb6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/81c2e120522a42f623233968244baebd6b36cb6a",
"reference": "81c2e120522a42f623233968244baebd6b36cb6a",
"shasum": ""
},
"require": {
"php": "^7.1.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\OptionsResolver\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony OptionsResolver Component",
"homepage": "https://symfony.com",
"keywords": [
"config",
"configuration",
"options"
],
"time": "2019-08-08T09:29:19+00:00"
},
{
"name": "symfony/polyfill-intl-icu",
"version": "v1.12.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-icu.git",
"reference": "66810b9d6eb4af54d543867909d65ab9af654d7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/66810b9d6eb4af54d543867909d65ab9af654d7e",
"reference": "66810b9d6eb4af54d543867909d65ab9af654d7e",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"symfony/intl": "~2.3|~3.0|~4.0|~5.0"
},
"suggest": {
"ext-intl": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.12-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's ICU-related data and classes",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"icu",
"intl",
"polyfill",
"portable",
"shim"
],
"time": "2019-08-06T08:03:45+00:00"
},
{
"name": "symfony/polyfill-intl-idn",
"version": "v1.12.0",
......@@ -3949,55 +4220,6 @@
],
"time": "2019-08-06T08:03:45+00:00"
},
{
"name": "symfony/process",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "e89969c00d762349f078db1128506f7f3dcc0d4a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/e89969c00d762349f078db1128506f7f3dcc0d4a",
"reference": "e89969c00d762349f078db1128506f7f3dcc0d4a",
"shasum": ""
},
"require": {
"php": "^7.1.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Process\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2019-08-26T08:26:39+00:00"
},
{
"name": "symfony/property-access",
"version": "v4.3.4",
......@@ -5206,65 +5428,6 @@
],
"time": "2019-08-08T09:29:19+00:00"
},
{
"name": "symfony/web-server-bundle",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/web-server-bundle.git",
"reference": "dc26b980900ddf3e9feade14e5b21c029e8ca92f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/web-server-bundle/zipball/dc26b980900ddf3e9feade14e5b21c029e8ca92f",
"reference": "dc26b980900ddf3e9feade14e5b21c029e8ca92f",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/config": "~3.4|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/process": "^3.4.2|^4.0.2"
},
"suggest": {
"symfony/expression-language": "For using the filter option of the log server.",
"symfony/monolog-bridge": "For using the log server."
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Bundle\\WebServerBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony WebServerBundle",
"homepage": "https://symfony.com",
"time": "2019-08-20T14:27:59+00:00"
},
{
"name": "symfony/yaml",
"version": "v4.3.4",
......@@ -8131,17 +8294,17 @@
"time": "2019-06-20T12:18:19+00:00"
},
{
"name": "symfony/options-resolver",
"name": "symfony/process",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "81c2e120522a42f623233968244baebd6b36cb6a"
"url": "https://github.com/symfony/process.git",
"reference": "e89969c00d762349f078db1128506f7f3dcc0d4a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/81c2e120522a42f623233968244baebd6b36cb6a",
"reference": "81c2e120522a42f623233968244baebd6b36cb6a",
"url": "https://api.github.com/repos/symfony/process/zipball/e89969c00d762349f078db1128506f7f3dcc0d4a",
"reference": "e89969c00d762349f078db1128506f7f3dcc0d4a",
"shasum": ""
},
"require": {
......@@ -8155,7 +8318,7 @@
},
"autoload": {
"psr-4": {
"Symfony\\Component\\OptionsResolver\\": ""
"Symfony\\Component\\Process\\": ""
},
"exclude-from-classmap": [
"/Tests/"
......@@ -8175,14 +8338,9 @@
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony OptionsResolver Component",
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"keywords": [
"config",
"configuration",
"options"
],
"time": "2019-08-08T09:29:19+00:00"
"time": "2019-08-26T08:26:39+00:00"
},
{
"name": "symfony/translation",
......@@ -8336,6 +8494,65 @@
],
"time": "2019-08-26T08:26:39+00:00"
},
{
"name": "symfony/web-server-bundle",
"version": "v4.3.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/web-server-bundle.git",
"reference": "dc26b980900ddf3e9feade14e5b21c029e8ca92f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/web-server-bundle/zipball/dc26b980900ddf3e9feade14e5b21c029e8ca92f",
"reference": "dc26b980900ddf3e9feade14e5b21c029e8ca92f",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/config": "~3.4|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/process": "^3.4.2|^4.0.2"
},
"suggest": {
"symfony/expression-language": "For using the filter option of the log server.",
"symfony/monolog-bridge": "For using the log server."
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Bundle\\WebServerBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony WebServerBundle",
"homepage": "https://symfony.com",
"time": "2019-08-20T14:27:59+00:00"
},
{
"name": "theseer/tokenizer",
"version": "1.1.3",
......
......@@ -22,6 +22,11 @@ security:
pattern: ^/api/docs?(?:[.](?:html|xml|json|ya?ml))?$
security: false
api_registration:
pattern: ^/api/users$
methods: [POST]
security: false
main:
# anonymous: true
pattern: ^/api
......
......@@ -11,16 +11,16 @@ class ApiRestFeatureContext extends BaseFeatureContext
{
/**
* @When /^(?P<actor>.+?)(?P<try> *essa[iy]ez? de)? créer? un compte utilisateur avec le courriel "(.*)" et le mot de passe "(.*)"$/ui
* @When /^(?P<actor>.+?)(?P<try> (?:essa[iy]ez?|tente) de|) créer? un compte utilisateur avec le courriel "(?P<email>.*)" et le mot de passe "(?P<password>.*)"$/ui
*/
public function actorRegistersWithEmailAndPassword($actor, $email, $password)
public function actorRegistersWithEmailAndPassword($actor, $try, $email, $password)
{
$this->actor($actor, true)->api(
'POST',"/users",
'POST',"/users", null,
[
'username' => $email,
'password' => $password,
], [], !empty($try)
'email' => $email,
'password' => ['plain' => $password], // weird, eh?
], !empty($try)
);
}
......
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Form\RegistrationType;
use Doctrine\ORM\EntityManagerInterface;
use MsgPhp\User\Command\CreateUser;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/api/users", name="api_register", methods={"POST"})
*/
final class RegistrationController
{
public function __invoke(
Request $request,
FormFactoryInterface $formFactory,
MessageBusInterface $bus,
EntityManagerInterface $em
): Response {
$data = [];
// if (\is_string($token = $request->query->get('token')) && null !== $invitation = $em->find(UserInvitation::class, $token)) {
// $data['email'] = $invitation->getEmail();
// }
$form = $formFactory->createNamed('', RegistrationType::class, $data, ['csrf_protection' => false]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
// $data['invitation_token'] = $token;
$bus->dispatch(new CreateUser($data));
return new JsonResponse([
'message' => "api.registration.success",
'data' => $data, // maybe instead output the user, with id?
], Response::HTTP_OK);
}
$error = "api.registration.failure.message";
if ( ! $form->isSubmitted()) {
$error .= "\n- "."api.registration.failure.missing_post_vars";