• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 21453337228

28 Jan 2026 07:55PM UTC coverage: 46.319%. First build
21453337228

Pull #6595

github

web-flow
Merge 118ea4828 into 8448333b8
Pull Request #6595: feat: persist sorting preferences

0 of 4 new or added lines in 2 files covered. (0.0%)

7765 of 16764 relevant lines covered (46.32%)

5.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/Controller/PageController.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Controller;
10

11
use OCA\Libresign\AppInfo\Application;
12
use OCA\Libresign\Db\FileMapper;
13
use OCA\Libresign\Db\SignRequestMapper;
14
use OCA\Libresign\Exception\LibresignException;
15
use OCA\Libresign\Helper\JSActions;
16
use OCA\Libresign\Helper\ValidateHelper;
17
use OCA\Libresign\Middleware\Attribute\PrivateValidation;
18
use OCA\Libresign\Middleware\Attribute\RequireSetupOk;
19
use OCA\Libresign\Middleware\Attribute\RequireSignRequestUuid;
20
use OCA\Libresign\Service\AccountService;
21
use OCA\Libresign\Service\File\FileListService;
22
use OCA\Libresign\Service\FileService;
23
use OCA\Libresign\Service\IdentifyMethod\SignatureMethod\TokenService;
24
use OCA\Libresign\Service\IdentifyMethodService;
25
use OCA\Libresign\Service\RequestSignatureService;
26
use OCA\Libresign\Service\SessionService;
27
use OCA\Libresign\Service\SignerElementsService;
28
use OCA\Libresign\Service\SignFileService;
29
use OCA\Viewer\Event\LoadViewer;
30
use OCP\AppFramework\Db\DoesNotExistException;
31
use OCP\AppFramework\Http;
32
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
33
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
34
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
35
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
36
use OCP\AppFramework\Http\Attribute\PublicPage;
37
use OCP\AppFramework\Http\ContentSecurityPolicy;
38
use OCP\AppFramework\Http\DataResponse;
39
use OCP\AppFramework\Http\FileDisplayResponse;
40
use OCP\AppFramework\Http\TemplateResponse;
41
use OCP\AppFramework\Services\IInitialState;
42
use OCP\EventDispatcher\IEventDispatcher;
43
use OCP\IAppConfig;
44
use OCP\IL10N;
45
use OCP\IRequest;
46
use OCP\IURLGenerator;
47
use OCP\IUserSession;
48
use OCP\Util;
49
use Psr\Log\LoggerInterface;
50

51
class PageController extends AEnvironmentPageAwareController {
52
        public function __construct(
53
                IRequest $request,
54
                protected IUserSession $userSession,
55
                private SessionService $sessionService,
56
                private IInitialState $initialState,
57
                private AccountService $accountService,
58
                protected SignFileService $signFileService,
59
                protected RequestSignatureService $requestSignatureService,
60
                private SignerElementsService $signerElementsService,
61
                protected IL10N $l10n,
62
                private IdentifyMethodService $identifyMethodService,
63
                private IAppConfig $appConfig,
64
                private FileService $fileService,
65
                private FileListService $fileListService,
66
                private FileMapper $fileMapper,
67
                private SignRequestMapper $signRequestMapper,
68
                private LoggerInterface $logger,
69
                private ValidateHelper $validateHelper,
70
                private IEventDispatcher $eventDispatcher,
71
                private IURLGenerator $urlGenerator,
72
        ) {
73
                parent::__construct(
×
74
                        request: $request,
×
75
                        signFileService: $signFileService,
×
76
                        l10n: $l10n,
×
77
                        userSession: $userSession,
×
78
                );
×
79
        }
80

81
        /**
82
         * Index page
83
         *
84
         * @return TemplateResponse<Http::STATUS_OK, array{}>
85
         *
86
         * 200: OK
87
         */
88
        #[NoAdminRequired]
89
        #[NoCSRFRequired]
90
        #[RequireSetupOk(template: 'main')]
91
        #[FrontpageRoute(verb: 'GET', url: '/')]
92
        public function index(): TemplateResponse {
93
                $this->initialState->provideInitialState('config', $this->accountService->getConfig($this->userSession->getUser()));
×
94
                $this->initialState->provideInitialState('filters', $this->accountService->getConfigFilters($this->userSession->getUser()));
×
NEW
95
                $this->initialState->provideInitialState('sorting', $this->accountService->getConfigSorting($this->userSession->getUser()));
×
96
                $this->initialState->provideInitialState('certificate_engine', $this->accountService->getCertificateEngineName());
×
97

98
                try {
99
                        $this->validateHelper->canRequestSign($this->userSession->getUser());
×
100
                        $this->initialState->provideInitialState('can_request_sign', true);
×
101
                } catch (LibresignException) {
×
102
                        $this->initialState->provideInitialState('can_request_sign', false);
×
103
                }
104

105
                $this->provideSignerSignatues();
×
106
                $this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
×
107
                $this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::NONE->value));
