-
Notifications
You must be signed in to change notification settings - Fork 28
/
UserRegisterController.php
78 lines (68 loc) · 2.66 KB
/
UserRegisterController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\RepositoryFormsBundle\Controller;
use eZ\Bundle\EzPublishCoreBundle\Controller;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
use EzSystems\RepositoryForms\Data\Mapper\UserRegisterMapper;
use EzSystems\RepositoryForms\Form\ActionDispatcher\ActionDispatcherInterface;
use EzSystems\RepositoryForms\Form\Type\User\UserRegisterType;
use EzSystems\RepositoryForms\UserRegister\View\UserRegisterConfirmView;
use EzSystems\RepositoryForms\UserRegister\View\UserRegisterFormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
class UserRegisterController extends Controller
{
/**
* @var UserRegisterMapper
*/
private $userRegisterMapper;
/**
* @var ActionDispatcherInterface
*/
private $contentActionDispatcher;
public function __construct(
UserRegisterMapper $userRegisterMapper,
ActionDispatcherInterface $contentActionDispatcher
) {
$this->userRegisterMapper = $userRegisterMapper;
$this->contentActionDispatcher = $contentActionDispatcher;
}
/**
* Displays and processes a user registration form.
*
* @param Request $request
*
* @return \EzSystems\RepositoryForms\UserRegister\View\UserRegisterFormView|\Symfony\Component\HttpFoundation\Response * @throws \Exception if the current user isn't allowed to register an account
*/
public function registerAction(Request $request)
{
if (!$this->isGranted(new Attribute('user', 'register'))) {
throw new UnauthorizedHttpException('You are not allowed to register a new account');
}
$data = $this->userRegisterMapper->mapToFormData();
$language = $data->mainLanguageCode;
$form = $this->createForm(
UserRegisterType::class,
$data,
['languageCode' => $language]
);
$form->handleRequest($request);
if ($form->isValid()) {
$this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName());
if ($response = $this->contentActionDispatcher->getResponse()) {
return $response;
}
}
return new UserRegisterFormView(null, ['form' => $form->createView()]);
}
public function registerConfirmAction()
{
return new UserRegisterConfirmView();
}
}