seedproject-web/api/app/Controllers/AppController.php

32 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
use App\Components\User;
/**
* AppController SaaS-level base controller.
*
* All UI controllers extend this instead of the core Controller directly.
* Owns app-wide concerns: session user profile injection, shared view data, etc.
* Core framework files (core/Controller.php) are never modified.
*/
class AppController extends Controller {
function __construct() {
parent::__construct();
// Inject the authenticated user's full profile into every view
if (!empty($_SESSION['login']['userid'])) {
$profile = User::profile($_SESSION['login']['userid']);
$this->view->UserProfile = $profile;
// Build tokenized slug for account settings link: "first-last.encryptedId"
if ($profile) {
$namePart = strtolower(trim(($profile['fname'] ?? '') . '-' . ($profile['lname'] ?? ''), '-'));
$namePart = preg_replace('/[^a-z0-9\-]/', '', $namePart);
$token = Functions::encryptData((string)$profile['userid'], HASH_PASSWORD_KEY);
$this->view->UserSlug = $namePart . '.' . $token;
}
}
}
}