×
108
                $this->initialState->provideInitialState('legal_information', $this->appConfig->getValueString(Application::APP_ID, 'legal_information'));
×
109

110
                Util::addScript(Application::APP_ID, 'libresign-main');
×
111

112
                if (class_exists(LoadViewer::class)) {
×
113
                        $this->eventDispatcher->dispatchTyped(new LoadViewer());
×
114
                }
115

116
                $response = new TemplateResponse(Application::APP_ID, 'main');
×
117

118
                $policy = new ContentSecurityPolicy();
×
119
                $policy->allowEvalScript(true);
×
120
                $policy->addAllowedFrameDomain('\'self\'');
×
121
                $response->setContentSecurityPolicy($policy);
×
122

123
                return $response;
×
124
        }
125

126
        /**
127
         * Index page to authenticated users
128
         *
129
         * This router is used to be possible render pages with /f/, is a
130
         * workaround at frontend side to identify pages with authenticated accounts
131
         *
132
         * @return TemplateResponse<Http::STATUS_OK, array{}>
133
         *
134
         * 200: OK
135
         */
136
        #[NoAdminRequired]
137
        #[NoCSRFRequired]
138
        #[RequireSetupOk(template: 'main')]
139
        #[FrontpageRoute(verb: 'GET', url: '/f/')]
140
        public function indexF(): TemplateResponse {
141
                return $this->index();
×
142
        }
143

144
        /**
145
         * Incomplete page
146
         *
147
         * @return TemplateResponse<Http::STATUS_OK, array{}>
148
         *
149
         * 200: OK
150
         */
151
        #[NoAdminRequired]
152
        #[NoCSRFRequired]
153
        #[FrontpageRoute(verb: 'GET', url: '/f/incomplete')]
154
        public function incomplete(): TemplateResponse {
155
                Util::addScript(Application::APP_ID, 'libresign-main');
×
156
                $response = new TemplateResponse(Application::APP_ID, 'main');
×
157
                return $response;
×
158
        }
159

160
        /**
161
         * Incomplete page in full screen
162
         *
163
         * @return TemplateResponse<Http::STATUS_OK, array{}>
164
         *
165
         * 200: OK
166
         */
167
        #[PublicPage]
168
        #[NoCSRFRequired]
169
        #[FrontpageRoute(verb: 'GET', url: '/p/incomplete')]
170
        public function incompleteP(): TemplateResponse {
171
                Util::addScript(Application::APP_ID, 'libresign-main');
×
172
                $response = new TemplateResponse(Application::APP_ID, 'main', [], TemplateResponse::RENDER_AS_BASE);
×
173
                return $response;
×
174
        }
175

176
        /**
177
         * Main page to authenticated signer with a path
178
         *
179
         * The path is used only by frontend
180
         *
181
         * @param string $path The path that was sent from frontend
182
         * @return TemplateResponse<Http::STATUS_OK, array{}>
183
         *
184
         * 200: OK
185
         */
186
        #[NoAdminRequired]
187
        #[NoCSRFRequired]
188
        #[RequireSetupOk(template: 'main')]
189
        #[FrontpageRoute(verb: 'GET', url: '/f/{path}', requirements: ['path' => '.+'])]
