AttributeSupportController::sendMailAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2015 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\Form\Type\AttributeSupportMailType;
22
use OpenConext\ProfileBundle\Security\Guard;
23
use OpenConext\ProfileBundle\Service\AttributeSupportMailService;
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 AttributeSupportController
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 AttributeSupportMailService
60
     */
61
    private $attributeSupportMailService;
62
63
    public function __construct(
64
        Guard $guard,
65
        EngineInterface $templateEngine,
66
        FormFactoryInterface $formFactory,
67
        UrlGeneratorInterface $urlGenerator,
68
        UserService $userService,
69
        AttributeSupportMailService $attributeSupportMailService
70
    ) {
71
        $this->guard                       = $guard;
72
        $this->templateEngine              = $templateEngine;
73
        $this->formFactory                 = $formFactory;
74
        $this->urlGenerator                = $urlGenerator;
75
        $this->userService                 = $userService;
76
        $this->attributeSupportMailService = $attributeSupportMailService;
77
    }
78
79
    public function overviewAction()
80
    {
81
        $this->guard->userIsLoggedIn();
82
83
        $attributeSupportMailForm = $this->formFactory->create(
84
            AttributeSupportMailType::class,
85
            null,
86
            ['action' => $this->urlGenerator->generate('profile.attribute_support_send_mail')]
87
        );
88
89
        return new Response(
90
            $this->templateEngine->render(
91
                'OpenConextProfileBundle:AttributeSupport:overview.html.twig',
92
                [
93
                    'attributes'               => $this->userService->getUser()->getAttributes(),
94
                    'attributeSupportMailForm' => $attributeSupportMailForm->createView()
95
                ]
96
            )
97
        );
98
    }
99
100
    public function sendMailAction()
101
    {
102
        $this->guard->userIsLoggedIn();
103
104
        $this->attributeSupportMailService->sendAttributeSupportMail();
105
106
        return new RedirectResponse($this->urlGenerator->generate('profile.attribute_support_confirm_mail_sent'));
107
    }
108
109
    public function confirmMailSentAction()
110
    {
111
        $this->guard->userIsLoggedIn();
112
113
        return new Response(
114
            $this->templateEngine->render('OpenConextProfileBundle:AttributeSupport:confirmation.html.twig')
115
        );
116
    }
117
}
118