PageController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B index() 0 30 6
1
<?php
2
/**
3
 * Nextcloud - NextNote
4
 *
5
 *
6
 * @copyright Copyright (c) 2017, Sander Brand ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\NextNote\Controller;
25
26
27
use OCA\NextNote\Service\NoteService;
28
use OCA\NextNote\Service\SettingsService;
29
use \OCP\IRequest;
30
use \OCP\AppFramework\Http\TemplateResponse;
31
use \OCP\AppFramework\Controller;
32
33
34
class PageController extends Controller {
35
36
	private $userId;
37
	private $config;
38
	private $noteService;
39
40
	public function __construct($appName, IRequest $request, $userId,
41
								SettingsService $settings,
42
								NoteService $noteService) {
43
		parent::__construct($appName, $request);
44
		$this->userId = $userId;
45
		$this->config = $settings;
46
		$this->noteService = $noteService;
47
	}
48
49
50
	/**
51
	 * CAUTION: the @Stuff turn off security checks, for this page no admin is
52
	 *          required and no CSRF check. If you don't know what CSRF is, read
53
	 *          it up in the docs or you might create a security hole. This is
54
	 *          basically the only required method to add this exemption, don't
55
	 *          add it to any other method if you don't exactly know what it does
56
	 *
57
	 * @NoAdminRequired
58
	 * @NoCSRFRequired
59
	 */
60
	public function index() {
61
		$shareMode = $this->config->getAppSetting('sharemode', 'merge'); // merge or standalone
62
		$params = array('user' => $this->userId, 'shareMode' => $shareMode, 'config'=> $this->config->getSettings());
63
64
		if($this->config->getUserSetting('first_user', '1') === '1'){
65
			$this->noteService->createExampleNote($this->userId);
66
			$this->config->setUserSetting('first_user', '0');
67
		}
68
69
		$response = new TemplateResponse('nextnote', 'main', $params);
70
		$ocVersion = \OCP\Util::getVersion();
71
		if ($ocVersion[0] > 8 || ($ocVersion[0] == 8 && $ocVersion[1] >= 1)) {
72
			$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
73
			$csp->addAllowedImageDomain('data:');
74
			$csp->addAllowedImageDomain('blob:');
75
			$csp->addAllowedFrameDomain('data:');
76
77
			$allowedFrameDomains = array(
78
				'https://www.youtube.com'
79
			);
80
			foreach ($allowedFrameDomains as $domain) {
81
				$csp->addAllowedFrameDomain($domain);
82
			}
83
84
			$csp->addAllowedScriptDomain("'nonce-test'");
85
			$csp->addAllowedScriptDomain("*");
86
			$response->setContentSecurityPolicy($csp);
87
		}
88
		return $response;
89
	}
90
}
91