190
        public function indexFPath(string $path): TemplateResponse {
191
                if (preg_match('/validation\/(?<uuid>[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$/', $path, $matches)) {
×
192

193
                        try {
194
                                $this->fileService->setFileByUuid($matches['uuid']);
×
195
                        } catch (LibresignException) {
×
196
                                try {
197
                                        $this->fileService->setFileBySignerUuid($matches['uuid']);
×
198
                                } catch (LibresignException) {
×
199
                                        throw new LibresignException(json_encode([
×
200
                                                'action' => JSActions::ACTION_DO_NOTHING,
×
201
                                                'errors' => [['message' => $this->l10n->t('Invalid UUID')]],
×
202
                                        ]), Http::STATUS_NOT_FOUND);
×
203
                                }
204
                        }
205

206
                        $this->initialState->provideInitialState('file_info',
×
207
                                $this->fileService
×
208
                                        ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
×
209
                                        ->setHost($this->request->getServerHost())
×
210
                                        ->setMe($this->userSession->getUser())
×
211
                                        ->showVisibleElements()
×
212
                                        ->showSigners()
×
213
                                        ->showSettings()
×
214
                                        ->showMessages()
×
215
                                        ->showValidateFile()
×
216
                                        ->toArray()
×
217
                        );
×
218
                } elseif (preg_match('/sign\/(?<uuid>[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/', $path, $matches)) {
×
219
                        try {
220
                                $signRequest = $this->signFileService->getSignRequestByUuid($matches['uuid']);
×
221
                                if ($signRequest->getStatusEnum() === \OCA\Libresign\Enum\SignRequestStatus::SIGNED) {
×
222
                                        $file = $this->signFileService->getFile($signRequest->getFileId());
×
223
                                        $redirectUrl = $this->urlGenerator->linkToRouteAbsolute('libresign.page.indexFPath', [
×
224
                                                'path' => 'validation/' . $file->getUuid(),
×
225
                                        ]);
×
226
                                        throw new LibresignException(json_encode([
×
227
                                                'action' => JSActions::ACTION_REDIRECT,
×
228
                                                'redirect' => $redirectUrl,
×
229
                                        ]), Http::STATUS_SEE_OTHER);
×
230
                                }
231
                                $file = $this->fileService
×
232
                                        ->setFile($this->signFileService->getFile($signRequest->getFileId()))
×
233
                                        ->setMe($this->userSession->getUser())
×
234
                                        ->setSignRequest($signRequest)
×
235
                                        ->showSettings()
×
236
                                        ->toArray();
×
237
                                $this->initialState->provideInitialState('needIdentificationDocuments', $file['settings']['needIdentificationDocuments'] ?? false);
×
238
                                $this->initialState->provideInitialState('identificationDocumentsWaitingApproval', $file['settings']['identificationDocumentsWaitingApproval'] ?? false);
×
239
                        } catch (LibresignException $e) {
×
240
                                throw $e;
×
241
                        } catch (\Throwable $e) {
×
242
                                throw new LibresignException(json_encode([
×
243
                                        'action' => JSActions::ACTION_DO_NOTHING,
×
244
                                        'errors' => [['message' => $this->l10n->t('Invalid UUID')]],
×
245
                                ]), Http::STATUS_NOT_FOUND);
×
246
                        }
247
                }
248
                return $this->index();
×
249
        }
250

251

252
        /**
253
         * Sign page to authenticated signer
254
         *
255
         * @param string $uuid Sign request uuid
256
         * @return TemplateResponse<Http::STATUS_OK, array{}>
257
         *
258
         * 200: OK
259
         */
260
        #[NoAdminRequired]
261
        #[NoCSRFRequired]
262
        #[RequireSetupOk]
263
        #[PublicPage]
264
        #[RequireSignRequestUuid(redirectIfSignedToValidation: true)]
265
        #[FrontpageRoute(verb: 'GET', url: '/f/sign/{uuid}')]
