Diff #4 - trunk/views/php/admin/settings/security.php
1,907 bytes
|
|
January 20, 2025 at 08:20
|
Diff
Index: security.php
--- security.php (nonexistent) +++ security.php (revision 4) @@ -0,0 +1,71 @@ +<?php +declare(strict_types = 1); + +namespace Views\admin\settings; + +use Apex\Svc{App, View, Container}; +use Apex\Armor\Policy{ArmorPolicy, PolicyManager}; + +/** + * Render the template. + */ +class security +{ + + /** + * Render + */ + public function render(View $view, App $app, Container $cntr, PolicyManager $manager):void + { + + if ($app->getMethod() == 'POST') { + $post = $app->getAllPost(); + + // Set booleans + $booleans = [ + 'create_as_pending', + 'lock_redis_expiration', + 'enable_ipcheck' + ]; + + // Type set booleans + foreach ($booleans as $var) { + $post[$var] = $post[$var] == 1 ? true : false; + } + + // Set integers + $integers = [ + 'min_password_strength', + 'min_username_length', + 'expire_verify_email_secs', + 'expire_verify_phone_secs', + 'expire_session_inactivity_secs', + 'expire_redis_session_secs', + 'remember_device_days', + 'remember_me_days' + ]; + + // Type set integers + foreach ($integers as $var) { + $post[$var] = (int) $post[$var]; + } + + // Generate policy + $policy = $cntr->make(ArmorPolicy::class, $post); + } + + // Create policy + if ($app->getAction() == 'create') { + $manager->savePolicy($app->post('name'), $policy); + $view->addCallout('Successfully created new security policy, ' . $app->post('name')); + // Update policy + } elseif ($app->getAction() == 'update') { + $manager->savePolicy($app->post('policy'), $policy); + $view->addCallout('Successfully updated the security policy, ' . $app->post('policy')); + } + + } + +} + +
Full Code
<?php declare(strict_types = 1);
namespace Views\admin\settings;
use Apex\Svc{App, View, Container}; use Apex\Armor\Policy{ArmorPolicy, PolicyManager};
/** * Render the template. */ class security {
/**
* Render
*/
public function render(View $view, App $app, Container $cntr, PolicyManager $manager):void
{
if ($app->getMethod() == 'POST') {
$post = $app->getAllPost();
// Set booleans
$booleans = [
'create_as_pending',
'lock_redis_expiration',
'enable_ipcheck'
];
// Type set booleans
foreach ($booleans as $var) {
$post[$var] = $post[$var] == 1 ? true : false;
}
// Set integers
$integers = [
'min_password_strength',
'min_username_length',
'expire_verify_email_secs',
'expire_verify_phone_secs',
'expire_session_inactivity_secs',
'expire_redis_session_secs',
'remember_device_days',
'remember_me_days'
];
// Type set integers
foreach ($integers as $var) {
$post[$var] = (int) $post[$var];
}
// Generate policy
$policy = $cntr->make(ArmorPolicy::class, $post);
}
// Create policy
if ($app->getAction() == 'create') {
$manager->savePolicy($app->post('name'), $policy);
$view->addCallout('Successfully created new security policy, ' . $app->post('name'));
// Update policy
} elseif ($app->getAction() == 'update') {
$manager->savePolicy($app->post('policy'), $policy);
$view->addCallout('Successfully updated the security policy, ' . $app->post('policy'));
}
}
}