make_sure_allowed()
public function make_sure_allowed(string $scenario = 'admin panel', array $params = []): mixed
Description
Centralised authorization method that routes access control checks to the appropriate module based on the supplied scenario. By default, it validates that the current user has a valid admin-level token (user level 1).
In development mode (ENV === 'dev'), convenience features streamline authentication. In production, unauthenticated users are always redirected to the login page.
Parameters
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
| scenario | string | The security context to check. Defaults to 'admin panel' which checks for a valid token with user level 1. Additional scenarios such as 'members area' can be defined in your application. |
'admin panel' | No |
| params | array | Optional parameters for fine-grained access control. For example, passing a record ID for ownership checks. | [] | No |
Return Value
| Type | Description |
|---|---|
| mixed | Returns a token string, boolean, object, array, or custom value depending on the scenario. Redirects to login if authentication fails. |
Example Usage
PHP
<?php
// Default admin panel check
$this->trongate_security->make_sure_allowed();
// Explicit admin panel check (same as above)
$this->trongate_security->make_sure_allowed('admin panel');
// Members area check (requires custom scenario)
$this->trongate_security->make_sure_allowed('members area');
// With additional parameters for ownership checks
$this->trongate_security->make_sure_allowed('edit comment', [
'comment_id' => 42
]);