1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Data Analytics |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @copyright 2019 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Controller; |
13
|
|
|
|
14
|
|
|
use OCA\Analytics\DataSession; |
15
|
|
|
use OCP\AppFramework\Controller; |
16
|
|
|
use OCP\AppFramework\Http\RedirectResponse; |
17
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
18
|
|
|
use OCP\IConfig; |
19
|
|
|
use OCP\IL10N; |
20
|
|
|
use OCP\ILogger; |
21
|
|
|
use OCP\IRequest; |
22
|
|
|
use OCP\IURLGenerator; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Controller class for main page. |
26
|
|
|
*/ |
27
|
|
|
class PageController extends Controller |
28
|
|
|
{ |
29
|
|
|
private $userId; |
30
|
|
|
private $l10n; |
31
|
|
|
private $configManager; |
32
|
|
|
private $logger; |
33
|
|
|
private $share; |
34
|
|
|
/** @var IURLGenerator */ |
35
|
|
|
private $url; |
36
|
|
|
/** @var DataSession */ |
37
|
|
|
private $DataSession; |
38
|
|
|
|
39
|
|
|
public function __construct( |
40
|
|
|
string $AppName, |
41
|
|
|
IRequest $request, |
42
|
|
|
$userId, |
43
|
|
|
ILogger $logger, |
44
|
|
|
IConfig $configManager, |
45
|
|
|
IL10N $l10n, |
46
|
|
|
IURLGenerator $url, |
47
|
|
|
ShareController $share, |
48
|
|
|
DataSession $DataSession |
49
|
|
|
) |
50
|
|
|
{ |
51
|
|
|
parent::__construct($AppName, $request); |
52
|
|
|
$this->userId = $userId; |
53
|
|
|
$this->configManager = $configManager; |
54
|
|
|
$this->l10n = $l10n; |
55
|
|
|
$this->logger = $logger; |
56
|
|
|
$this->url = $url; |
57
|
|
|
$this->share = $share; |
58
|
|
|
$this->DataSession = $DataSession; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @NoAdminRequired |
63
|
|
|
* @NoCSRFRequired |
64
|
|
|
*/ |
65
|
|
|
public function index() |
66
|
|
|
{ |
67
|
|
|
$response = new TemplateResponse('analytics', 'main'); |
68
|
|
|
return $response; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @PublicPage |
73
|
|
|
* @NoCSRFRequired |
74
|
|
|
* @UseSession |
75
|
|
|
* |
76
|
|
|
* @param string $token |
77
|
|
|
* @param string $password |
78
|
|
|
* @return RedirectResponse|TemplateResponse |
79
|
|
|
*/ |
80
|
|
|
public function authenticatePassword(string $token, string $password = '') |
81
|
|
|
{ |
82
|
|
|
return $this->indexPublic($token, $password); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @PublicPage |
87
|
|
|
* @UseSession |
88
|
|
|
* @NoCSRFRequired |
89
|
|
|
* @param $token |
90
|
|
|
* @param string $password |
91
|
|
|
* @return TemplateResponse|RedirectResponse |
92
|
|
|
*/ |
93
|
|
|
public function indexPublic($token, string $password = '') |
94
|
|
|
{ |
95
|
|
|
$share = $this->share->getDatasetByToken($token); |
96
|
|
|
|
97
|
|
|
if ($share === false) { |
|
|
|
|
98
|
|
|
// Dataset not shared or wrong token |
99
|
|
|
return new RedirectResponse($this->url->linkToRoute('core.login.showLoginForm', [ |
100
|
|
|
'redirect_url' => $this->url->linkToRoute('analytics.page.index', ['token' => $token]), |
101
|
|
|
])); |
102
|
|
|
} else { |
103
|
|
|
if ($share['password'] !== null) { |
104
|
|
|
$password = $password !== '' ? $password : (string)$this->DataSession->getPasswordForShare($token); |
105
|
|
|
$passwordVerification = $this->share->verifyPassword($password, $share['password']); |
106
|
|
|
if ($passwordVerification === true) { |
107
|
|
|
$this->DataSession->setPasswordForShare($token, $password); |
108
|
|
|
} else { |
109
|
|
|
$this->DataSession->removePasswordForShare($token); |
110
|
|
|
return new TemplateResponse('analytics', 'authenticate', ['wrongpw' => $password !== '',], 'guest'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
$params = array(); |
114
|
|
|
$params['token'] = $token; |
115
|
|
|
$response = new TemplateResponse('analytics', 'public', $params); |
116
|
|
|
return $response; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |