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

LibreSign / libresign / 22047397566

16 Feb 2026 01:47AM UTC coverage: 51.605%. First build
22047397566

Pull #6891

github

web-flow
Merge cc204601c into bdac9dc51
Pull Request #6891: feat: add id doc approver workflow

171 of 424 new or added lines in 24 files covered. (40.33%)

9145 of 17721 relevant lines covered (51.61%)

6.15 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()));
×
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)) {
×
NEW
192
                        $signRequest = null;
×
193

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

NEW
208
                        if ($signRequest) {
×
NEW
209
                                $this->fileService->setSignRequest($signRequest);
×
210
                        }
211

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

257

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

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

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

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

377
                Util::addScript(Application::APP_ID, 'libresign-external');
×
378
                if (class_exists(LoadViewer::class)) {
×
379
                        $this->eventDispatcher->dispatchTyped(new LoadViewer());
×
380
                }
381
                $response = new TemplateResponse(Application::APP_ID, 'external', [], TemplateResponse::RENDER_AS_BASE);
×
382

383
                $policy = new ContentSecurityPolicy();
×
384
                $policy->allowEvalScript(true);
×
385
                $response->setContentSecurityPolicy($policy);
×
386

387
                return $response;
×
388
        }
389

390
        private function provideSignerSignatues(): void {
391
                $signatures = [];
×
392
                if ($this->userSession->getUser()) {
×
393
                        $signatures = $this->signerElementsService->getUserElements($this->userSession->getUser()->getUID());
×
394
                } else {
395
                        $signatures = $this->signerElementsService->getElementsFromSessionAsArray();
×
396
                }
397
                $this->initialState->provideInitialState('user_signatures', $signatures);
×
398
        }
399

400
        /**
401
         * @return string[] Array of PDF URLs
402
         */
403
        private function getPdfUrls(): array {
404
                return $this->signFileService->getPdfUrlsForSigning(
×
405
                        $this->getFileEntity(),
×
406
                        $this->getSignRequestEntity()
×
407
                );
×
408
        }
409

410
        private function getEnvelopeChildFiles(): array {
411
                $parentFileId = $this->getFileEntity()->getId();
×
412
                $currentSignRequest = $this->getSignRequestEntity();
×
413
                $childFiles = $this->fileMapper->getChildrenFiles($parentFileId);
×
414
                $childSignRequests = $this->signRequestMapper->getByEnvelopeChildrenAndIdentifyMethod(
×
415
                        $parentFileId,
×
416
                        $currentSignRequest->getId()
×
417
                );
×
418

419
                $signRequestsByFileId = [];
×
420
                foreach ($childSignRequests as $childSignRequest) {
×
421
                        $signRequestsByFileId[$childSignRequest->getFileId()] = true;
×
422
                }
423

424
                foreach ($childFiles as $childFile) {
×
425
                        if (!isset($signRequestsByFileId[$childFile->getId()])) {
×
426
                                $this->logger->warning('Missing sign request for envelope child file', [
×
427
                                        'parentFileId' => $parentFileId,
×
428
                                        'childFileId' => $childFile->getId(),
×
429
                                        'signRequestId' => $currentSignRequest->getId(),
×
430
                                ]);
×
431
                        }
432
                }
433

434
                return $this->fileListService->formatEnvelopeChildFilesForSignRequest(
×
435
                        $childFiles,
×
436
                        $childSignRequests,
×
437
                        $currentSignRequest,
×
438
                );
×
439
        }
440

441
        /**
442
         * Use UUID of file to get PDF
443
         *
444
         * @param string $uuid File uuid
445
         * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
446
         *
447
         * 200: OK
448
         * 401: Validation page not accessible if unauthenticated
449
         * 404: File not found
450
         */
451
        #[PrivateValidation]
452
        #[NoAdminRequired]
453
        #[NoCSRFRequired]
454
        #[RequireSetupOk]
455
        #[PublicPage]
456
        #[RequireSignRequestUuid(allowIdDocs: true)]
457
        #[AnonRateLimit(limit: 300, period: 60)]