266
        public function signF(string $uuid): TemplateResponse {
267
                $this->initialState->provideInitialState('action', JSActions::ACTION_SIGN_INTERNAL);
×
268
                return $this->index();
×
269
        }
270

271
        /**
272
         * Sign page to authenticated signer with the path of file
273
         *
274
         * The path is used only by frontend
275
         *
276
         * @param string $uuid Sign request uuid
277
         * @return TemplateResponse<Http::STATUS_OK, array{}>
278
         *
279
         * 200: OK
280
         */
281
        #[NoAdminRequired]
282
        #[NoCSRFRequired]
283
        #[RequireSetupOk]
284
        #[PublicPage]
285
        #[RequireSignRequestUuid(redirectIfSignedToValidation: true)]
286
        #[FrontpageRoute(verb: 'GET', url: '/f/sign/{uuid}/{path}', requirements: ['path' => '.+'])]
287
        public function signFPath(string $uuid): TemplateResponse {
288
                $this->initialState->provideInitialState('action', JSActions::ACTION_SIGN_INTERNAL);
×
289
                return $this->index();
×
290
        }
291

292
        /**
293
         * Sign page to unauthenticated signer
294
         *
295
         * The path is used only by frontend
296
         *
297
         * @param string $uuid Sign request uuid
298
         * @return TemplateResponse<Http::STATUS_OK, array{}>
299
         *
300
         * 200: OK
301
         */
302
        #[NoAdminRequired]
303
        #[NoCSRFRequired]
304
        #[RequireSetupOk]
305
        #[PublicPage]
306
        #[RequireSignRequestUuid(redirectIfSignedToValidation: true)]
307
        #[FrontpageRoute(verb: 'GET', url: '/p/sign/{uuid}/{path}', requirements: ['path' => '.+'])]
308
        public function signPPath(string $uuid): TemplateResponse {
309
                return $this->sign($uuid);
×
310
        }
311

312
        /**
313
         * Sign page to unauthenticated signer
314
         *
315
         * The path is used only by frontend
316
         *
317
         * @param string $uuid Sign request uuid
318
         * @return TemplateResponse<Http::STATUS_OK, array{}>
319
         *
320
         * 200: OK
321
         */
322
        #[PrivateValidation]
323
        #[NoAdminRequired]
324
        #[NoCSRFRequired]
325
        #[RequireSetupOk]
326
        #[PublicPage]
327
        #[RequireSignRequestUuid(redirectIfSignedToValidation: true)]
328
        #[FrontpageRoute(verb: 'GET', url: '/p/sign/{uuid}')]
329
        public function sign(string $uuid): TemplateResponse {
330
                $this->initialState->provideInitialState('action', JSActions::ACTION_SIGN);
×
331
                $this->initialState->provideInitialState('config',
×
332
                        $this->accountService->getConfig($this->userSession->getUser())
×
333
                );
×
334
                $this->initialState->provideInitialState('filename', $this->getFileEntity()->getName());
×
335
                $file = $this->fileService
×
336
                        ->setFile($this->getFileEntity())
×
337
                        ->setHost($this->request->getServerHost())
×
338
                        ->setMe($this->userSession->getUser())
×
339
                        ->setSignerIdentified()
×
340
                        ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
×
341
                        ->setSignRequest($this->getSignRequestEntity())
×
342
                        ->showVisibleElements()
×
343
                        ->showSigners()
×
344
                        ->showSettings()
×
345
                        ->toArray();
×
346
                $this->initialState->provideInitialState('config', [
×
347
                        'identificationDocumentsFlow' => $file['settings']['needIdentificationDocuments'] ?? false,
×
348
                ]);
×
349
                $this->initialState->provideInitialState('id', $file['id']);
×
350
                $this->initialState->provideInitialState('nodeId', $file['nodeId']);
×
351
                $this->initialState->provideInitialState('needIdentificationDocuments', $file['settings']['needIdentificationDocuments'] ?? false);
×
352
                $this->initialState->provideInitialState('identificationDocumentsWaitingApproval', $file['settings']['identificationDocumentsWaitingApproval'] ?? false);
×
353
                $this->initialState->provideInitialState('status', $file['status']);
×
354
                $this->initialState->provideInitialState('statusText', $file['statusText']);
×
355
                $this->initialState->provideInitialState('signers', $file['signers']);
×
356
                $this->initialState->provideInitialState('visibleElements', $file['visibleElements'] ?? []);
×
357
                $this->initialState->provideInitialState('sign_request_uuid', $uuid);
×
358
                $this->provideSignerSignatues();
×
359
                $this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH);
