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

LibreSign / libresign / 22147773017

18 Feb 2026 04:16PM UTC coverage: 52.831%. First build
22147773017

Pull #6938

github

web-flow
Merge 312721399 into 725528158
Pull Request #6938: fix: docmdp first signature allow

59 of 68 new or added lines in 7 files covered. (86.76%)

9406 of 17804 relevant lines covered (52.83%)

6.27 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\DocMdp\ConfigService;
22
use OCA\Libresign\Service\File\FileListService;
23
use OCA\Libresign\Service\FileService;
24
use OCA\Libresign\Service\IdentifyMethod\SignatureMethod\TokenService;
25
use OCA\Libresign\Service\IdentifyMethodService;
26
use OCA\Libresign\Service\RequestSignatureService;
27
use OCA\Libresign\Service\SessionService;
28
use OCA\Libresign\Service\SignerElementsService;
29
use OCA\Libresign\Service\SignFileService;
30
use OCA\Viewer\Event\LoadViewer;
31
use OCP\AppFramework\Db\DoesNotExistException;
32
use OCP\AppFramework\Http;
33
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
34
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
35
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
36
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
37
use OCP\AppFramework\Http\Attribute\PublicPage;
38
use OCP\AppFramework\Http\ContentSecurityPolicy;
39
use OCP\AppFramework\Http\DataResponse;
40
use OCP\AppFramework\Http\FileDisplayResponse;
41
use OCP\AppFramework\Http\TemplateResponse;
42
use OCP\AppFramework\Services\IInitialState;
43
use OCP\EventDispatcher\IEventDispatcher;
44
use OCP\IAppConfig;
45
use OCP\IL10N;
46
use OCP\IRequest;
47
use OCP\IURLGenerator;
48
use OCP\IUserSession;
49
use OCP\Util;
50
use Psr\Log\LoggerInterface;
51

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

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

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

107
                $this->provideSignerSignatues();
×
108
                $this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
×
109
                $this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::NONE->value));
×
NEW
110
                $this->initialState->provideInitialState('docmdp_config', $this->docMdpConfigService->getConfig());
×
111
                $this->initialState->provideInitialState('legal_information', $this->appConfig->getValueString(Application::APP_ID, 'legal_information'));
×
112

113
                Util::addScript(Application::APP_ID, 'libresign-main');
×
114

115
                if (class_exists(LoadViewer::class)) {
×
116
                        $this->eventDispatcher->dispatchTyped(new LoadViewer());
×
117
                }
118

119
                $response = new TemplateResponse(Application::APP_ID, 'main');
×
120

121
                $policy = new ContentSecurityPolicy();
×
122
                $policy->allowEvalScript(true);
×
123
                $policy->addAllowedFrameDomain('\'self\'');
×
124
                $response->setContentSecurityPolicy($policy);
×
125

126
                return $response;
×
127
        }
128

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

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

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

179
        /**
180
         * Main page to authenticated signer with a path
181
         *
182
         * The path is used only by frontend
183
         *
184
         * @param string $path The path that was sent from frontend
185
         * @return TemplateResponse<Http::STATUS_OK, array{}>
186
         *
187
         * 200: OK
188
         */
189
        #[NoAdminRequired]
190
        #[NoCSRFRequired]
191
        #[RequireSetupOk(template: 'main')]
192
        #[FrontpageRoute(verb: 'GET', url: '/f/{path}', requirements: ['path' => '.+'])]
193
        public function indexFPath(string $path): TemplateResponse {
194
                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)) {
×
195
                        $signRequest = null;
×
196

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

211
                        if ($signRequest) {
×
212
                                $this->fileService->setSignRequest($signRequest);
×
213
                        }
214

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

260

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

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

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

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

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

386
                $policy = new ContentSecurityPolicy();
×
387
                $policy->allowEvalScript(true);
×
388
                $response->setContentSecurityPolicy($policy);
×
389

390
                return $response;
×
391
        }
392

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

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

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

422
                $signRequestsByFileId = [];
×
423
                foreach ($childSignRequests as $childSignRequest) {
×
424
                        $signRequestsByFileId[$childSignRequest->getFileId()] = true;
×
425
                }
426

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

437
                return $this->fileListService->formatEnvelopeChildFilesForSignRequest(
×
438
                        $childFiles,
×
439
                        $childSignRequests,
×
440
                        $currentSignRequest,
×
441
                );
×
442
        }
443

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

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

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

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

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

537
                return $response;
×
538
        }
539

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

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

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

585
                return $response;
×
586
        }
587

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

630
                if ($signRequest) {
×
631
                        $this->fileService->setSignRequest($signRequest);
×
632
                }
633

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

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

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

654
                return $response;
×
655
        }
656
}
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