-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat. impl. new ban system -> StanByes
- Loading branch information
Showing
14 changed files
with
364 additions
and
28 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
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,130 @@ | ||
<?php | ||
|
||
class BanController extends AppController | ||
{ | ||
function index() { | ||
if (!$this->isConnected || $this->User->isBanned() == false) | ||
$this->redirect("/"); | ||
|
||
$this->set('title_for_layout', $this->Lang->get("BAN__BAN")); | ||
$this->set('reason', $this->User->isBanned()); | ||
} | ||
|
||
function admin_index() | ||
{ | ||
if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) | ||
throw new ForbiddenException(); | ||
|
||
$this->set('title_for_layout', $this->Lang->get("BAN__HOME")); | ||
$this->layout = 'admin'; | ||
|
||
$this->loadModel("Ban"); | ||
$this->loadModel("User"); | ||
$banned_users = $this->Ban->find("all"); | ||
|
||
$users = $this->User->find("all"); | ||
|
||
$this->set(compact("banned_users", "users")); | ||
} | ||
|
||
function admin_add() | ||
{ | ||
if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) | ||
throw new ForbiddenException(); | ||
|
||
$this->set('title_for_layout', $this->Lang->get("BAN__HOME")); | ||
$this->layout = 'admin'; | ||
|
||
if ($this->request->is("post")) { | ||
$this->autoRender = false; | ||
$this->response->type('json'); | ||
|
||
if (empty($this->request->data("reason"))) | ||
return $this->response->body(json_encode(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')])); | ||
|
||
foreach ($this->request->data as $key => $v) { | ||
if ($v != "on" || $key == "name") | ||
continue; | ||
|
||
$this->Ban->create(); | ||
$this->Ban->set([ | ||
"user_id" => $key, | ||
"reason" => $this->request->data("reason") | ||
]); | ||
$this->Ban->save(); | ||
} | ||
|
||
$this->response->body(json_encode(['statut' => true, 'msg' => $this->Lang->get('BAN__SUCCESS')])); | ||
} | ||
} | ||
|
||
function admin_unban($id = false) | ||
{ | ||
if (!$this->isConnected || !$this->Permissions->can("MANAGE_BAN")) | ||
throw new ForbiddenException(); | ||
|
||
$this->loadModel('Ban'); | ||
$this->Ban->delete($id); | ||
$this->Session->setFlash($this->Lang->get('BAN__UNBAN_SUCCESS'), 'default.success'); | ||
$this->redirect(['controller' => 'ban', 'action' => 'index', 'admin' => true]); | ||
} | ||
|
||
public function admin_get_users_not_ban() | ||
{ | ||
if ($this->isConnected and $this->Permissions->can('MANAGE_BAN')) { | ||
$this->autoRender = false; | ||
$this->response->type('json'); | ||
if ($this->request->is('ajax')) { | ||
$available_ranks = [ | ||
0 => ['label' => 'success', 'name' => $this->Lang->get('USER__RANK_MEMBER')], | ||
2 => ['label' => 'warning', 'name' => $this->Lang->get('USER__RANK_MODERATOR')], | ||
3 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], | ||
4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], | ||
5 => ['label' => 'primary', 'name' => $this->Lang->get('USER__RANK_BANNED')] | ||
]; | ||
$this->loadModel('Rank'); | ||
$custom_ranks = $this->Rank->find('all'); | ||
foreach ($custom_ranks as $value) { | ||
$available_ranks[$value['Rank']['rank_id']] = [ | ||
'label' => 'info', | ||
'name' => $value['Rank']['name'] | ||
]; | ||
} | ||
$this->DataTable = $this->Components->load('DataTable'); | ||
$this->modelClass = 'User'; | ||
$this->DataTable->initialize($this); | ||
$this->paginate = [ | ||
'fields' => ['User.id', 'User.pseudo', 'User.rank'], | ||
]; | ||
$this->DataTable->mDataProp = true; | ||
$response = $this->DataTable->getResponse(); | ||
$users = $response['aaData']; | ||
$data = []; | ||
foreach ($users as $value) { | ||
$checkIsBan = $this->Ban->find('first', ["conditions" => ['user_id' => $value['User']['id']]]); | ||
|
||
if ($checkIsBan != null) | ||
continue; | ||
|
||
if ($this->Permissions->have($value['User']['rank'], "CAN_BE_BAN")) | ||
continue; | ||
|
||
$username = $value['User']['pseudo']; | ||
$rank_label = (isset($available_ranks[$value['User']['rank']])) ? $available_ranks[$value['User']['rank']]['label'] : $available_ranks[0]['label']; | ||
$rank_name = (isset($available_ranks[$value['User']['rank']])) ? $available_ranks[$value['User']['rank']]['name'] : $available_ranks[0]['name']; | ||
$rank = '<span class="label label-' . $rank_label . '">' . $rank_name . '</span>'; | ||
$checkbox = "<input type='checkbox' name=" . $value['User']['id'] . ">"; | ||
$data[] = [ | ||
'User' => [ | ||
'pseudo' => $username, | ||
'ban' => $checkbox, | ||
'rank' => $rank | ||
] | ||
]; | ||
} | ||
$response['aaData'] = $data; | ||
$this->response->body(json_encode($response)); | ||
} | ||
} | ||
} | ||
} |
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
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,5 @@ | ||
<?php | ||
|
||
class Ban extends AppModel | ||
{ | ||
} |
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,62 @@ | ||
<section class="content"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-header with-border"> | ||
<h3 class="card-title"><?= $Lang->get('BAN__HOME') ?></h3> | ||
</div> | ||
<div class="card-body"> | ||
<form method="post" data-ajax="true" data-upload-image="true" | ||
data-redirect-url="<?= $this->Html->url(['controller' => 'ban', 'action' => 'index', 'admin' => 'true']) ?>"> | ||
<table class="table table-responsive-sm table-bordered" | ||
style="table-layout: fixed;word-wrap: break-word;" id="users"> | ||
<thead> | ||
<tr> | ||
<th><?= $Lang->get('BAN__QUESTION') ?></th> | ||
<th><?= $Lang->get('USER__TITLE') ?></th> | ||
<th><?= $Lang->get('USER__RANK') ?></th> | ||
</tr> | ||
</thead> | ||
</table> | ||
|
||
<div class="col-sm-6"> | ||
<div class="form-group"> | ||
<label><?= $Lang->get('BAN__REASON') ?></label> | ||
<input type="text" class="form-control" | ||
value="<?= $page['title'] ?>" | ||
name="reason"> | ||
</div> | ||
</div> | ||
|
||
<div class="float-right"> | ||
<a href="<?= $this->Html->url(['controller' => 'ban', 'action' => 'index', 'admin' => true]) ?>" | ||
class="btn btn-default"><?= $Lang->get('GLOBAL__CANCEL') ?></a> | ||
<button class="btn btn-primary" type="submit"><?= $Lang->get('GLOBAL__SUBMIT') ?></button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<script type="text/javascript"> | ||
$(document).ready(function () { | ||
$('#users').DataTable({ | ||
"paging": true, | ||
"lengthChange": false, | ||
"searching": false, | ||
"ordering": false, | ||
"info": false, | ||
"autoWidth": false, | ||
'searching': true, | ||
"bProcessing": true, | ||
"bServerSide": true, | ||
"sAjaxSource": "<?= $this->Html->url(['action' => 'get_users_not_ban']) ?>", | ||
"aoColumns": [ | ||
{mData: "User.ban", "bSearchable": true}, | ||
{mData: "User.pseudo", "bSearchable": true}, | ||
{mData: "User.rank", "bSearchable": false} | ||
] | ||
}); | ||
}); | ||
</script> |
Oops, something went wrong.