×
360
                $this->initialState->provideInitialState('description', $this->getSignRequestEntity()->getDescription() ?? '');
×
361
                if ($this->getFileEntity()->getNodeType() === 'envelope') {
×
362
                        $this->initialState->provideInitialState('pdfs', []);
×
363
                        $this->initialState->provideInitialState('envelopeFiles', $this->getEnvelopeChildFiles());
×
364
                } else {
365
                        $this->initialState->provideInitialState('pdfs', $this->getPdfUrls());
×
366
                        $this->initialState->provideInitialState('envelopeFiles', []);
×
367
                }
368
                $this->initialState->provideInitialState('nodeId', $this->getFileEntity()->getNodeId());
×
369
                $this->initialState->provideInitialState('nodeType', $this->getFileEntity()->getNodeType());
×
370

371
                Util::addScript(Application::APP_ID, 'libresign-external');
×
372
                $response = new TemplateResponse(Application::APP_ID, 'external', [], TemplateResponse::RENDER_AS_BASE);
×
373

374
                $policy = new ContentSecurityPolicy();
×
375
                $policy->allowEvalScript(true);
×
376
                $response->setContentSecurityPolicy($policy);
×
377

378
                return $response;
×
379
        }
380

381
        private function provideSignerSignatues(): void {
382
                $signatures = [];
×
383
                if ($this->userSession->getUser()) {
×
384
                        $signatures = $this->signerElementsService->getUserElements($this->userSession->getUser()->getUID());
×
385
                } else {
386
                        $signatures = $this->signerElementsService->getElementsFromSessionAsArray();
×
387
                }
388
                $this->initialState->provideInitialState('user_signatures', $signatures);
×
389
        }
390

391
        /**
392
         * @return string[] Array of PDF URLs
393
         */
394
        private function getPdfUrls(): array {
395
                return $this->signFileService->getPdfUrlsForSigning(
×
396
                        $this->getFileEntity(),
×
397
                        $this->getSignRequestEntity()
×
398
                );
×
399
        }
400

401
        private function getEnvelopeChildFiles(): array {
402
                $parentFileId = $this->getFileEntity()->getId();
×
403
                $currentSignRequest = $this->getSignRequestEntity();
×
404
                $childFiles = $this->fileMapper->getChildrenFiles($parentFileId);
×
405
                $childSignRequests = $this->signRequestMapper->getByEnvelopeChildrenAndIdentifyMethod(
×
406
                        $parentFileId,
×
407
                        $currentSignRequest->getId()
×
408
                );
×
409

410
                $signRequestsByFileId = [];
×
411
                foreach ($childSignRequests as $childSignRequest) {
×
412
                        $signRequestsByFileId[$childSignRequest->getFileId()] = true;
×
413
                }
414

415
                foreach ($childFiles as $childFile) {
×
416
                        if (!isset($signRequestsByFileId[$childFile->getId()])) {
×
417
                                $this->logger->warning('Missing sign request for envelope child file', [
×
418
                                        'parentFileId' => $parentFileId,
×
419
                                        'childFileId' => $childFile->getId(),
×
420
                                        'signRequestId' => $currentSignRequest->getId(),
×
421
                                ]);
×
422
                        }
423
                }
424

425
                return $this->fileListService->formatEnvelopeChildFilesForSignRequest(
×
426
                        $childFiles,
×
427
                        $childSignRequests,
×
428
                        $currentSignRequest,
×
429
                );
×
430
        }
431

