Merge pull request #6 from Luceos/validation_fix

fixed validation the date instead of integers
This commit is contained in:
Toby Zerner 2016-02-21 16:45:53 +10:30
commit f0f668938a
2 changed files with 14 additions and 11 deletions

View File

@ -10,6 +10,7 @@
namespace Flarum\Suspend\Listener; namespace Flarum\Suspend\Listener;
use Illuminate\Support\Arr;
use Carbon\Carbon; use Carbon\Carbon;
use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Access\AssertPermissionTrait;
use Flarum\Event\UserWillBeSaved; use Flarum\Event\UserWillBeSaved;
@ -50,16 +51,18 @@ class SaveSuspensionToDatabase
{ {
$attributes = array_get($event->data, 'attributes', []); $attributes = array_get($event->data, 'attributes', []);
if (array_key_exists('suspendUntil', $attributes)) { $suspendUntil = Arr::get($attributes, 'suspendUntil');
if ($suspendUntil) {
$suspendUntil = new Carbon($suspendUntil);
}
$this->validator->assertValid($attributes); $this->validator->assertValid($attributes);
$suspendUntil = $attributes['suspendUntil'];
$user = $event->user; $user = $event->user;
$actor = $event->actor; $actor = $event->actor;
$this->assertCan($actor, 'suspend', $user); $this->assertCan($actor, 'suspend', $user);
$user->suspend_until = new Carbon($suspendUntil); $user->suspend_until = $suspendUntil;
}
} }
} }

View File

@ -18,6 +18,6 @@ class SuspendValidator extends AbstractValidator
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $rules = [ protected $rules = [
'suspendUntil' => ['min:1', 'integer'], 'suspendUntil' => ['date'],
]; ];
} }