-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: do not allow users to browse with an invalid account from s…
…ession
- Loading branch information
1 parent
453e8a6
commit 14a6195
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Filters; | ||
|
||
use App\Models\Account; | ||
use CodeIgniter\Filters\FilterInterface; | ||
use CodeIgniter\HTTP\RequestInterface; | ||
use CodeIgniter\HTTP\ResponseInterface; | ||
|
||
class AccountExists implements FilterInterface | ||
{ | ||
/** | ||
* Do whatever processing this filter needs to do. | ||
* By default it should not return anything during | ||
* normal execution. However, when an abnormal state | ||
* is found, it should return an instance of | ||
* CodeIgniter\HTTP\Response. If it does, script | ||
* execution will end and that Response will be | ||
* sent back to the client, allowing for error pages, | ||
* redirects, etc. | ||
* | ||
* @param RequestInterface $request | ||
* @param array|null $arguments | ||
* | ||
* @return RequestInterface|ResponseInterface|string|void | ||
*/ | ||
public function before(RequestInterface $request, $arguments = null) | ||
{ | ||
if ($user = session()->get('user')) { | ||
if (!model(Account::class)->find($user->ID)) { | ||
session()->delete('user'); | ||
return response()->redirect('/auth/login'); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Allows After filters to inspect and modify the response | ||
* object as needed. This method does not allow any way | ||
* to stop execution of other after filters, short of | ||
* throwing an Exception or Error. | ||
* | ||
* @param RequestInterface $request | ||
* @param ResponseInterface $response | ||
* @param array|null $arguments | ||
* | ||
* @return ResponseInterface|void | ||
*/ | ||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) | ||
{ | ||
// | ||
} | ||
} |