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

FastyBird / simple-auth / 9818139344

06 Jul 2024 09:09AM UTC coverage: 65.685% (-0.3%) from 66.025%
9818139344

push

github

web-flow
Added ability to redirect to home page when user is signed in (#5)

* Added ability to redirect to home page when user is signed in

* QA fixes

4 of 11 new or added lines in 3 files covered. (36.36%)

379 of 577 relevant lines covered (65.68%)

4.04 hits per line

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

0.0
/src/Application/TSimpleAuth.php
1
<?php declare(strict_types = 1);
2

3
/**
4
 * TSimpleAuth.php
5
 *
6
 * @license        More in LICENSE.md
7
 * @copyright      https://www.fastybird.com
8
 * @author         Adam Kadlec <adam.kadlec@fastybird.com>
9
 * @package        FastyBird:SimpleAuth!
10
 * @subpackage     Application
11
 * @since          1.0.0
12
 *
13
 * @date           01.07.24
14
 */
15

16
namespace FastyBird\SimpleAuth\Application;
17

18
use FastyBird\SimpleAuth;
19
use FastyBird\SimpleAuth\Security;
20
use Nette\Application;
21
use ReflectionClass;
22
use ReflectionMethod;
23

24
/**
25
 * Nette's presenters security trait
26
 *
27
 * @package        FastyBird:SimpleAuth!
28
 * @subpackage     Subscribers
29
 *
30
 * @author         Adam Kadlec <adam.kadlec@fastybird.com>
31
 *
32
 * @method Application\IPresenter getPresenter()
33
 * @method string storeRequest(string $expiration = '+ 10 minutes')
34
 */
35
trait TSimpleAuth
36
{
37

38
        protected SimpleAuth\Configuration $simpleAuthConfiguration;
39

40
        protected Security\AnnotationChecker $annotationChecker;
41

42
        protected Security\User|null $simpleUser = null;
43

44
        public function injectSimpleAuth(
45
                Security\AnnotationChecker $annotationChecker,
46
                SimpleAuth\Configuration $configuration,
47
                Security\User|null $simpleUser = null,
48
        ): void
49
        {
50
                $this->annotationChecker = $annotationChecker;
×
51
                $this->simpleAuthConfiguration = $configuration;
×
52
                $this->simpleUser = $simpleUser;
×
53
        }
54

55
        /**
56
         * @param mixed $element
57
         *
58
         * @throws Application\ForbiddenRequestException
59
         * @throws Application\UI\InvalidLinkException
60
         */
61
        public function checkRequirements(ReflectionClass|ReflectionMethod $element): void
62
        {
63
                $redirectUrl = $this->simpleAuthConfiguration->getRedirectUrl([
×
64
                        'backlink' => $this->storeRequest(),
×
65
                ]);
×
66

NEW
67
                $homeUrl = $this->simpleAuthConfiguration->getHomeUrl();
×
68

69
                try {
70
                        parent::checkRequirements($element);
×
71

72
                        if (!$this->annotationChecker->checkAccess(
×
73
                                $this->simpleUser,
×
74
                                $element instanceof ReflectionClass ? $element->name : $element->class,
×
75
                                $element instanceof ReflectionMethod ? $element->name : null,
×
76
                        )) {
×
77
                                throw new Application\ForbiddenRequestException();
×
78
                        }
79
                } catch (Application\ForbiddenRequestException $ex) {
×
80
                        if ($redirectUrl) {
×
NEW
81
                                if ($this->simpleUser->isLoggedIn()) {
×
NEW
82
                                        $this->getPresenter()->redirectUrl($homeUrl);
×
83
                                } else {
NEW
84
                                        $this->getPresenter()->redirectUrl($redirectUrl);
×
85
                                }
86
                        } else {
87
                                throw $ex;
×
88
                        }
89
                }
90
        }
91

92
}
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