init backend presensi
This commit is contained in:
36
app/Filters/DashboardAuthFilter.php
Normal file
36
app/Filters/DashboardAuthFilter.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use App\Modules\Auth\Services\AuthService;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Dashboard Auth Filter
|
||||
*
|
||||
* Blocks access to dashboard if user is not logged in. Returns 401 JSON.
|
||||
*/
|
||||
class DashboardAuthFilter implements \CodeIgniter\Filters\FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
$authService = new AuthService();
|
||||
if ($authService->currentUser() === null) {
|
||||
return service('response')
|
||||
->setStatusCode(401)
|
||||
->setJSON([
|
||||
'success' => false,
|
||||
'message' => 'Unauthorized',
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user