432
        /**
433
         * Show signature page for identification document approval
434
         *
435
         * @param string $uuid File UUID for the identification document approval
436
         * @return TemplateResponse<Http::STATUS_OK, array{}>
437
         *
438
         * 200: OK
439
         * 404: Invalid UUID
440
         */
441
        #[NoAdminRequired]
442
        #[NoCSRFRequired]
443
        #[RequireSetupOk]
444
        #[FrontpageRoute(verb: 'GET', url: '/p/id-docs/approve/{uuid}')]
445
        public function signIdDoc($uuid): TemplateResponse {
446
                try {
447
                        $fileEntity = $this->signFileService->getFileByUuid($uuid);
×
448
                        $this->signFileService->getIdDocById($fileEntity->getId());
×
449
                } catch (DoesNotExistException) {
×
450
                        throw new LibresignException(json_encode([
×
451
                                'action' => JSActions::ACTION_DO_NOTHING,
×
452
                                'errors' => [['message' => $this->l10n->t('Invalid UUID')]],
×
453
                        ]), Http::STATUS_NOT_FOUND);
×
454
                }
455
                $this->initialState->provideInitialState('action', JSActions::ACTION_SIGN_ID_DOC);
×
456
                $this->initialState->provideInitialState('config',
×
457
                        $this->accountService->getConfig($this->userSession->getUser())
×
458
                );
×
459
                $this->initialState->provideInitialState('signer',
×
460
                        $this->signFileService->getSignerData(
×
461
                                $this->userSession->getUser(),
×
462
                        )
×
463
                );
×
464
                $this->initialState->provideInitialState('identifyMethods',
×
465
                        $this->signFileService->getAvailableIdentifyMethodsFromSettings()
×
466
                );
×
467
                $this->initialState->provideInitialState('filename', $fileEntity->getName());
×
468
                $file = $this->fileService
×
469
                        ->setFile($fileEntity)
×
470
                        ->setHost($this->request->getServerHost())
×
471
                        ->setMe($this->userSession->getUser())
×
472
                        ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
×
473
                        ->showVisibleElements()
×
474
                        ->showSigners()
×
475
                        ->toArray();
×
476
                $this->initialState->provideInitialState('id', $file['id']);
×
477
                $this->initialState->provideInitialState('nodeId', $file['nodeId']);
×
478
                $this->initialState->provideInitialState('status', $file['status']);
×
479
                $this->initialState->provideInitialState('statusText', $file['statusText']);
×
480
                $this->initialState->provideInitialState('visibleElements', $file['visibleElements'] ?? []);
×
481
                $this->initialState->provideInitialState('signers', $file['signers'] ?? []);
×
482
                $this->provideSignerSignatues();
×
483
                $signatureMethods = $this->identifyMethodService->getSignMethodsOfIdentifiedFactors($this->getSignRequestEntity()->getId());
×
484
                $this->initialState->provideInitialState('signature_methods', $signatureMethods);
×
485
                $this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH);
×
486
                $this->initialState->provideInitialState('description', '');
×
487
                $this->initialState->provideInitialState('pdf', [
×
488
                        'url' => $this->signFileService->getFileUrl($fileEntity->getId(), $uuid)
×
489
                ]);
×
490

491
                Util::addScript(Application::APP_ID, 'libresign-external');
×
492
                $response = new TemplateResponse(Application::APP_ID, 'external', [], TemplateResponse::RENDER_AS_BASE);
×
493

494
                $policy = new ContentSecurityPolicy();
×
495
                $policy->allowEvalScript(true);
×
496
                $response->setContentSecurityPolicy($policy);
×
497

498
                return $response;
×
499
        }
500

501
        /**
502
         * Use UUID of file to get PDF
503
         *
504
         * @param string $uuid File uuid
505
         * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
506
         *
507
         * 200: OK
508
         * 401: Validation page not accessible if unauthenticated
509
         * 404: File not found
510
         */
511
        #[PrivateValidation]
512
        #[NoAdminRequired]
513
        #[NoCSRFRequired]
514
        #[RequireSetupOk]
515
        #[PublicPage]
516
        #[AnonRateLimit(limit: 300, period: 60)]
