Completed
Push — develop ( a368ca...435c97 )
by
unknown
07:19 queued 04:10
created

MySurfConextController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 82
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A overviewAction() 0 16 1
A userDataDownloadAction() 0 18 2
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\Security\Guard;
22
use OpenConext\ProfileBundle\Service\UserService;
23
use Psr\Log\LoggerInterface;
24
use Symfony\Component\HttpFoundation\JsonResponse;
25
use Symfony\Component\HttpFoundation\Response;
26
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
27
use Symfony\Component\Templating\EngineInterface;
28
29
class MySurfConextController
30
{
31
    /**
32
     * @var UserService
33
     */
34
    private $userService;
35
36
    /**
37
     * @var EngineInterface
38
     */
39
    private $templateEngine;
40
41
    /**
42
     * @var Guard
43
     */
44
    private $guard;
45
46
    /**
47
     * @var LoggerInterface
48
     */
49
    private $logger;
50
51
    /**
52
     * @param UserService $userService
53
     * @param EngineInterface $templateEngine
54
     * @param Guard $guard
55
     * @param LoggerInterface $logger
56
     */
57
    public function __construct(
58
        UserService $userService,
59
        EngineInterface $templateEngine,
60
        Guard $guard,
61
        LoggerInterface $logger
62
    ) {
63
        $this->userService    = $userService;
64
        $this->templateEngine = $templateEngine;
65
        $this->guard          = $guard;
66
        $this->logger         = $logger;
67
    }
68
69
    /**
70
     * @return Response
71
     */
72
    public function overviewAction()
73
    {
74
        $this->guard->userIsLoggedIn();
75
76
        $this->logger->notice('Showing My SURFconext page');
77
78
        $user = $this->userService->getUser();
79
80
        return new Response($this->templateEngine->render(
81
            'OpenConextProfileBundle:MySurfConext:overview.html.twig',
82
            [
83
                'user' => $user,
84
                'userLifecycleIsEnabled' => $this->userService->userLifecycleApiIsEnabled(),
85
            ]
86
        ));
87
    }
88
89
    /**
90
     * @return Response
91
     */
92
    public function userDataDownloadAction()
93
    {
94
        $this->guard->userIsLoggedIn();
95
96
        if (!$this->userService->userLifecycleApiIsEnabled()) {
97
            throw new ResourceNotFoundException('User lifecycle API is disabled');
98
        }
99
100
        $this->logger->notice('Exporting user data from user lifecycle API');
101
102
        return new JsonResponse(
103
            $this->userService->getUserLifecycleData(),
104
            200,
105
            [
106
                'Content-Disposition' => 'attachment; filename="profile-user-data.json"'
107
            ]
108
        );
109
    }
110
}
111