fix: [autkey expiration] has to be in the future
parent
6907ed2842
commit
da565f3f91
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue