PHP code example of struktal / struktal-auth

1. Go to this page and download the library: Download struktal/struktal-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

struktal / struktal-auth example snippets


enum PermissionLevel: int implements \struktal\Auth\PermissionLevel {
    // Examples:
    case USER = 0;
    case ADMIN = 1;
    
    public function value(): int {
        return $this->value;
    }
}

class User extends \struktal\ORM\GenericUser {
    #[\struktal\ORM\InheritedType(PermissionLevel::class)]
    public ?PermissionLevel $permissionLevel = null;

    // You can add custom methods or properties here if needed
}

class UserDAO extends \struktal\ORM\GenericUserDAO {
    // You can add custom methods or properties here if needed
}

\struktal\Auth\Auth::setUserObjectName(User::class);

$auth = new \struktal\Auth\Auth();
$user = $auth->enforceLogin(PermissionLevel::USER, Router->generate("nologin"));

$auth = new \struktal\Auth\Auth();
$user = $auth->getLoggedInUser();