fix: [autkey expiration] has to be in the future

dependabot/npm_and_yarn/webroot/theme/braces-3.0.3
iglocska 2024-05-15 14:24:01 +02:00
parent 6907ed2842
commit da565f3f91
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 11 additions and 2 deletions

View File

@ -29,7 +29,7 @@ class AuthKeysTable extends AppTable
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options)
{ {
$data['created'] = time(); $data['created'] = time();
if (empty($data['expiration'])) { if (!isset($data['expiration'])) {
$data['expiration'] = 0; $data['expiration'] = 0;
} else { } else {
$data['expiration'] = strtotime($data['expiration']); $data['expiration'] = strtotime($data['expiration']);
@ -56,7 +56,16 @@ class AuthKeysTable extends AppTable
{ {
$validator $validator
->notEmptyString('user_id') ->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; return $validator;
} }