458
        #[FrontpageRoute(verb: 'GET', url: '/p/pdf/{uuid}')]
459
        public function getPdf($uuid) {
460
                try {
461
                        $file = $this->accountService->getPdfByUuid($uuid);
×
462
                } catch (DoesNotExistException) {
×
463
                        return new DataResponse([], Http::STATUS_NOT_FOUND);
×
464
                }
465

466
                return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
×
467
        }
468

469
        /**
470
         * Use UUID of user to get PDF
471
         *
472
         * @param string $uuid Sign request uuid
473
         * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>
474
         *
475
         * 200: OK
476
         * 401: Validation page not accessible if unauthenticated
477
         */
478
        #[PrivateValidation]
479
        #[NoAdminRequired]
480
        #[NoCSRFRequired]
481
        #[RequireSignRequestUuid(allowIdDocs: true)]
482
        #[PublicPage]
483
        #[RequireSetupOk]
484
        #[AnonRateLimit(limit: 300, period: 60)]
485
        #[FrontpageRoute(verb: 'GET', url: '/pdf/{uuid}')]
486
        public function getPdfFile($uuid): FileDisplayResponse {
487
                $files = $this->getNextcloudFiles();
×
488
                if (empty($files)) {
×
489
                        throw new LibresignException(json_encode([
×
490
                                'action' => JSActions::ACTION_DO_NOTHING,
×
491
                                'errors' => [['message' => $this->l10n->t('File not found')]],
×
492
                        ]), Http::STATUS_NOT_FOUND);
×
493
                }
494
                $file = current($files);
×
495
                return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
×
496
        }
497

498
        /**
499
         * Show validation page
500
         *
501
         * @return TemplateResponse<Http::STATUS_OK, array{}>
502
         *
503
         * 200: OK
504
         * 401: Validation page not accessible if unauthenticated
505
         */
506
        #[PrivateValidation]
507
        #[NoAdminRequired]
508
        #[NoCSRFRequired]
509
        #[RequireSetupOk(template: 'validation')]
510
        #[PublicPage]
511
        #[AnonRateLimit(limit: 30, period: 60)]
512
        #[FrontpageRoute(verb: 'GET', url: '/p/validation')]
513
        public function validation(): TemplateResponse {
514
                if ($this->getFileEntity()) {
×
515
                        $this->initialState->provideInitialState('config',
×
516
                                $this->accountService->getConfig($this->userSession->getUser())
×
517
                        );
×
518
                        $this->initialState->provideInitialState('file', [
×
519
                                'uuid' => $this->getFileEntity()?->getUuid(),
×
520
                                'description' => $this->getSignRequestEntity()?->getDescription(),
×
521
                        ]);
×
522
                        $this->initialState->provideInitialState('filename', $this->getFileEntity()?->getName());
×
523
                        $this->initialState->provideInitialState('pdfs', $this->getPdfUrls());
×
524
                        $this->initialState->provideInitialState('signer',
×
525
                                $this->signFileService->getSignerData(
×
526
                                        $this->userSession->getUser(),
×
527
                                        $this->getSignRequestEntity(),
×
528
                                )
×
529
                        );
×
530
                }
531

532
                Util::addScript(Application::APP_ID, 'libresign-validation');
×
533
                $response = new TemplateResponse(Application::APP_ID, 'validation', [], TemplateResponse::RENDER_AS_BASE);
×
534

535
                return $response;
×
536
        }
537

538
        /**
539
         * Show validation page
540
         *
541
         * The path is used only by frontend
542
         *
543
         * @param string $uuid Sign request uuid
544
         * @return TemplateResponse<Http::STATUS_OK, array{}>
545
         *
546
         * 200: OK
547
         * 303: Redirected to validation page
548
         * 401: Validation page not accessible if unauthenticated
549
         */
550
        #[PrivateValidation]
551
        #[NoAdminRequired]
552
        #[NoCSRFRequired]
553
        #[RequireSetupOk]
554
        #[PublicPage]
555
        #[AnonRateLimit(limit: 30, period: 60)]
556
        #[FrontpageRoute(verb: 'GET', url: '/validation/{uuid}')]