517
        #[FrontpageRoute(verb: 'GET', url: '/p/pdf/{uuid}')]
518
        public function getPdf($uuid) {
519
                try {
520
                        $file = $this->accountService->getPdfByUuid($uuid);
×
521
                } catch (DoesNotExistException) {
×
522
                        return new DataResponse([], Http::STATUS_NOT_FOUND);
×
523
                }
524

525
                return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
×
526
        }
527

528
        /**
529
         * Use UUID of user to get PDF
530
         *
531
         * @param string $uuid Sign request uuid
532
         * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>
533
         *
534
         * 200: OK
535
         * 401: Validation page not accessible if unauthenticated
536
         */
537
        #[PrivateValidation]
538
        #[NoAdminRequired]
539
        #[NoCSRFRequired]
540
        #[RequireSignRequestUuid]
541
        #[PublicPage]
542
        #[RequireSetupOk]
543
        #[AnonRateLimit(limit: 300, period: 60)]
544
        #[FrontpageRoute(verb: 'GET', url: '/pdf/{uuid}')]
545
        public function getPdfFile($uuid): FileDisplayResponse {
546
                $files = $this->getNextcloudFiles();
×
547
                if (empty($files)) {
×
548
                        throw new LibresignException(json_encode([
×
549
                                'action' => JSActions::ACTION_DO_NOTHING,
×
550
                                'errors' => [['message' => $this->l10n->t('File not found')]],
×
551
                        ]), Http::STATUS_NOT_FOUND);
×
552
                }
553
                $file = current($files);
×
554
                return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
×
555
        }
556

557
        /**
558
         * Show validation page
559
         *
560
         * @return TemplateResponse<Http::STATUS_OK, array{}>
561
         *
562
         * 200: OK
563
         * 401: Validation page not accessible if unauthenticated
564
         */
565
        #[PrivateValidation]
566
        #[NoAdminRequired]
567
        #[NoCSRFRequired]
568
        #[RequireSetupOk(template: 'validation')]
569
        #[PublicPage]
570
        #[AnonRateLimit(limit: 30, period: 60)]
571
        #[FrontpageRoute(verb: 'GET', url: '/p/validation')]
572
        public function validation(): TemplateResponse {
573
                if ($this->getFileEntity()) {
×
574
                        $this->initialState->provideInitialState('config',
×
575
                                $this->accountService->getConfig($this->userSession->getUser())
×
576
                        );
×
577
                        $this->initialState->provideInitialState('file', [
×
578
                                'uuid' => $this->getFileEntity()?->getUuid(),
×
579
                                'description' => $this->getSignRequestEntity()?->getDescription(),
×
580
                        ]);
×
581
                        $this->initialState->provideInitialState('filename', $this->getFileEntity()?->getName());
×
582
                        $this->initialState->provideInitialState('pdfs', $this->getPdfUrls());
×
583
                        $this->initialState->provideInitialState('signer',
×
584
                                $this->signFileService->getSignerData(
×
585
                                        $this->userSession->getUser(),
×
586
                                        $this->getSignRequestEntity(),
×
587
                                )
×
588
                        );
×
589
                }
590

591
                Util::addScript(Application::APP_ID, 'libresign-validation');
×
592
                $response = new TemplateResponse(Application::APP_ID, 'validation', [], TemplateResponse::RENDER_AS_BASE);
×
593

594
                return $response;
×
595
        }
596

597
        /**
598
         * Show validation page
599
         *
600
         * The path is used only by frontend
601
         *
602
         * @param string $uuid Sign request uuid
603
         * @return TemplateResponse<Http::STATUS_OK, array{}>
604
         *
605
         * 200: OK
606
         * 303: Redirected to validation page
607
         * 401: Validation page not accessible if unauthenticated
608
         */
609
        #[PrivateValidation]
610
        #[NoAdminRequired]
611
        #[NoCSRFRequired]
612
        #[RequireSetupOk]
613
        #[PublicPage]
614
        #[AnonRateLimit(limit: 30, period: 60)]
615
        #[FrontpageRoute(verb: 'GET', url: '/validation/{uuid}')]
