Enhance user actions with CSRF protection and POST requests
Added CSRF protection and enforced POST requests for user delete and toggle status actions in UserController. Updated the users index view to use JavaScript for submitting POST forms with CSRF tokens for these actions, improving security and user experience. Also improved login success messages to include the user's full name.
This commit is contained in:
@@ -306,6 +306,14 @@ class UserController extends Controller
|
||||
*/
|
||||
public function delete($params = [])
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
$this->redirect('/users');
|
||||
return;
|
||||
}
|
||||
|
||||
// CSRF Protection
|
||||
$this->verifyCsrf('/users');
|
||||
|
||||
$userId = $params['id'] ?? 0;
|
||||
$user = $this->userModel->find($userId);
|
||||
|
||||
@@ -348,6 +356,14 @@ class UserController extends Controller
|
||||
*/
|
||||
public function toggleStatus($params = [])
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
$this->redirect('/users');
|
||||
return;
|
||||
}
|
||||
|
||||
// CSRF Protection
|
||||
$this->verifyCsrf('/users');
|
||||
|
||||
$userId = $params['id'] ?? 0;
|
||||
$user = $this->userModel->find($userId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user