Skip to content

Commit cbcd208

Browse files
committed
wip
1 parent 6f1f00e commit cbcd208

19 files changed

+93
-505
lines changed

config/laravel-expiry.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount;
4+
use CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword;
5+
use CleaniqueCoders\LaravelExpiry\Listeners\LogoutOnExpired;
6+
7+
return [
8+
'events' => [
9+
ExpiredAccount::class => [
10+
LogoutOnExpired::class,
11+
],
12+
ExpiredPassword::class => [
13+
LogoutOnExpired::class,
14+
],
15+
],
16+
];

database/migrations/2020_03_27_000000_add_expiry_columns.php renamed to database/migrations/add_expiry_columns.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class AddExpiryColumns extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -27,4 +27,4 @@ public function down()
2727
$table->dropColumn('account_expired_at');
2828
});
2929
}
30-
}
30+
};

phpunit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<env name="SESSION_DRIVER" value="array"/>
1212
<env name="QUEUE_DRIVER" value="sync"/>
1313
<env name="APP_KEY" value="base64:BQ5eDl9HCEwtIe+tozAZuDN8XLadbq84WUAGnpCcD6g="/>
14+
<env name="DB_CONNECTION" value="sqlite"/>
15+
<env name="DB_DATABASE" value=":memory:"/>
1416
</php>
1517
<source>
1618
<include>

src/Exceptions/ExpiredAccountException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exceptions/ExpiredPasswordException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Http/Middleware/AccountExpiry.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ public function handle($request, Closure $next)
1818
event(
1919
new \CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount(auth()->user())
2020
);
21-
auth()->logout();
22-
23-
throw new \CleaniqueCoders\LaravelExpiry\Exceptions\ExpiredAccountException;
2421
}
2522

2623
return $next($request);

src/Http/Middleware/PasswordExpiry.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ public function handle($request, Closure $next)
1818
event(
1919
new \CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword(auth()->user())
2020
);
21-
auth()->logout();
22-
23-
throw new \CleaniqueCoders\LaravelExpiry\Exceptions\ExpiredPasswordException;
2421
}
2522

2623
return $next($request);

src/LaravelExpiryServiceProvider.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22

33
namespace CleaniqueCoders\LaravelExpiry;
44

5-
use Spatie\LaravelPackageTools\PackageServiceProvider;
5+
use Illuminate\Support\Facades\Event;
66
use Spatie\LaravelPackageTools\Package;
7+
use Spatie\LaravelPackageTools\PackageServiceProvider;
78

89
class LaravelExpiryServiceProvider extends PackageServiceProvider
910
{
1011
public function configurePackage(Package $package): void
1112
{
1213
$package
1314
->name('laravel-expiry')
14-
->hasMigration('add_expiry_columns');
15+
->hasMigration('add_expiry_columns')
16+
->hasConfigFile('laravel-expiry');
17+
}
18+
19+
public function packageRegistered()
20+
{
21+
$events = config('laravel-expiry.events');
22+
23+
foreach ($events as $event => $listeners) {
24+
foreach ($listeners as $listener) {
25+
Event::listen($event, $listener);
26+
}
27+
}
1528
}
1629
}

src/Listeners/LogoutOnExpired.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace CleaniqueCoders\LaravelExpiry\Listeners;
4+
5+
use CleaniqueCoders\LaravelExpiry\Events\ExpiredAccount;
6+
use CleaniqueCoders\LaravelExpiry\Events\ExpiredPassword;
7+
use Illuminate\Support\Facades\Auth;
8+
9+
class LogoutOnExpired
10+
{
11+
/**
12+
* Create the event listener.
13+
*/
14+
public function __construct()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Handle the event.
21+
*/
22+
public function handle(ExpiredAccount|ExpiredPassword $event): void
23+
{
24+
Auth::logout();
25+
}
26+
}

tests/ArchTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
it('will not use debugging functions')
4+
->expect(['dd', 'dump', 'ray'])
5+
->not->toBeUsed();

tests/Pest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
use CleaniqueCoders\LaravelExpiry\Tests\TestCase;
4+
5+
uses(TestCase::class)->in(__DIR__);

tests/Stubs/Models/User.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/TestCase.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@
22

33
namespace CleaniqueCoders\LaravelExpiry\Tests;
44

5-
class TestCase extends \Orchestra\Testbench\TestCase
5+
use CleaniqueCoders\LaravelExpiry\LaravelExpiryServiceProvider;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
use Orchestra\Testbench\TestCase as Orchestra;
8+
9+
class TestCase extends Orchestra
610
{
7-
use Traits\TestCaseTrait;
11+
protected function setUp(): void
12+
{
13+
parent::setUp();
14+
15+
Factory::guessFactoryNamesUsing(
16+
fn (string $modelName) => 'Workbench\\Database\\Factories\\'.class_basename($modelName).'Factory'
17+
);
18+
}
819

9-
/**
10-
* Load Package Service Provider.
11-
*
12-
* @param \Illuminate\Foundation\Application $app
13-
* @return array List of Service Provider
14-
*/
1520
protected function getPackageProviders($app)
1621
{
1722
return [
18-
\CleaniqueCoders\LaravelExpiry\LaravelExpiryServiceProvider::class,
23+
LaravelExpiryServiceProvider::class,
1924
];
2025
}
26+
27+
public function getEnvironmentSetUp($app)
28+
{
29+
config()->set('database.default', 'testing');
30+
31+
// $migration = include __DIR__.'/../database/migrations/add_expiry_columns.php.stub';
32+
// $migration->up();
33+
}
2134
}

tests/Traits/SeedTrait.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)