616
        public function validationFileWithShortUrl(): TemplateResponse {
617
                return $this->validationFilePublic($this->request->getParam('uuid'));
×
618
        }
619

620
        /**
621
         * Show validation page
622
         *
623
         * @param string $uuid Sign request uuid
624
         * @return TemplateResponse<Http::STATUS_OK, array{}>
625
         *
626
         * 200: OK
627
         */
628
        #[NoAdminRequired]
629
        #[NoCSRFRequired]
630
        #[RequireSetupOk(template: 'main')]
631
        #[PublicPage]
632
        #[RequireSignRequestUuid]
633
        #[FrontpageRoute(verb: 'GET', url: '/reset-password')]
634
        public function resetPassword(): TemplateResponse {
635
                $this->initialState->provideInitialState('config',
×
636
                        $this->accountService->getConfig($this->userSession->getUser())
×
637
                );
×
638

639
                Util::addScript(Application::APP_ID, 'libresign-main');
×
640
                $response = new TemplateResponse(Application::APP_ID, 'reset_password');
×
641

642
                return $response;
×
643
        }
644

645
        /**
646
         * Public page to show validation for a specific file UUID
647
         *
648
         * @param string $uuid File uuid
649
         * @return TemplateResponse<Http::STATUS_OK, array{}>
650
         *
651
         * 200: OK
652
         * 401: Validation page not accessible if unauthenticated
653
         */
654
        #[PrivateValidation]
655
        #[NoAdminRequired]
656
        #[NoCSRFRequired]
657
        #[RequireSetupOk(template: 'validation')]
658
        #[PublicPage]
659
        #[AnonRateLimit(limit: 30, period: 60)]
660
        #[FrontpageRoute(verb: 'GET', url: '/p/validation/{uuid}')]
661
        public function validationFilePublic(string $uuid): TemplateResponse {
662
                try {
663
                        $this->signFileService->getFileByUuid($uuid);
×
664
                        $this->fileService->setFileByUuid($uuid);
×
665
                } catch (DoesNotExistException) {
×
666
                        try {
667
                                $signRequest = $this->signFileService->getSignRequestByUuid($uuid);
×
668
                                $libresignFile = $this->signFileService->getFile($signRequest->getFileId());
×
669
                                $this->fileService->setFile($libresignFile);
×
670
                        } catch (DoesNotExistException) {
×
671
                                $this->initialState->provideInitialState('action', JSActions::ACTION_DO_NOTHING);
×
672
                                $this->initialState->provideInitialState('errors', [['message' => $this->l10n->t('Invalid UUID')]]);
×
673
                        }
674
                }
675
                if ($this->userSession->isLoggedIn()) {
×
676
                        $this->initialState->provideInitialState('config',
×
677
                                $this->accountService->getConfig($this->userSession->getUser())
×
678
                        );
×
679
                        $this->fileService->setMe($this->userSession->getUser());
×
680
                } else {
681
                        $this->initialState->provideInitialState('config',
×
682
                                $this->accountService->getConfig()
×
683
                        );
×
684
                }
685

686
                $this->initialState->provideInitialState('legal_information', $this->appConfig->getValueString(Application::APP_ID, 'legal_information'));
×
687

688
                $this->initialState->provideInitialState('file_info',
×
689
                        $this->fileService
×
690
                                ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
×
691
                                ->setHost($this->request->getServerHost())
×
692
                                ->showVisibleElements()
×
693
                                ->showSigners()
×
694
                                ->showSettings()
×
695
                                ->showMessages()
×
696
                                ->showValidateFile()
×
697
                                ->toArray()
×
698
                );
×
699

700
                Util::addScript(Application::APP_ID, 'libresign-validation');
×
701
                if (class_exists(LoadViewer::class)) {
×
702
                        $this->eventDispatcher->dispatchTyped(new LoadViewer());
×
703
                }
704
                $response = new TemplateResponse(Application::APP_ID, 'validation', [], TemplateResponse::RENDER_AS_BASE);
×
705

706
                return $response;
×
707
        }
708
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc