Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fix user settings #43

Merged
merged 11 commits into from
Dec 21, 2021
16 changes: 8 additions & 8 deletions bonfire/Libraries/Widgets/Charts/ChartsItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ public function getScript(): string
}

return '
const data_' . $this->chartName() . ' = ' . json_encode($this->data()) . ';
const labels_' . $this->chartName() . ' = ' . json_encode($this->label()) . ';
' . $backgroundColor . '
' . $borderColor . '
const Chart_' . $this->chartName() . " = new Chart(
document.getElementById('" . $this->chartName() . "'),
drawChart( data_" . $this->chartName() . ', labels_' . $this->chartName() . ", '" . $this->title() . "', '" . $this->type() . "', " . $line_tension . ', backgroundColor_' . $this->chartName() . ' , borderColor_' . $this->chartName() . ', ' . $borderWidth . ', ' . $enableAnimation . ', ' . $showTitle . ', ' . $showSubTitle . ', ' . $showLegend . ', ' . $legendPosition . ')
);';
const data_' . $this->chartName() . ' = ' . json_encode($this->data()) . ';
const labels_' . $this->chartName() . ' = ' . json_encode($this->label()) . ';
' . $backgroundColor . '
' . $borderColor . '
const Chart_' . $this->chartName() . " = new Chart(
document.getElementById('" . $this->chartName() . "'),
drawChart( data_" . $this->chartName() . ', labels_' . $this->chartName() . ", '" . $this->title() . "', '" . $this->type() . "', " . $line_tension . ', backgroundColor_' . $this->chartName() . ' , borderColor_' . $this->chartName() . ', ' . $borderWidth . ', ' . $enableAnimation . ', ' . $showTitle . ', ' . $showSubTitle . ', ' . $showLegend . ', ' . $legendPosition . ')
);';
}