557
        public function validationFileWithShortUrl(): TemplateResponse {
558
                return $this->validationFilePublic($this->request->getParam('uuid'));
×
559
        }
560

561
        /**
562
         * Show validation page
563
         *
564
         * @param string $uuid Sign request uuid
565
         * @return TemplateResponse<Http::STATUS_OK, array{}>
566
         *
567
         * 200: OK
568
         */
569
        #[NoAdminRequired]
570
        #[NoCSRFRequired]
571
        #[RequireSetupOk(template: 'main')]
572
        #[PublicPage]
573
        #[RequireSignRequestUuid]
574
        #[FrontpageRoute(verb: 'GET', url: '/reset-password')]
575
        public function resetPassword(): TemplateResponse {
576
                $this->initialState->provideInitialState('config',
×
577
                        $this->accountService->getConfig($this->userSession->getUser())
×
578
                );
×
579

580
                Util::addScript(Application::APP_ID, 'libresign-main');
×
581
                $response = new TemplateResponse(Application::APP_ID, 'reset_password');
×
582

583
                return $response;
×
584
        }
585

586
        /**
587
         * Public page to show validation for a specific file UUID
588
         *
589
         * @param string $uuid File uuid
590
         * @return TemplateResponse<Http::STATUS_OK, array{}>
591
         *
592
         * 200: OK
593
         * 401: Validation page not accessible if unauthenticated
594
         */
595
        #[PrivateValidation]
596
        #[NoAdminRequired]
597
        #[NoCSRFRequired]
598
        #[RequireSetupOk(template: 'validation')]
599
        #[PublicPage]
600
        #[AnonRateLimit(limit: 30, period: 60)]
601
        #[FrontpageRoute(verb: 'GET', url: '/p/validation/{uuid}')]
602
        public function validationFilePublic(string $uuid): TemplateResponse {
NEW
603
                $signRequest = null;
×
604
                try {
605
                        $this->signFileService->getFileByUuid($uuid);
×
606
                        $this->fileService->setFileByUuid($uuid);
×
607
                } catch (DoesNotExistException) {
×
608
                        try {
609
                                $signRequest = $this->signFileService->getSignRequestByUuid($uuid);
×
610
                                $libresignFile = $this->signFileService->getFile($signRequest->getFileId());
×
611
                                $this->fileService->setFile($libresignFile);
×
612
                        } catch (DoesNotExistException) {
×
613
                                $this->initialState->provideInitialState('action', JSActions::ACTION_DO_NOTHING);
×
614
                                $this->initialState->provideInitialState('errors', [['message' => $this->l10n->t('Invalid UUID')]]);
×
615
                        }
616
                }
617
                if ($this->userSession->isLoggedIn()) {
×
618
                        $this->initialState->provideInitialState('config',
×
619
                                $this->accountService->getConfig($this->userSession->getUser())
×
620
                        );
×
621
                        $this->fileService->setMe($this->userSession->getUser());
×
622
                } else {
623
                        $this->initialState->provideInitialState('config',
×
624
                                $this->accountService->getConfig()
×
625
                        );
×
626
                }
627

NEW
628
                if ($signRequest) {
×
NEW
629
                        $this->fileService->setSignRequest($signRequest);
×
630
                }
631

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

634
                $this->initialState->provideInitialState('file_info',
×
635
                        $this->fileService
×
636
                                ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
×
637
                                ->setHost($this->request->getServerHost())
×
638
                                ->showVisibleElements()
×
639
                                ->showSigners()
×
640
                                ->showSettings()
×
641
                                ->showMessages()
×
642
                                ->showValidateFile()
×
643
                                ->toArray()
×
644
                );
×
645

646
                Util::addScript(Application::APP_ID, 'libresign-validation');
×
647
                if (class_exists(LoadViewer::class)) {
×
648
                        $this->eventDispatcher->dispatchTyped(new LoadViewer());
×
649
                }
650
                $response = new TemplateResponse(Application::APP_ID, 'validation', [], TemplateResponse::RENDER_AS_BASE);
×
651

652
                return $response;
×
653
        }
654
}
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