Initial public push: docs cosmos v4 + AI module + framework groundwork

This is the snapshot the production landing site (nibiru-framework.com) is
deployed from. Brings together the recent splash + docs migration to the v4
"Cosmos" design system, the new in-framework AI module, and the framework
groundwork that backs the framework-reference extraction.

What lands:
- docs/: Astro + Starlight site with the v4 dark cosmic palette, GalaxyHero
  canvas constellation, Mission Control chat (wired to /api/oracle →
  api.neuronetz.ai via providers.mjs Ollama), 5-panel MMVC stage
  (Model · AI · Module · Controller · View), translated EN/DE/JA/ES/FR
  content, PWA + sitemap + llms.txt + Umami analytics.
- docs/design-system/: canonical mockup bundle (source/index-v2.html for
  splash, source/docs-system.html + preview/ for docs, SPEC.md, tokens).
- docs/scripts/extraction/framework-reference-v2.md: deep framework
  reference (~1.6k lines, file:line citations, every public factory and
  idiom — basis for the LoRA training corpus.
- application/module/ai/: AI module with chat / embed / RAG / agent
  plugins, plus pdoQuery / httpGet / fileRead tools and Modelfile +
  smoke-test in training/.
- application/module/users/: user / ACL / form-factory traits used as the
  reference plugin pattern for the framework docs.
- application/settings/config/database/: schema + seed migrations
  including the AI module tables (200–203).
- Form factory + autogenerator changes the framework-reference-v2 covers.

Production secrets stay out: docs/.env, settings.production.ini and
ai.production.ini are all gitignored (.example files are in tree).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
stephan
2026-05-08 15:22:18 +02:00
parent a60ce90643
commit 48c839d927
662 changed files with 172811 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace Nibiru\Module\Users\Interfaces;
/**
* @desc this file is for the autoloader to function properly,
* you might as well use it as the primary user interface for your
* application
* Created by PhpStorm.
* User: kasdorf
* Date: 28.08.18
* Time: 11:21
*/
interface Users
{
const CONFIG_MODULE_NAME = 'users';
const FORM_CREATE_USER = [
[ 'visibleName' => 'Benutzername', 'valueName' => 'user_login', 'icon' => 'lock' ],
[ 'visibleName' => 'Vorname', 'valueName' => 'user_firstname', 'icon' => 'user' ],
[ 'visibleName' => 'Nachname', 'valueName' => 'user_lastname', 'icon' => 'user' ],
];
const FORM_CREATE_PASSWORD = [
[ 'visibleName' => 'Passwort', 'valueName' => 'user_pass', 'icon' => 'lock' ],
[ 'visibleName' => 'Passwort wiederholen', 'valueName' => 'password_repeat', 'icon' => 'lock' ],
];
const FORM_CREATE_ACCOUNT = [
[ 'visibleName' => 'Konto Name', 'valueName' => 'user_account_name', 'icon' => 'wallet' ],
[ 'visibleName' => 'Konto Email', 'valueName' => 'user_account_email', 'icon' => 'email' ]
];
const REGISTRY_USER_KEYS = [
'user_firstname',
'user_lastname',
'user_login',
'user_active',
'user_acl_id',
'user_account_name',
'user_account_active',
'user_account_email',
'user_pass'
];
const FORM_CHECKBOX_SWITCH = [
'on' => true,
'off' => false
];
const FORM_CHECKBOX_ON = "on";
const FORM_CHECKBOX_OFF = "off";
const USER_ID_ENCRYPTION = 'user_id_encryption';
const USER_ID_ENCRYPTION_KEY = 'user_id_encryption_key';
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Nibiru\Module\Users\Plugins;
/**
* Class Acl
* @project Lagerverwaltung
* @desc This is the ACL plugin for the users module. It checks if the user is logged in or not, and also loads the corresponding
* user role into the session.
* @author stephan - Maschinen Stockert Großhandels GmbH
* @date 26.01.23
* @time 11:38
* @package Nibiru\Module\Users\Plugins
*/
use Nibiru\View;
use Nibiru\Factory\Db;
class Acl extends User
{
/**
* @desc Acl constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* @desc checks if the users is logged into the system, if yes nothing happens,
* if no it redirects to the login page.
* @return void
*/
public function init(): void
{
if(!$this->validate())
{
View::forwardTo('/users/login');
}
else
{
$this->loadUserRole();
}
}
/**
* @desc checks if the user is logged in, if yes it loads the corresponding user role into the session.
* @return void
* [auth] => Array
(
[session_id] => SESSION_ID
[user_id] => USER_ID
[login] => USER_LOGIN
[role] => ACL_ROLE
)
*/
public function loadUserRole(): void
{
if(User::validate())
{
$userRole = User::getRoleByLoggedInUser();
$_SESSION['auth']['role'] = $userRole['acl_role'];
}
}
/**
* @desc will load the acl roles from the database and return them as an array.
* @return array
* @throws \Exception
*/
public function loadAclRoles(): array
{
$acl = Db::loadModel('WarehouseLoach\Acl');
return $acl->loadTableAsArray();
}
}

View File

@@ -0,0 +1,516 @@
<?php
namespace Nibiru\Module\Users\Plugins;
/**
* Class Users
* @package Nibiru\Module\Users\Plugins
* @author: Stephan Kasdorf
* @date: 04.09.20
* @copyright: 2020 Nibiru Framework, you may copy the code,
* but have to inform the author about where it
* is used. So happy copying.
* @licence: BSD 4-Old License
*/
use Nibiru\Auth;
use Nibiru\Controller;
use Nibiru\Config;
use Nibiru\Module\Error\Plugins\Message;
use Nibiru\Module\Memcached\Plugins\Memcached;
use Nibiru\Module\Users\Traits\UserForm;
use Nibiru\Module\Users\Users;
use Nibiru\Factory\Db;
use Nibiru\IView;
use Nibiru\Pdo;
use Nibiru\Model\WarehouseLoach;
class User extends Users
{
use UserForm;
//check from auth in order to determine if user may login to the system
private bool $_auth;
private object $userRegistry;
private string $status;
private int $userId;
public function __construct()
{
parent::__construct();
return $this;
}
/**
* @desc authenticates user in the system and stores the session in order to verify the
* the login, then set the session and return true if the user is logged in.
* Will update the timeanddate_time field in the timeanddate table with the current time.
* @return bool
*/
public function validate( ): bool
{
if(array_key_exists('login', Controller::getInstance()->getRequest('', true)) && array_key_exists('password', Controller::getInstance()->getRequest('', true)))
{
$this->_auth = Auth::getInstance()->auth(
Controller::getInstance()->getRequest('login'),
Controller::getInstance()->getRequest('password'));
if($this->_auth)
{
$timeanddateToUser = Db::loadModel('WarehouseLoach\timeanddateToUser')->selectDatasetByFieldWhere(['name' => 'user_id', 'value' => Controller::getInstance()->getSession('auth')['user_id']]);
$timeanddate_id = array_shift($timeanddateToUser)['timeanddate_id'];
Db::loadModel('WarehouseLoach\timeanddate')->updateRowByFieldWhere('timeanddate_id', $timeanddate_id, 'timeanddate_time', date('Y-m-d H:i:s'));
$this->setUserIdToSessionCookie();
}
}
else
{
$this->_auth = $this->isAuthorized();
}
return $this->_auth;
}
/**
* @desc will return true if the user is authorized otherwise false
* @return bool
*/
public function isAuthorized(): bool
{
if(array_key_exists('auth', Controller::getInstance()->getSession('', true)))
{
if(array_key_exists('login', Controller::getInstance()->getSession('auth')))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
/**
* @desc will log out the user and destroy the session
* @return bool
*/
public function revokeAuthorized(): bool
{
setcookie('user_id', '', [
'expires' => time() - 3600, // set the cookie to expire one hour ago
'path' => '/',
'secure' => false,
'httponly' => true,
]);
Memcached::init()->runServer()->delete($_SESSION['auth']['user_id']);
unset($_SESSION['auth']);
return true;
}
/**
* @desc will update the password of the user, check if the value $user_id is set, if not it will use the current logged in user.
* @param int $user_id
* @param string $password
* @return bool
*/
public function updatePassword(string $password, int $user_id): bool
{
if($user_id == 0)
{
$user_id = $_SESSION['auth']['user_id'];
}
return Pdo::query('UPDATE user SET user_pass = DES_ENCRYPT("'.$password.'", "'.Config::getInstance()->getConfig()[IView::NIBIRU_SECURITY]["password_hash"].'") WHERE user_id = '.$user_id.';');
}
/**
* @desc will return true if the standard user is present otherwise false
* @return bool
* @throws \Exception
*/
public function checkForStandardUser(): bool
{
$userTable = Db::loadModel('WarehouseLoach\user')->loadTableAsArray();
if(sizeof($userTable)==0)
{
return false;
}
else
{
$standardUser = array_search(self::getUsersRegistry()->user_login, array_column($userTable, 'user_login'));
if($standardUser === false)
{
return false;
}
else
{
return true;
}
}
}
/**
* @desc will check if the user exists in the database
* @param string $user_login
* @return bool
*/
public function checkIfUserExists(string $user_login): bool
{
$userTable = Db::loadModel('WarehouseLoach\user')->loadTableAsArray();
$user = array_search($user_login, array_column($userTable, 'user_login'));
if($user === false)
{
return false;
}
else
{
return true;
}
}
/**
* @desc create an object that loads the userdata from the registry, if the user data is not passed by the method
* parameter. Also prepares the user data for user updates in the database.
* @param array $user_data
* @param bool $isUpdate
* @return bool
*/
public function loadUser( array $user_data = [], bool $isUpdate = false ): bool
{
$this->userRegistry = new \stdClass();
if(sizeof($user_data) == 0)
{
foreach(self::REGISTRY_USER_KEYS as $key)
{
$this->userRegistry->$key = self::getUsersRegistry()->$key;
}
return Message::loadInfo('User loaded', ['info' => json_decode(json_encode($this->userRegistry), true)]);
}
else
{
try {
if(!$this->checkIfUserExists($user_data['user_login']) || $isUpdate)
{
foreach(self::REGISTRY_USER_KEYS as $key)
{
if($user_data[$key] == self::FORM_CHECKBOX_ON || $user_data[$key] == self::FORM_CHECKBOX_OFF)
{
$user_data[$key] = self::FORM_CHECKBOX_SWITCH[$user_data[$key]];
}
$this->userRegistry->$key = $user_data[$key];
}
if($isUpdate)
{
$this->userRegistry->user_id = $user_data['user_id'];
}
return Message::loadInfo('User loaded', ['info' => json_decode(json_encode($this->userRegistry), true)]);
} else
{
throw new \Exception('User already exists');
}
} catch (\Exception $e) {
return Message::loadError($e);
}
}
}
/**
* @desc will create the initial user for the system, if no user is setup.
* Can be found in the application/module/users/settings/users.ini
* file.
* @return int|bool
* @throws \Exception
*/
public function createStandardUser(): int|bool
{
try {
Db::loadModel('WarehouseLoach\user')->insertArrayIntoTable([
'user_firstname' => $this->userRegistry->user_firstname,
'user_lastname' => $this->userRegistry->user_lastname,
'user_login' => $this->userRegistry->user_login,
'user_account_active' => $this->userRegistry->user_active
]);
$lastUserId = Db::loadModel('WarehouseLoach\user')->lastInsertId();
Db::loadModel('WarehouseLoach\timeanddate')->insertArrayIntoTable([
]);
$lastTimeanddateId = Db::loadModel('WarehouseLoach\timeanddate')->lastInsertId();
Db::loadModel('WarehouseLoach\timeanddateToUser')->insertArrayIntoTable([
'timeanddate_id' => $lastTimeanddateId,
'user_id' => $lastUserId
]);
Db::loadModel('WarehouseLoach\userToAcl')->insertArrayIntoTable([
'user_id' => $lastUserId,
'acl_id' => $this->userRegistry->user_acl_id
]);
Db::loadModel('WarehouseLoach\account')->insertArrayIntoTable([
'account_name' => $this->userRegistry->user_account_name,
'account_email' => $this->userRegistry->user_account_email,
'account_active' => $this->userRegistry->user_account_active
]);
$lastAccountId = Db::loadModel('WarehouseLoach\account')->lastInsertId();
Db::loadModel('WarehouseLoach\timeanddate')->insertArrayIntoTable([
]);
$lastTimeanddateId = Db::loadModel('WarehouseLoach\timeanddate')->lastInsertId();
Db::loadModel('WarehouseLoach\timeanddateToAccount')->insertArrayIntoTable([
'account_id' => $lastAccountId,
'timeanddate_id' => $lastTimeanddateId
]);
Db::loadModel('WarehouseLoach\userToAccount')->insertArrayIntoTable([
'account_id' => $lastAccountId,
'user_id' => $lastUserId
]);
$setPassword = Pdo::query('UPDATE user SET user_pass = DES_ENCRYPT("'.$this->userRegistry->user_pass.'", "'.Config::getInstance()->getConfig()[IView::NIBIRU_SECURITY]["password_hash"].'") WHERE user_id = '.$lastUserId.';');
if(empty($setPassword))
{
return $lastUserId;
}
else
{
throw new \Exception('Could not set password for user '.$lastUserId . ' with exception value: ' . $setPassword . '!');
}
} catch (\Exception $e) {
return Message::loadError($e);
}
}
/**
* @desc will return the role of the logged in user
* @return array
* @throws \Exception
*/
public function getRoleByLoggedInUser(): array
{
$userToAcl = Db::loadModel('WarehouseLoach\userToAcl')->selectRowByFieldWhere([
'field' => 'user_id',
'value' => $_SESSION['auth']['user_id']
]);
return Db::loadModel('WarehouseLoach\acl')->selectRowByFieldWhere([
'field' => 'acl_id',
'value' => $userToAcl['acl_id']
]);
}
/**
* @desc will load all users from the database and return them as an array
* @return array
*/
public function loadUsers(): array
{
return Pdo::queryString('select u.user_id as uid,
u.user_firstname as vorname,
u.user_lastname as nachname,
u.user_login as login,
u.user_account_active as aktiv,
a.acl_role as berechtigung,
tad.timeanddate_date as datum_benutzer,
tad.timeanddate_time as zeit_benutzer,
ac.account_name as konto,
ac.account_email as konto_email,
ac.account_active as konto_aktiv,
tadc.timeanddate_date as datum_konto,
tadc.timeanddate_time as zeit_konto
from warehouse_loach.user as u
join warehouse_loach.user_to_acl as uta on u.user_id = uta.user_id
join warehouse_loach.acl as a on uta.acl_id = a.acl_id
join warehouse_loach.timeanddate_to_user as ttu on u.user_id = ttu.user_id
join warehouse_loach.timeanddate as tad on ttu.timeanddate_id = tad.timeanddate_id
join user_to_account uta2 on u.user_id = uta2.user_id
join account ac on uta2.account_id = ac.account_id
join timeanddate_to_account tta on ac.account_id = tta.account_id
join timeanddate tadc on tta.timeanddate_id = tadc.timeanddate_id;', true);
}
/**
* @desc will load a user by the given id
* @param int $user_id
* @return array
*/
public function loadUserById( int $user_id ): array
{
$user = Pdo::queryString('select u.user_id as uid,
u.user_firstname as user_firstname,
u.user_lastname as user_lastname,
u.user_login as user_login,
DES_DECRYPT(u.user_pass, "'.Config::getInstance()->getConfig()[IView::NIBIRU_SECURITY]["password_hash"].'") as user_pass,
u.user_account_active as user_account_active,
a.acl_id as user_role_id,
ac.account_name as user_account_name,
ac.account_active as user_account_active,
ac.account_email as user_account_email
from warehouse_loach.user as u
join warehouse_loach.user_to_acl as uta on u.user_id = uta.user_id
join warehouse_loach.acl as a on uta.acl_id = a.acl_id
join warehouse_loach.timeanddate_to_user as ttu on u.user_id = ttu.user_id
join warehouse_loach.timeanddate as tad on ttu.timeanddate_id = tad.timeanddate_id
join user_to_account uta2 on u.user_id = uta2.user_id
join account ac on uta2.account_id = ac.account_id
join timeanddate_to_account tta on ac.account_id = tta.account_id
join timeanddate tadc on tta.timeanddate_id = tadc.timeanddate_id
where u.user_id = '.$user_id.';', true);
$user = array_shift($user);
return $user;
}
/**
* @desc will delete a user by the given id
* @param int $user_id
* @return bool
*/
public function deleteUserById( int $user_id ): bool
{
try {
$user = $this->loadUserById($user_id);
if($user['user_role_id'] == 1)
{
unset($user);
throw new \Exception('You can not delete the superuser!');
}
else
{
$userToAccount = Pdo::queryString('SELECT account_id FROM user_to_account WHERE user_id = '.$user_id.';', true);
$account_id = array_shift($userToAccount)["account_id"];
$timeanddateToUser = Pdo::queryString('SELECT timeanddate_id FROM timeanddate_to_user WHERE user_id = '.$user_id.';', true);
$timeanddate_id = array_shift($timeanddateToUser)["timeanddate_id"];
Pdo::query('DELETE FROM user_to_acl WHERE user_id = '.$user_id.';');
Pdo::query('DELETE FROM user_to_account WHERE user_id = '.$user_id.';');
Pdo::query('DELETE FROM timeanddate_to_user WHERE user_id = '.$user_id.';');
Pdo::query('DELETE FROM timeanddate_to_account WHERE account_id = '.$account_id.';');
Pdo::query('DELETE FROM user WHERE user_id = '.$user_id.';');
Pdo::query('DELETE FROM account WHERE account_id = '.$account_id.';');
Pdo::query('DELETE FROM timeanddate WHERE timeanddate_id = '.$timeanddate_id.';');
unset($user['user_pass']);
return Message::loadInfo("User deleted successfully", $user);
}
} catch (\Exception $e) {
return Message::loadError($e);
}
}
/**
* @desc will set the user active or inactive
* @param int $user_id
* @param int $active
* @return bool
*/
public function setUserActive( int $user_id, int $active ): bool
{
try {
if($active)
{
$state = '<span class="badge badge-success">Aktiv</span>';
}
else
{
$state = '<span class="badge badge-danger">Inaktiv</span>';
}
$user = $this->loadUserById($user_id);
if($user['user_role_id'] == 1)
{
unset($user);
throw new \Exception('You can not deactivate the superuser!');
}
else
{
Db::loadModel('WarehouseLoach\User')->updateRowByFieldWhere('user_id', $user_id, 'user_account_active', $active);
unset($user['user_pass']);
return Message::loadInfo("User updated active state successfully: $state", $user);
}
} catch (\Exception $e) {
return Message::loadError($e);
}
}
/**
* @desc will update the user by the given user array
* @return bool
* @throws \Exception
*/
public function updateUser(): bool
{
try {
$user = (array) $this->userRegistry;
$userString = '';
foreach(WarehouseLoach\User::TABLE['fields'] as $field)
{
if(array_key_exists($field, $user))
{
if($field == 'user_pass')
{
$userString .= $field.' = DES_ENCRYPT("'.$user[$field].'", "'.Config::getInstance()->getConfig()[IView::NIBIRU_SECURITY]["password_hash"].'"), ';
}
else
{
if($field != 'user_id')
{
$userString .= $field.' = "'.$user[$field].'", ';
}
}
}
}
Pdo::query('UPDATE user SET '.substr($userString, 0, -2).' WHERE user_id = '.$user['user_id'].';');
$userToAccount = Db::loadModel('WarehouseLoach\userToAccount')->selectDatasetByFieldWhere(['name' => 'user_id', 'value' => $user['user_id']]);
$account_id = array_shift($userToAccount)['account_id'];
if(isset($account_id))
{
$accountString = '';
foreach(WarehouseLoach\Account::TABLE['fields'] as $field)
{
foreach($user as $key => $value)
{
if(strstr($key, $field))
{
$accountString .= $field.' = "'.$user[$key].'", ';
}
}
}
Pdo::query('UPDATE account SET '.substr($accountString, 0, -2).' WHERE account_id = '.$account_id.';');
}
else
{
throw new \Exception('Did not get valid Account ID, the database could be corrupted for that user! user_id: ' . $user['user_id']);
}
Db::loadModel('WarehouseLoach\userToAcl')->updateRowByFieldWhere('user_id', $user['user_id'], 'acl_id', $user['user_acl_id']);
} catch (\Exception $e) {
Message::loadError($e);
}
}
/**
* @desc will set the user_id in a cookie, in order to find the memcached session
* @return void
*/
public function setUserIdToSessionCookie(): void
{
if(!array_key_exists('user_id', $_COOKIE) && array_key_exists('auth', $_SESSION))
{
$ivLength = openssl_cipher_iv_length($this->getUsersRegistry()->{self::USER_ID_ENCRYPTION});
$iv = openssl_random_pseudo_bytes($ivLength);
$encryptedUserId = openssl_encrypt($_SESSION['auth']['user_id'], $this->getUsersRegistry()->{self::USER_ID_ENCRYPTION}, $this->getUsersRegistry()->{self::USER_ID_ENCRYPTION_KEY}, 0, $iv);
$cookieValue = base64_encode($encryptedUserId . '::' . $iv);
setcookie('user_id', $cookieValue, [
'expires' => time() + (86400 * 30),
'path' => '/',
'secure' => false, // only send cookie over https
'httponly' => true, // make the cookie inaccessible to javascript
]);
}
}
/**
* @desc will get the user_id from the cookie
* @return int
*/
public function getUserIdFromSessionCookie(): int
{
if(array_key_exists('user_id', $_COOKIE))
{
list($encryptedUserId, $iv) = explode('::', base64_decode($_COOKIE['user_id']), 2);
$decryptedUserId = openssl_decrypt($encryptedUserId, $this->getUsersRegistry()->{self::USER_ID_ENCRYPTION}, $this->getUsersRegistry()->{self::USER_ID_ENCRYPTION_KEY}, 0, $iv);
return $decryptedUserId;
}
else
{
return 0;
}
}
}

View File

@@ -0,0 +1,71 @@
[USERS]
name = "users"
path = "/application/module/users"
is_api = false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Start User when no user is part of the system
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
user_firstname = "{user_firstname}"
user_lastname = "{user_lastname}"
user_pass = "{GENERATE_PASSWORD}"
user_login = "{user_login}"
user_active = true
user_account_name = "admin"
user_account_active = true
user_account_email = "{user_account_email}"
user_acl_id = 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;User Cookie // Session handling
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
user_id_encryption = "AES-256-CBC"
user_id_encryption_key = "B4D4F6H8J0K2L4N6"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Login css files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
users_login_css[] = "/public/css/vendors_css.css"
users_login_css[] = "/public/css/style.css"
users_login_css[] = "/public/css/skin_color.css"
users_login_js[] = "/public/js/vendors.min.js"
users_login_js[] = "/public/js/pages/chat-popup.js"
users_login_js[] = "/public/assets/icons/feather-icons/feather.min.js"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;User listing css/js files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
users_user-list_css[] = "/public/css/vendors_css.css"
users_user-list_css[] = "/public/css/style.css"
users_user-list_css[] = "/public/css/skin_color.css"
users_user-list_js[] = "/public/js/vendors.min.js"
users_user-list_js[] = "/public/js/pages/chat-popup.js"
users_user-list_js[] = "/public/assets/icons/feather-icons/feather.min.js"
users_user-list_js[] = "/public/assets/vendor_components/perfect-scrollbar-master/perfect-scrollbar.jquery.min.js"
users_user-list_js[] = "/public/assets/vendor_components/datatable/datatables.min.js"
users_user-list_js[] = "/public/js/template.js"
users_user-list_js[] = "/public/js/pages/data-table.js"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;User new css/js files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
users_user-new_css[] = "/public/css/vendors_css.css"
users_user-new_css[] = "/public/css/style.css"
users_user-new_css[] = "/public/css/skin_color.css"
users_user-new_js[] = "/public/js/vendors.min.js"
users_user-new_js[] = "/public/js/pages/chat-popup.js"
users_user-new_js[] = "/public/assets/icons/feather-icons/feather.min.js"
users_user-new_js[] = "/public/assets/vendor_components/jquery-toast-plugin-master/src/jquery.toast.js"
users_user-new_js[] = "/public/js/template.js"
users_user-new_js[] = "/public/js/pages/toastr.js"
users_user-new_js[] = "/public/js/pages/notification.js"
users_user-new_js[] = "/public/js/pages/users/new-user.js"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;User edit css/js files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
users_user-edit_css[] = "/public/css/vendors_css.css"
users_user-edit_css[] = "/public/css/style.css"
users_user-edit_css[] = "/public/css/skin_color.css"
users_user-edit_js[] = "/public/js/vendors.min.js"
users_user-edit_js[] = "/public/js/pages/chat-popup.js"
users_user-edit_js[] = "/public/assets/icons/feather-icons/feather.min.js"
users_user-edit_js[] = "/public/assets/vendor_components/jquery-toast-plugin-master/src/jquery.toast.js"
users_user-edit_js[] = "/public/js/template.js"
users_user-edit_js[] = "/public/js/pages/toastr.js"
users_user-edit_js[] = "/public/js/pages/notification.js"
users_user-edit_js[] = "/public/js/pages/users/edit-user.js"

View File

@@ -0,0 +1,359 @@
<?php
namespace Nibiru\Module\Users\Traits;
/**
* Trait UserForm
* @project src
* @desc This is a PHP trait file, please specify the use
* @author stephan - Maschinen Stockert Großhandels GmbH
* @date 19.04.23
* @time 15:10
* @package ${PACKAGE}
*/
use Nibiru\Factory\Form;
use Nibiru\Module\Users\Plugins\Acl;
trait UserForm
{
public static function userForm(string $action = '', array $user = [])
{
$acl = new Acl();
Form::create();
self::openHalfWidthElement('Benutzer Informationen');
self::openInnerHalfWithElement();
foreach(self::FORM_CREATE_USER as $entry)
{
if(sizeof($user) > 0)
{
self::addTextElement($entry['visibleName'], $entry['valueName'], $entry['icon'], $user[$entry['valueName']]);
}
else
{
self::addTextElement($entry['visibleName'], $entry['valueName'], $entry['icon']);
}
}
foreach(self::FORM_CREATE_PASSWORD as $entry)
{
if(sizeof($user) > 0)
{
self::addPasswordElement($entry['visibleName'], $entry['valueName'], $entry['icon'], $user['user_pass']);
}
else
{
self::addPasswordElement($entry['visibleName'], $entry['valueName'], $entry['icon']);
}
}
self::closeHalfWidthElement();
self::closeHalfWidthElement();
self::openHalfWidthElement('Konto Informationen');
self::openInnerHalfWithElement();
foreach(self::FORM_CREATE_ACCOUNT as $entry)
{
if(sizeof($user) > 0)
{
self::addTextElement($entry['visibleName'], $entry['valueName'], $entry['icon'], $user[$entry['valueName']]);
}
else
{
self::addTextElement($entry['visibleName'], $entry['valueName'], $entry['icon']);
}
}
if(sizeof($user) > 0)
{
self::addSelectDropdown($acl->loadAclRoles(), 'lock', $user['user_role_id']);
self::addActiveCheckbox('Konto aktivieren', $user['user_account_active']);
}
else
{
self::addSelectDropdown($acl->loadAclRoles(), 'lock');
self::addActiveCheckbox('Konto aktivieren', true);
}
self::closeHalfWidthElement();
if(sizeof($user) > 0)
{
self::addHiddenElementEditUser($user);
self::addSubmitFormButton('Speichern', 'save-alt');
}
else
{
self::addHiddenElementNewUser();
self::addSubmitFormButton('Erstellen', 'save-alt');
}
self::closeHalfWidthElement();
return Form::addForm([
'name' => 'userForm',
'action' => $action,
'class' => 'row',
'method' => 'post',
'target' => '_self'
]);
}
private static function addHiddenElementNewUser()
{
Form::addTypeHidden([
'name' => 'user_new',
'value' => 1
]);
Form::addTypeHidden([
'name' => 'user_active',
'value' => 1
]);
}
private static function addHiddenElementEditUser(array $user = [])
{
Form::addTypeHidden([
'name' => 'user_edit',
'value' => 1
]);
Form::addTypeHidden([
'name' => 'user_active',
'value' => $user['user_account_active']
]);
Form::addTypeHidden([
'name' => 'user_id',
'value' => $user['uid']
]);
}
private static function addSubmitFormButton(string $buttonText = '', string $icon = '')
{
Form::addOpenDiv([
'class' => 'box-footer text-end',
'value' => ''
]);
Form::addTypeButton([
'class' => 'btn btn-primary',
'type' => 'submit',
'value' => '<i class="ti-'.$icon.'"></i>&nbsp;'.$buttonText
]);
Form::addCloseDiv();
}
/**
* @desc will add a text element to the form
* @param string $visibleName
* @param string $valueName
* @param string $icon
* @return void
*/
private static function addTextElement(string $visibleName = '', string $valueName = '', string $icon = '', string $value = '')
{
Form::addTypeLabel([
'class' => 'form-label',
'for' => $valueName,
'value' => $visibleName
]);
Form::addOpenDiv([
'class' => 'input-group mb-3',
'value' => ''
]);
Form::addOpenAny([
'any' => 'span',
'class' => 'input-group-text',
'value' => '<i class="ti-'.$icon.'"></i>'
]);
Form::addCloseAny([
'any' => 'span'
]);
if($value!="")
{
Form::addInputTypeText([
'class' => 'form-control',
'name' => $valueName,
'placeholder' => $visibleName,
'value' => $value
]);
}
else
{
Form::addInputTypeText([
'class' => 'form-control',
'name' => $valueName,
'placeholder' => $visibleName
]);
}
Form::addCloseDiv();
}
/**
* @desc will add a select dropdown to the form
* @param array $options
* @param string $icon
* @return void
*/
private static function addSelectDropdown( array $options = [], string $icon = '', int $selected = 0 )
{
Form::addTypeLabel([
'for' => 'source-api',
'class' => 'form-label',
'value' => 'Rolle auswählen:'
]);
Form::addOpenDiv([
'class' => 'input-group mb-3',
'value' => ''
]);
Form::addOpenAny([
'any' => 'span',
'class' => 'input-group-text',
'value' => '<i class="ti-'.$icon.'"></i>'
]);
Form::addCloseAny([
'any' => 'span'
]);
foreach($options as $option)
{
if($selected == $option['acl_id'])
{
Form::addSelectOption([
'context' => $option['acl_role'],
'value' => $option['acl_id'],
'selected' => 'selected'
]);
}
else
{
Form::addSelectOption([
'context' => $option['acl_role'],
'value' => $option['acl_id']
]);
}
}
Form::addSelect([
'name' => 'user_acl_id',
'class' => 'form-control select2'
]);
Form::addCloseDiv();
}
/**
* @desc will add a password element to the form
* @param string $visibleName
* @param string $valueName
* @param string $icon
* @return void
*/
private static function addPasswordElement(string $visibleName = '', string $valueName = '', string $icon = '', string $value = '')
{
Form::addTypeLabel([
'class' => 'form-label',
'for' => $valueName,
'value' => $visibleName
]);
Form::addOpenDiv([
'class' => 'input-group mb-3',
'value' => ''
]);
Form::addOpenAny([
'any' => 'span',
'class' => 'input-group-text',
'value' => '<i class="ti-'.$icon.'"></i>'
]);
Form::addCloseAny([
'any' => 'span'
]);
if($value!="")
{
Form::addInputTypePassword([
'class' => 'form-control',
'name' => $valueName,
'placeholder' => $visibleName,
'value' => $value
]);
}
else
{
Form::addInputTypePassword([
'class' => 'form-control',
'name' => $valueName,
'placeholder' => $visibleName
]);
}
Form::addCloseDiv();
}
/**
* @desc will open a half width element for form fields
* @param string $title
* @return void
*/
private static function openHalfWidthElement(string $title = '')
{
Form::addOpenDiv([
'class' => 'col-lg-6 col-13',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'box',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'box-header with-border',
'value' => '<h4 class="box-title">'.$title.'</h4>'
]);
Form::addCloseDiv();
}
/**
* @desc will add the inner half width distance frame element for form fields
* @return void
*/
private static function openInnerHalfWithElement()
{
Form::addOpenDiv([
'class' => 'form-group',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'box-body',
'value' => ''
]);
}
/**
* @desc will add a checkbox for the active user account state
* @param string $visibleTitle
* @param bool $active
* @return void
*/
private static function addActiveCheckbox(string $visibleTitle = '', int $active = 0)
{
Form::addOpenDiv([
'class' => 'form-group', 'value' => ''
]);
Form::addOpenDiv([
'class' => 'checkbox checkbox-success',
'value' => ''
]);
if($active)
{
Form::addInputTypeCheckbox([
'id' => 'checkbox',
'name' => 'user_account_active',
'checked' => true
]);
}
else
{
Form::addInputTypeCheckbox([
'id' => 'checkbox',
'name' => 'account_active'
]);
}
Form::addTypeLabel([
'for' => 'checkbox',
'value' => $visibleTitle
]);
Form::addCloseDiv();
Form::addCloseDiv();
}
/**
* @desc will close the inner half width distance frame element, and the half width element for form fields
* @return void
*/
private static function closeHalfWidthElement()
{
Form::addCloseDiv();
Form::addCloseDiv();
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace Nibiru\Module\Users\Traits;
/**
* @desc this file is for the autoloader to function properly,
* you might as well use it as the primary user trait for your
* application
* Created by PhpStorm.
* User: kasdorf
* Date: 28.08.18
* Time: 11:24
*/
use Nibiru\Factory\Form;
trait Users
{
/**
* @desc this will return the login form
* @return string
*/
public function loginForm(): string
{
Form::create();
//Start form field Username
Form::addOpenDiv([
'class' => 'form-group',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'input-group mb-3',
'value' => ''
]);
Form::addOpenAny([
'any' => 'span',
'class' => 'input-group-text bg-transparent',
'value' => ''
]);
Form::addOpenAny([
'any' => 'i',
'class' => 'ti-user',
'value' => ''
]);
Form::addCloseAny([
'any' => 'i'
]);
Form::addCloseAny([
'any' => 'span'
]);
Form::addInputTypeText([
'class' => 'form-control ps-15 bg-transparent',
'name' => 'login',
'placeholder' => 'Benutzername'
]);
Form::addCloseDiv();
Form::addCloseDiv();
//Start form field Password
Form::addOpenDiv([
'class' => 'form-group',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'input-group mb-3',
'value' => ''
]);
Form::addOpenAny([
'any' => 'span',
'class' => 'input-group-text bg-transparent',
'value' => ''
]);
Form::addOpenAny([
'any' => 'i',
'class' => 'ti-lock',
'value' => ''
]);
Form::addCloseAny([
'any' => 'i'
]);
Form::addCloseAny([
'any' => 'span'
]);
Form::addInputTypePassword([
'class' => 'form-control ps-15 bg-transparent',
'name' => 'password',
'placeholder' => 'Passwort'
]);
Form::addCloseDiv();
Form::addCloseDiv();
//End form field Password
Form::addOpenDiv([
'class' => 'row',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'col-6',
'value' => ''
]);
Form::addCloseDiv();
Form::addOpenDiv([
'class' => 'col-6',
'value' => ''
]);
Form::addOpenDiv([
'class' => 'fog-pwd text-end',
'value' => ''
]);
Form::addOpenAny([
'any' => 'a',
'href' => 'javascript:void(0)',
'class' => 'hover-warning',
'value' => '<i class="ion ion-locked"></i> Passwort vergessen?'
]);
Form::addCloseAny([
'any' => 'a'
]);
Form::addCloseDiv();
Form::addCloseDiv();
Form::addOpenDiv([
'class' => 'col-12 text-center',
'value' => ''
]);
Form::addTypeButton([
'type' => 'submit',
'class' => 'btn btn-danger mt-10',
'value' => 'Anmelden'
]);
Form::addCloseDiv();
Form::addCloseDiv();
return Form::addForm([
'name' => 'loginForm',
'action' => '/users/login',
'method' => 'post',
'target' => '_self'
]);
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Nibiru\Module\Users;
/**
* @desc this file is for the autoloader to function properly,
* you might as well use it as the primary user class for your
* application, the interface an the trait are currently implemented
* Created by PhpStorm.
* User: kasdorf
* Date: 28.08.18
* Time: 11:22
*/
use Nibiru\Module\Users\Interfaces;
use Nibiru\Module\Users\Traits;
use Nibiru\Registry;
use SplSubject;
use SplObserver;
use SplObjectStorage;
class Users implements Interfaces\Users, SplSubject
{
use Traits\Users;
protected static object $usersRegistry;
protected SplObjectStorage $observers;
/**
* Users constructor.
*/
public function __construct()
{
$this->setUsersRegistry();
$this->observers = new SplObjectStorage();
}
/**
* @desc will attach an observer to the observer storage
* @param SplObserver $observer
* @return void
*/
public function attach(SplObserver $observer): void
{
$this->observers->attach($observer);
}
/**
* @desc will detach an observer from the observer storage
* @param SplObserver $observer
* @return void
*/
public function detach(SplObserver $observer): void
{
$this->observers->detach($observer);
}
/**
* @desc will notify all observers
* @return void
*/
public function notify(): void
{
foreach ($this->observers as $observer) {
$observer->update($this);
}
}
/**
* @desc will return the user registry object from the users.ini configuration
* @return object
*/
protected static function getUsersRegistry(): object
{
return self::$usersRegistry;
}
/**
* @desc setter for the user Registry
*/
protected function setUsersRegistry(): void
{
self::$usersRegistry = Registry::getInstance()->loadModuleConfigByName(self::CONFIG_MODULE_NAME);
}
}