forked from nextcloud/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagecontroller.php
More file actions
85 lines (72 loc) · 2.07 KB
/
pagecontroller.php
File metadata and controls
85 lines (72 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <[email protected]>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\IRequest;
use OCP\IConfig;
use OCA\Notes\Service\NotesService;
use OCA\Notes\Service\NoteDoesNotExistException;
/**
* Class PageController
*
* @package OCA\Notes\Controller
*/
class PageController extends Controller {
/** @var NotesService */
private $notesService;
/** @var IConfig */
private $settings;
/** @var string */
private $userId;
/**
* @param string $AppName
* @param IRequest $request
* @param NotesService $notesService
* @param IConfig $settings
* @param string $UserId
*/
public function __construct($AppName, IRequest $request, $UserId,
NotesService $notesService, IConfig $settings){
parent::__construct($AppName, $request);
$this->notesService = $notesService;
$this->userId = $UserId;
$this->settings = $settings;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function index() {
$lastViewedNote = (int) $this->settings->getUserValue($this->userId,
$this->appName, 'notesLastViewedNote');
// check if note exists
try {
$this->notesService->get($lastViewedNote, $this->userId);
} catch(NoteDoesNotExistException $ex) {
$lastViewedNote = 0;
}
$response = new TemplateResponse(
$this->appName,
'main',
[
'lastViewedNote' => $lastViewedNote
]
);
$csp = new ContentSecurityPolicy();
$csp->addAllowedImageDomain('*');
$response->setContentSecurityPolicy($csp);
return $response;
}
}