Skip to content

Internals Admin Admin

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

admin\Admin

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/admin/Admin.php · Snapshot 8411f4287706.

Admin models and authentication manage the framework administrator record and PHP session. Permission levels are compared numerically with lower values granting broader access. Passwords currently use SHA-512.

Imports and dependencies

use /**
 * Class AdminModel
 *
 * This class represents the model for handling administrative operations
 * within the application. It includes methods for managing data interactions
 * related to administration and provides functionalities to interact with
 * the database, retrieve and modify data specific to administrative needs.
 *
 * Responsibility:
 * - Contains logic for handling administrative data.
 * - Interacts with the database for creating, reading, updating, or deleting
 *   administrative records or entities.
 * - Acts as a bridge between the database layer and the controller layer
 *   specific to administrative modules.
 */
    admin\model\AdminModel;

Admin

Declaration and architectural role

class Admin extends AdminModel

Source description (behavioral corrections are recorded in Known discrepancies):

Class Admin.

Handles administrative-level functionalities including authentication, permission checks, and session management.

Constants, enum cases, traits and properties

No own constants, enum cases, traits or property declarations. Inherited members are documented on the parent reference page.

Method index

Method Signature
__construct public function __construct()
checkPermission public function checkPermission(int $level): bool
checkAuthentication public function checkAuthentication(): bool
logout public function logout(): void

__construct

Source line 43

public function __construct()

Constructor method for Admin.

Calls the parent constructor from AdminModel to initialize the admin model.

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
/**
     * Constructor method for Admin.
     *
     * Calls the parent constructor from AdminModel to initialize
     * the admin model.
     */
    public function __construct() {
        parent::__construct();
    }

checkPermission

Source line 58

public function checkPermission(int $level): bool

Parameters

Parameter Type, modifiers and default Purpose
$level int $level The permission level to check against.

Checks if the administrator has permission at a specified level.

Compares the current administrator's permission level with the provided level and returns true if the current level is less than or equal to the specified level.

@param int $level The permission level to check against. @return bool Returns true if the administrator has the required permission level, false otherwise.

Return expressions (including local callbacks): true; false.

Implementation, validation guards and interaction order
/**
     * Checks if the administrator has permission at a specified level.
     *
     * Compares the current administrator's permission level with the
     * provided level and returns true if the current level is less than
     * or equal to the specified level.
     *
     * @param int $level The permission level to check against.
     * @return bool Returns true if the administrator has the required
     * permission level, false otherwise.
     */
    public function checkPermission(int $level): bool
    {
        if($this->getParam("permission_level") <= $level) {
            return true;
        }
        return false;
    }

checkAuthentication

Source line 76

public function checkAuthentication(): bool

Checks if the administrator is authenticated based on the session token.

This method ensures that a session is started and verifies that the stored token matches the token in the session. Returns true if authenticated, false otherwise.

@return bool Returns true if the administrator is authenticated, false otherwise.

Return expressions (including local callbacks): false; true.

External effects include session_start.

Implementation, validation guards and interaction order
/**
     * Checks if the administrator is authenticated based on the session token.
     *
     * This method ensures that a session is started and verifies that
     * the stored token matches the token in the session. Returns true
     * if authenticated, false otherwise.
     *
     * @return bool Returns true if the administrator is authenticated,
     * false otherwise.
     */
    public function checkAuthentication(): bool
    {
        if(!isset($_SESSION)) {
            session_start();
        }

        if($this->token === null) {
            return false;
        }

        if($this->token !== $_SESSION['admin']['token']) {
            return false;
        }

        return true;
    }

logout

Source line 101

public function logout(): void

Logs out the administrator by clearing the session.

This method unsets the admin session to effectively log the administrator out.

@return void

Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.

Implementation, validation guards and interaction order
/**
     * Logs out the administrator by clearing the session.
     *
     * This method unsets the admin session to effectively log the
     * administrator out.
     *
     * @return void
     */
    public function logout(): void
    {
        unset($_SESSION['admin']);
    }

Related types

Clone this wiki locally