/**
Expand Down
10 changes: 5 additions & 5 deletions bonfire/Modules/Users/Controllers/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ public function save()
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}

setting('Auth.allowRegistration', $this->request->getPost('allowRegistration') === 1);
setting('Auth.allowRegistration', $this->request->getPost('allowRegistration') ?? false);
setting('Auth.minimumPasswordLength', (int) $this->request->getPost('minimumPasswordLength'));
setting('Auth.passwordValidators', $this->request->getPost('validators'));
setting('AuthGroups.defaultGroup', $this->request->getPost('defaultGroup'));

// Actions
$actions = setting('Auth.actions');
$actions['login'] = (bool) $this->request->getPost('email2FA');
$actions['register'] = (bool) $this->request->getPost('emailActivation');
$actions['login'] = $this->request->getPost('email2FA') ?? false;
$actions['register'] = $this->request->getPost('emailActivation') ?? false;
setting('Auth.actions', $actions);

// Remember Me
$sessionConfig = setting('Auth.sessionConfig');
$sessionConfig['allowRemembering'] = $this->request->getPost('allowRemember') === 1;
$sessionConfig['allowRemembering'] = $this->request->getPost('allowRemember') ?? false;
$sessionConfig['rememberLength'] = $this->request->getPost('rememberLength');
setting('Auth.sessionConfig', $sessionConfig);

// Avatars
setting('Users.useGravatar', $this->request->getPost('useGravatar') === 1);
setting('Users.useGravatar', $this->request->getPost('useGravatar') ?? false);
setting('Users.gravatarDefault', $this->request->getPost('gravatarDefault'));

alert('success', lang('Bonfire.resourcesSaved', ['settings']));
Expand Down
12 changes: 6 additions & 6 deletions bonfire/Modules/Users/Views/user_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
checked
<?php endif ?>
>
<label class="form-check-label" for="allow-registration">
<label class="form-check-label" for="email-activation">
Force email verification after registration?
</label>
</div>
Expand Down Expand Up @@ -89,7 +89,7 @@
<?php if (old('allowRemember', setting('Auth.sessionConfig')['allowRemembering'])) : ?> checked <?php endif ?>
x-on:click="remember = ! remember"
>
<label class="form-check-label" for="allow-registration">
<label class="form-check-label" for="allow-remember">
Allow users to be "remembered"
</label>
</div>
Expand All @@ -106,7 +106,7 @@
<?php if (isset($rememberOptions) && count($rememberOptions)) : ?>
<?php foreach ($rememberOptions as $title => $seconds) : ?>
<option value="<?= $seconds ?>"
<?php if (old('rememberDuration', setting('Auth.sessionConfig')['rememberLength']) === $seconds) : ?> selected <?php endif?>
<?php if (old('rememberLength', setting('Auth.sessionConfig')['rememberLength']) === (string) $seconds) : ?> selected <?php endif?>
>
<?= $title ?>
</option>
Expand All @@ -120,12 +120,12 @@
<div class="col-12 col-sm-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="email2FA"
value="Shield\Authentication\Actions\Email2FA" id="email-activation"
value="Shield\Authentication\Actions\Email2FA" id="email-2fa"
<?php if (old('email2FA', setting('Auth.actions')['login']) === 'Shield\Authentication\Actions\Email2FA') : ?>
checked
<?php endif ?>
>
<label class="form-check-label" for="allow-registration">
<label class="form-check-label" for="email-2fa">
Force 2FA check after login?
</label>
</div>
Expand Down Expand Up @@ -309,4 +309,4 @@
<script>

</script>
<?php $this->endSection() ?>
<?php $this->endSection() ?>
118 changes: 65 additions & 53 deletions tests/Bonfire/Widgets/ChartsCollectionTest.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,91 @@
<?php

/**
* This file is part of Bonfire.
*
* (c) Lonnie Ezell <lonnieje@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Bonfire\Widgets;

use Bonfire\Libraries\Widgets\Charts\ChartsItem;
use Bonfire\Libraries\Widgets\Charts\ChartsCollection;
use Bonfire\Libraries\Widgets\Charts\ChartsItem;
use Tests\Support\TestCase;

class ChartsCollectionTest extends TestCase
/**
* @internal
*/
final class ChartsCollectionTest extends TestCase
{
public function testExtendsChartsItem()
{
$item = new ChartsCollection([
'title' => 'Item A',
'type' => 'line',
'cssClass' => 'col-3',
]);
public function testExtendsChartsItem()
{
$item = new ChartsCollection([
'title' => 'Item A',
'type' => 'line',
'cssClass' => 'col-3',
]);

$this->assertEquals('Item A', $item->title());
$this->assertEquals('line', $item->type());
$this->assertEquals('col-3', $item->cssClass());
}
$this->assertSame('Item A', $item->title());
$this->assertSame('line', $item->type());
$this->assertSame('col-3', $item->cssClass());
}

public function testTitles()
{
$collection = new ChartsCollection();
$this->assertNull($collection->title());
public function testTitles()
{
$collection = new ChartsCollection();
$this->assertNull($collection->title());

$collection = new ChartsCollection(['title' => 'Foo']);
$this->assertEquals('Foo', $collection->title());
$collection = new ChartsCollection(['title' => 'Foo']);
$this->assertSame('Foo', $collection->title());

$collection = new ChartsCollection();
$collection->setTitle('Foo');
$this->assertEquals('Foo', $collection->title());
}
$collection = new ChartsCollection();
$collection->setTitle('Foo');
$this->assertSame('Foo', $collection->title());
}

public function testWithItem()
{
$collection = new ChartsCollection(['name' => 'Foo']);
$item1 = new ChartsItem(['title' => 'Item 1']);
$item2 = new ChartsItem(['title' => 'Item 2']);
public function testWithItem()
{
$chart_collection = new ChartsCollection(['name' => 'Foo']);
$item1 = new ChartsItem(['title' => 'Item 1']);
$item2 = new ChartsItem(['title' => 'Item 2']);

$collection->addItem($item1);
$collection->addItem($item2);
$chart_collection->addItem($item1);
$chart_collection->addItem($item2);

$items = $collection->items();
$items = $chart_collection->items();

$this->assertCount(2, $items);
$this->assertEquals('Item 1', $items[0]->title());
$this->assertEquals('Item 2', $items[1]->title());
$this->assertCount(2, $items);
$this->assertSame('Item 1', $items[0]->title());
$this->assertSame('Item 2', $items[1]->title());

$collection->removeItem('Item 1');
$chart_collection->removeItem('Item 1');

$items = $collection->items();
$items = $chart_collection->items();

$this->assertCount(1, $items);
$this->assertEquals('Item 2', $items[0]->title());
$this->assertCount(1, $items);
$this->assertSame('Item 2', $items[0]->title());

$collection->removeAllItems();
$chart_collection->removeAllItems();

$items = $collection->items();
$this->assertEquals([], $items);
}
$items = $chart_collection->items();
$this->assertSame([], $items);
}

public function testAddItems()
{
$collection = new ChartsCollection(['name' => 'Foo']);
$item1 = new ChartsItem(['title' => 'Item 1']);
$item2 = new ChartsItem(['title' => 'Item 2']);
public function testAddItems()
{
$chart_collection = new ChartsCollection(['name' => 'Foo']);
$item1 = new ChartsItem(['title' => 'Item 1']);
$item2 = new ChartsItem(['title' => 'Item 2']);

$collection->addItems([$item1, $item2]);
$chart_collection->addItems([$item1, $item2]);

$items = $collection->items();
$items = $chart_collection->items();

$this->assertCount(2, $items);
$this->assertEquals('Item 1', $items[0]->title());
$this->assertEquals('Item 2', $items[1]->title());
}
$this->assertCount(2, $items);
$this->assertSame('Item 1', $items[0]->title());
$this->assertSame('Item 2', $items[1]->title());
}
}
37 changes: 24 additions & 13 deletions tests/Bonfire/Widgets/ChartsItemTest.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
<?php

namespace Tests\Bonfire\Widgets;
/**
* This file is part of Bonfire.
*
* (c) Lonnie Ezell <lonnieje@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Bonfire\Widgets;

use Bonfire\Libraries\Widgets\Charts\ChartsItem;
use Tests\Support\TestCase;

class ChartsItemTest extends TestCase
/**
* @internal
*/
final class ChartsItemTest extends TestCase
{
public function testBasicDetails()
{
$item = new ChartsItem();
$item->setTitle('Item A')
->setType('line')
->setType('line')
->setCssclass('col-3');

$this->assertEquals('Item A', $item->title());
$this->assertEquals('line', $item->type());
$this->assertEquals('col-3', $item->cssClass());
$this->assertSame('Item A', $item->title());
$this->assertSame('line', $item->type());
$this->assertSame('col-3', $item->cssClass());
}

public function testConstructorFill()
{
$item = new ChartsItem([
'title' => 'Item A',
'type' => 'line',
'cssClass' => 'col-3',
]);
'title' => 'Item A',
'type' => 'line',
'cssClass' => 'col-3',
]);

$this->assertEquals('Item A', $item->title());
$this->assertEquals('line', $item->type());
$this->assertEquals('col-3', $item->cssClass());
$this->assertSame('Item A', $item->title());
$this->assertSame('line', $item->type());
$this->assertSame('col-3', $item->cssClass());
}
}
Loading