Skip to content

Commit

Permalink
property authAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbadxiii committed Apr 13, 2022
1 parent 615ae4e commit 35090ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,25 @@ class ProfileController extends Controller implements Accessicate
}
...
}
```

or just use the `$authAccess` property in the controller, adjusting with the help of `false` and `true` access to the controller

```php
declare(strict_types=1);

namespace App\Controllers;

use Phalcon\Mvc\Controller;

class ProfileController extends Controller
{
//access to the controller only when the user is logged in
public $autAccess = true;
}
```


5. Create middleware extends from `Sinbadxiii\PhalconAuth\Middlewares\Authenticate`

example:
Expand Down
12 changes: 10 additions & 2 deletions src/Middlewares/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
use Phalcon\Di\Injectable;
use Phalcon\Mvc\Dispatcher;

/**
* Class Authenticate
* @package Sinbadxiii\PhalconAuth\Middlewares
*/
class Authenticate extends Injectable implements AuthenticatesRequest
{
private const PROPERTY_AUTH_ACCESS = "authAccess";

/**
* @var
* @var Dispatcher
*/
protected Dispatcher $dispatcher;

Expand Down Expand Up @@ -54,6 +60,8 @@ protected function isGuest()
{
$controller = $this->dispatcher->getControllerClass();

return !(new $controller)->authAccess();
return !(new $controller)->authAccess() ||
(property_exists($controller, self::PROPERTY_AUTH_ACCESS) &&
(new $controller)->authAccess === false);
}
}

0 comments on commit 35090ae

Please sign in to comment.