Skip to content

Commit 25ba60a

Browse files
committed
Add middleware interface
1 parent 63581b7 commit 25ba60a

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Interfaces;
4+
5+
interface MiddlewareInterface
6+
{
7+
public function auth();
8+
}

app.test/app/Middlewares/Auth.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,4 @@ public static function isAdmin()
4444
exit;
4545
}
4646
}
47-
48-
public static function isWelcome()
49-
{
50-
if (!session()->has('welcomed')) {
51-
header('location: /logout');
52-
exit;
53-
}
54-
}
55-
56-
public static function isResetPassword()
57-
{
58-
if (!session()->has('reset_password_code')) {
59-
header('location: /logout');
60-
exit;
61-
}
62-
}
6347
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Middlewares;
4+
5+
use App\Interfaces\MiddlewareInterface;
6+
7+
class ResetPassword implements MiddlewareInterface
8+
{
9+
public static function auth()
10+
{
11+
if (!session()->has('reset_password_code')) {
12+
header('location: /logout');
13+
exit;
14+
}
15+
}
16+
}

app.test/app/Middlewares/Welcome.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Middlewares;
4+
5+
use App\Interfaces\MiddlewareInterface;
6+
7+
class Welcome implements MiddlewareInterface
8+
{
9+
public static function auth()
10+
{
11+
if (!session()->has('welcomed')) {
12+
header('location: /logout');
13+
exit;
14+
}
15+
}
16+
}

app.test/routes/auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
$router->post('/forgot-password', '\App\Controllers\Auth\ForgotPassword@post');
2020

2121
// Define routes
22-
// $router->before('GET|POST', '/reset-password', '\App\Middlewares\Auth@isResetPassword');
22+
$router->before('GET|POST', '/reset-password', '\App\Middlewares\ResetPassword@auth');
2323
$router->get('/reset-password', '\App\Controllers\Auth\ResetPassword@get');
2424
$router->post('/reset-password', '\App\Controllers\Auth\ResetPassword@post');
2525

2626
// Define routes
27-
$router->before('GET', '/welcome', '\App\Middlewares\Auth@isWelcome');
27+
$router->before('GET', '/welcome', '\App\Middlewares\Welcome@auth');
2828
$router->get('/welcome', '\App\Controllers\Auth\Welcome@get');
2929

3030
// Define routes

0 commit comments

Comments
 (0)