Completed
Pull Request — develop (#79)
by
unknown
01:48
created

confirmMailSentAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\Controller;
20
21
use OpenConext\ProfileBundle\Attribute\AttributeFilter;
22
use OpenConext\ProfileBundle\Security\Guard;
23
use OpenConext\ProfileBundle\Service\InformationRequestMailService;
24
use OpenConext\ProfileBundle\Service\UserService;
25
use Symfony\Component\Form\FormFactoryInterface;
26
use Symfony\Component\HttpFoundation\RedirectResponse;
27
use Symfony\Component\HttpFoundation\Response;
28
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
29
use Symfony\Component\Templating\EngineInterface;
30
31
class InformationRequestController
32
{
33
    /**
34
     * @var Guard
35
     */
36
    private $guard;
37
38
    /**
39
     * @var EngineInterface
40
     */
41
    private $templateEngine;
42
43
    /**
44
     * @var FormFactoryInterface
45
     */
46
    private $formFactory;
47
48
    /**
49
     * @var UrlGeneratorInterface
50
     */
51
    private $urlGenerator;
52
53
    /**
54
     * @var UserService
55
     */
56
    private $userService;
57
58
    /**
59
     * @var InformationRequestMailService
60
     */
61
    private $informationRequestMailService;
62
63
    /**
64
     * @var AttributeFilter
65
     */
66
    private $attributeFilter;
67
68
    public function __construct(
69
        Guard $guard,
70
        EngineInterface $templateEngine,
71
        FormFactoryInterface $formFactory,
72
        UrlGeneratorInterface $urlGenerator,
73
        UserService $userService,
74
        AttributeFilter $attributeFilter,
75
        InformationRequestMailService $informationRequestMailService
76
    ) {
77
        $this->guard = $guard;
78
        $this->templateEngine = $templateEngine;
79
        $this->formFactory = $formFactory;
80
        $this->urlGenerator = $urlGenerator;
81
        $this->userService = $userService;
82
        $this->attributeFilter = $attributeFilter;
83
        $this->informationRequestMailService = $informationRequestMailService;
84
    }
85
86
    public function overviewAction()
87
    {
88
        $this->guard->userIsLoggedIn();
89
90
        $informationRequestMailForm = $this->formFactory->create(
91
            'profile_information_request_mail',
92
            null,
93
            ['action' => $this->urlGenerator->generate('profile.information_request_send_mail')]
94
        );
95
96
        $attributes = $this->attributeFilter->filter($this->userService->getUser()->getAttributes());
97
98
        return new Response(
99
            $this->templateEngine->render(
100
                'OpenConextProfileBundle:InformationRequest:overview.html.twig',
101
                [
102
                    'attributes' => $attributes,
103
                    'informationRequestMailForm' => $informationRequestMailForm->createView()
104
                ]
105
            )
106
        );
107
    }
108
109
    public function sendMailAction()
110
    {
111
        $this->guard->userIsLoggedIn();
112
113
        $this->informationRequestMailService->sendInformationRequestMail();
114
115
        return new RedirectResponse($this->urlGenerator->generate('profile.information_request_confirm_mail_sent'));
116
    }
117
118
    public function confirmMailSentAction()
119
    {
120
        $this->guard->userIsLoggedIn();
121
122
        return new Response(
123
            $this->templateEngine->render('OpenConextProfileBundle:InformationRequest:confirmation.html.twig')
124
        );
125
    }
126
}
127