From da565f3f9160b6f73ae9c71cd10f2901ccb34030 Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 15 May 2024 14:24:01 +0200 Subject: [PATCH] fix: [autkey expiration] has to be in the future --- src/Model/Table/AuthKeysTable.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Model/Table/AuthKeysTable.php b/src/Model/Table/AuthKeysTable.php index f5336e6..f20299e 100644 --- a/src/Model/Table/AuthKeysTable.php +++ b/src/Model/Table/AuthKeysTable.php @@ -29,7 +29,7 @@ class AuthKeysTable extends AppTable public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) { $data['created'] = time(); - if (empty($data['expiration'])) { + if (!isset($data['expiration'])) { $data['expiration'] = 0; } else { $data['expiration'] = strtotime($data['expiration']); @@ -56,7 +56,16 @@ class AuthKeysTable extends AppTable { $validator ->notEmptyString('user_id') - ->requirePresence(['user_id'], 'create'); + ->requirePresence(['user_id'], 'create') + ->add('expiration', 'custom', [ + 'rule' => function ($value, $context) { + if ($value && $value < time()) { + return false; + } + return true; + }, + 'message' => __('Expiration date/time has to be in the future.') + ]); return $validator; }