Test Failed
Push — development ( d53c15...2aa3a7 )
by Philippe
09:58
created

AccountController::injectHubicService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/*
3
 * This program is free software: you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 */
16
namespace Filoucrackeur\Hubic\Controller\Backend;
17
18
use Filoucrackeur\Hubic\Domain\Model\Account;
19
use Filoucrackeur\Hubic\Domain\Repository\AccountRepository;
20
use Filoucrackeur\Hubic\Service\HubicService;
21
use TYPO3\CMS\Core\Messaging\AbstractMessage;
22
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
23
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
24
25
/**
26
 * Class AccountController
27
 */
28
class AccountController extends ActionController
29
{
30
    /**
31
     * @var \Filoucrackeur\Hubic\Domain\Repository\AccountRepository
32
     */
33
    protected $accountRepository;
34
35
    /**
36
     * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
37
     */
38
    protected $persistenceManager;
39
40
    /**
41
     * @var \Filoucrackeur\Hubic\Service\HubicService
42
     */
43
    protected $hubicService;
44
45
    public function indexAction(): void
46
    {
47
        $accounts = $this->accountRepository->findAll();
48
        $this->view->assign('accounts', $accounts);
49
    }
50
51
    /**
52
     * @param Account $account
53
     */
54
    public function showAction(Account $account): void
55
    {
56
        if ($account->getAccessToken()) {
57
            $this->hubicService->setAccount($account);
58
            $clientAccountQuota = $this->hubicService->getAccountQuota();
59
            $clientAccount = $this->hubicService->getAccount();
60
            $agreement = $this->hubicService->getAgreement();
61
            $links = $this->hubicService->getAllLinks();
62
            $this->view->assignMultiple([
63
                'clientAccount' => $clientAccount,
64
                'clientAccountQuota' => $clientAccountQuota,
65
                'agreement' => $agreement,
66
                'links' => $links
67
            ]);
68
        }
69
70
        $this->view->assign('account', $account);
71
    }
72
73
    /**
74
     * @param Account $account
75
     */
76
    public function refreshTokenAction(Account $account): void
77
    {
78
        $this->hubicService->refreshToken($account);
79
        $this->redirect('show', '', '', ['account' => $account]);
80
    }
81
82
    /**
83
     * @param Account $account
84
     */
85
    public function accessTokenAction(Account $account): void
86
    {
87
        $this->hubicService->redirectUrlRequestToken($account);
88
    }
89
90
    /**
91
     * @param Account $account
92
     */
93
    public function callbackAction(Account $account): void
94
    {
95
        if ($this->hubicService->accessToken($account)) {
96
            $this->addFlashMessage('Token successfully added', 'Authentication request', AbstractMessage::OK);
97
        } else {
98
            $this->addFlashMessage('Failed getting token please check client ID and client secret', 'Authentication request', AbstractMessage::ERROR);
99
        }
100
        $this->redirect('show', '', '', ['account' => $account]);
101
    }
102
103
    /**
104
     * @param Account $account
105
     */
106
    public function deleteAction(Account $account): void
107
    {
108
        $this->persistenceManager->remove($account);
109
        $this->addFlashMessage('Account successfully deleted', 'Account', AbstractMessage::OK);
110
        $this->redirect('index');
111
    }
112
113
    /**
114
     * @param Account $account
115
     */
116
    public function unlinkAction(Account $account): void
117
    {
118
        $account->setAccessToken('');
119
        $account->setRefreshToken('');
120
        $this->persistenceManager->update($account);
121
        $this->persistenceManager->persistAll();
122
        $this->addFlashMessage('Account successfully unlinked', 'Account', AbstractMessage::OK);
123
        $this->redirect('show', '', '', ['account' => $account]);
124
    }
125
126
    /**
127
     * @param AccountRepository $accountRepository
128
     */
129
    public function injectAccountRepository(AccountRepository $accountRepository): void
130
    {
131
        $this->accountRepository = $accountRepository;
132
    }
133
134
    /**
135
     * @param PersistenceManager $persistenceManager
136
     */
137
    public function injectPersistenceManager(PersistenceManager $persistenceManager): void
138
    {
139
        $this->persistenceManager = $persistenceManager;
140
    }
141
142
    /**
143
     * @param HubicService $hubicService
144
     */
145
    public function injectHubicService(HubicService $hubicService): void
146
    {
147
        $this->hubicService = $hubicService;
148
    }
149
}
150