Skip to content

Commit

Permalink
Merge branch 'crown-requests' of https://github.com/Ansteorra/KMP int…
Browse files Browse the repository at this point in the history
…o crown-requests
  • Loading branch information
jhandel committed Nov 1, 2024
2 parents fbfd93d + c21372e commit ba1deb4
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
* You can remove these routes once you've connected the
* routes you want in your application.
*/

$builder->fallbacks();
});
$routes->connect('/keepalive', ['controller' => 'Sessions', 'action' => 'keepalive']);
$routes->scope('/images', function ($routes) {
$routes->registerMiddleware('glide', new \ADmad\Glide\Middleware\GlideMiddleware([
// Run this middleware only for URLs starting with specified string. Default null.
Expand Down Expand Up @@ -157,4 +159,4 @@
* });
* ```
*/
};
};
6 changes: 3 additions & 3 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AuthorizationApprovalsController extends AppController
public function index()
{
$search = $this->request->getQuery("search");

$search = $search ? trim($search) : null;

$query = $this->AuthorizationApprovals
Expand Down Expand Up @@ -58,11 +59,26 @@ public function index()
),
])
->group("Approvers.id");

if ($search) {
//detect th and replace with Þ
$nsearch = $search;
if (preg_match("/th/", $search)) {
$nsearch = str_replace("th", "Þ", $search);
}
//detect Þ and replace with th
$usearch = $search;
if (preg_match("/Þ/", $search)) {
$usearch = str_replace("Þ", "th", $search);
}
$query = $query->where([
"OR" => [
"Approvers.sca_name LIKE" => "%" . $search . "%",
"Approvers.email_address LIKE" => "%" . $search . "%",
["Approvers.sca_name LIKE" => "%" . $search . "%"],
["Approvers.sca_name LIKE" => "%" . $nsearch . "%"],
["Approvers.sca_name LIKE" => "%" . $usearch . "%"],
["Approvers.email_address LIKE" => "%" . $search . "%"],
["Approvers.email_address LIKE" => "%" . $nsearch . "%"],
["Approvers.email_address LIKE" => "%" . $usearch . "%"],
],
]);
}
Expand Down Expand Up @@ -281,4 +297,4 @@ public function deny(AuthorizationManagerInterface $maService, $id = null)

return $this->redirect($this->referer());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public function request(
return false;
}
}
//Checking for existing pending requests
$existingRequests = $table
->find()
->where([
"member_id" => $requesterId,
"activity_id" => $activityId,
"status" => Authorization::PENDING_STATUS
])
->count();
if ($existingRequests > 0) {
return false;
}


$auth = $table->newEmptyEntity();
$auth->member_id = $requesterId;
$auth->activity_id = $activityId;
Expand Down Expand Up @@ -534,4 +548,4 @@ private function saveAuthorizationApproval(
}

// endregion
}
}
25 changes: 25 additions & 0 deletions app/src/Controller/SessionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Controller;

use Cake\Http\ServerRequest;
use Cake\Http\Response;

class SessionsController extends AppController
{
public function keepalive()
{

// $session = $this->request->getSession();
// if ($session->check('count')) {
// $session->write(['count' => $session->read('count') + 1]);
// } else {
// $session->write(['count' => 1]);
// }
$response = $this->response;
$response = $response->withStringBody('My Body');
$response = $response->withType('application/json')
->withStringBody(json_encode(['response' => 'Session extended']));
return $response;
}
}
7 changes: 7 additions & 0 deletions app/templates/layout/TwitterBootstrap/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
?>

<body <?= $this->fetch("tb_body_attrs") ?>>
<?php
echo $this->Html->script('sessionExtender')
?>
<script>
url = <?= json_encode((empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]" . "/keepalive") ?>;
extendSesh(url)
</script>
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<div class="navbar-brand col-md-3 col-lg-2 me-0 px-3">
<?= $this->Html->image($this->KMP->getAppSetting("KMP.BannerLogo"), [
Expand Down
28 changes: 28 additions & 0 deletions app/templates/layout/TwitterBootstrap/view_record.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
?>

<body <?= $this->fetch("tb_body_attrs") ?>>
<?php
echo $this->Html->script('sessionExtender')
?>
<script>
url = <?= json_encode((empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]" . "/keepalive") ?>;
extendSesh(url)
</script>
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<div class="navbar-brand col-md-3 col-lg-2 me-0 px-3">
<?= $this->Html->image($this->KMP->getAppSetting("KMP.BannerLogo"), [
Expand Down Expand Up @@ -49,6 +56,27 @@
<a class="btn btn-outline-secondary <?= $css ?>" href="<?= $url ?>"><?= $key ?></a>
</li>
<?php endforeach; ?>
<!-- <script>
function extendSesh() {
console.log('start session')
setTimeout(function() {
alert('Session Expiring! Click ok to extend session.');
fetch(
<?= json_encode((empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]" . "/keepalive") ?>
)
.then(res => {
return res.json()
})
.then(data => {
console.log(data.response)
extendSesh()
})

}, 45000)

}
extendSesh()
</script> -->
<li class="nav-item text-nowrap mx-1">
<?= $this->Html->link(
__("Sign out"),
Expand Down
15 changes: 15 additions & 0 deletions app/webroot/js/sessionExtender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function extendSesh(url) {
setTimeout(function () {
alert('Session Expiring! Click ok to extend session.');
fetch(url)
.then(res => {
return res.json()
})
.then(data => {
console.log(data.response)
extendSesh(url)
})
//minutes * 60000 miliseconds per minute
}, 25 * 60000)

}

0 comments on commit ba1deb4

Please sign in to comment.