add operation of setting/canceling admins #21

This commit is contained in:
printempw 2016-07-29 15:31:05 +08:00
parent 63bc3ec4e0
commit c6a20e910a
4 changed files with 139 additions and 20 deletions

View File

@ -112,6 +112,8 @@ class AdminController extends BaseController
$user = new User('', Utils::getValue('uid', $_POST));
$current_user = new User($_SESSION['email']);
if (!$user->is_registered)
throw new E('用户不存在', 1);
@ -148,12 +150,40 @@ class AdminController extends BaseController
if ($user->setScore($_POST['score']))
View::json('积分修改成功', 0);
} else if ($action == "permission") {
$permission = $user->getPermission() == "0"
? "-1" : "0";
} else if ($action == "ban") {
if ($user->getPermission() == "1") {
if ($current_user->getPermission() != "2")
View::json('非超级管理员无法封禁普通管理员');
} elseif ($user->getPermission() == "2") {
View::json('超级管理员无法被封禁');
}
if ($user->setPermission($permission))
View::json('账号已被'.($permission == "-1"?"封禁":"解封"), 0);
$permission = $user->getPermission() == "-1" ? "0" : "-1";
if ($user->setPermission($permission)) {
View::json([
'errno' => 0,
'msg' => '账号已被' . ($permission == '-1' ? '封禁' : '解封'),
'permission' => $user->getPermission()
]);
}
} else if ($action == "admin") {
if ($current_user->getPermission() != "2")
View::json('非超级管理员无法进行此操作');
if ($user->getPermission() == "2")
View::json('超级管理员无法被解除');
$permission = $user->getPermission() == "1" ? "0" : "1";
if ($user->setPermission($permission)) {
View::json([
'errno' => 0,
'msg' => '账号已被' . ($permission == '1' ? '设为' : '解除') . '管理员',
'permission' => $user->getPermission()
]);
}
} else if ($action == "delete") {
if ($user->delete())

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-22 14:02:44
* @Last Modified by: printempw
* @Last Modified time: 2016-07-23 21:12:23
* @Last Modified time: 2016-07-29 15:27:02
*/
'use strict';
@ -131,19 +131,43 @@ function changeUserScore(uid, score) {
});
}
function changePermission(uid) {
function changeBanStatus(uid) {
$.ajax({
type: "POST",
url: "../admin/users?action=permission",
url: "../admin/users?action=ban",
dataType: "json",
data: { 'uid': uid },
success: function(json) {
if (json.errno == 0) {
var object = $($('#'+uid).find('ul').children()[6]);
var dom = '<a href="javascript:changePermission('+uid+');">' +
var object = $('#'+uid).find('a#ban');
var dom = '<a id="ban" href="javascript:changeBanStatus('+uid+');">' +
(object.text() == '封禁' ? '解封' : '封禁') + '</a>';
object.html(dom);
$('#'+uid).find('#permission').text(object.text() == '封禁' ? '正常' : '封禁');
$('#'+uid).find('#permission').text(json.permission == '-1' ? '封禁' : '正常');
toastr.success(json.msg);
} else {
toastr.warning(json.msg);
}
},
error: showAjaxError
});
}
function changeAdminStatus(uid) {
$.ajax({
type: "POST",
url: "../admin/users?action=admin",
dataType: "json",
data: { 'uid': uid },
success: function(json) {
if (json.errno == 0) {
var object = $('#'+uid).find('a#admin');
var dom = '<a href="javascript:changeAdminStatus('+uid+');">' +
(object.text() == '设为管理员' ? '解除管理员' : '设为管理员') + '</a>';
object.html(dom);
$('#'+uid).find('#permission').text(json.permission == '1' ? '管理员' : '正常');
toastr.success(json.msg);
} else {
toastr.warning(json.msg);

View File

@ -164,3 +164,11 @@
</div><!-- /.modal -->
@endsection
@section('script')
<script type="text/javascript">
$(document).ready(function() {
$('.box-body').css('min-height', $('.content-wrapper').height() - $('.content-header').outerHeight() - 120);
});
</script>
@endsection

View File

@ -26,6 +26,8 @@
</h1>
</section>
<?php $current_user = new App\Models\User($_SESSION['email']); ?>
<!-- Main content -->
<section class="content">
<div class="box">
@ -50,7 +52,17 @@
<td id="email">{{ $user->email }}</td>
<td id="nickname">{{ $user->nickname }}</td>
<td><input type="text" class="form-control score" value="{{ $user->score }}" title="输入修改后的积分,回车提交" data-placement="top"></td>
<td id="permission">{{ $user->permission == "-1" ? "封禁" : "正常" }}</td>
<td id="permission">
@if ($user->permission == "0")
正常
@elseif ($user->permission == "-1")
封禁
@elseif ($user->permission == "1")
管理员
@elseif ($user->permission == "2")
超级管理员
@endif
</td>
<td>{{ $user->register_at }}</td>
<td>
@ -66,21 +78,58 @@
<li><a href="../admin/players?filter=uid&q={{ $user->uid }}">查看该用户拥有的角色</a></li>
<li class="divider"></li>
@if ($user->permission == "1")
<li><a href="javascript:;">无法封禁管理员</a></li>
@elseif ($user->permission == "0")
<li><a href="javascript:changePermission('{{ $user->uid }}');">封禁</a></li>
{{-- If current user is super admin --}}
@if ($current_user->getPermission() == "2")
@if ($user->permission == "1")
<li><a id="admin" href="javascript:changeAdminStatus('{{ $user->uid }}');">解除管理员</a></li>
@elseif ($user->permission == "2")
<li><a href="javascript:;">无法解除超级管理员</a></li>
@else
<li><a id="admin" href="javascript:changeAdminStatus('{{ $user->uid }}');">设为管理员</a></li>
@endif
<li class="divider"></li>
@if ($user->permission == "2")
<li><a href="javascript:;">无法封禁超级管理员</a></li>
@elseif ($user->permission == "-1")
<li><a id="ban" href="javascript:changeBanStatus('{{ $user->uid }}');">解封</a></li>
@else
<li><a id="ban" href="javascript:changeBanStatus('{{ $user->uid }}');">封禁</a></li>
@endif
{{-- If current user is ordinary admin --}}
@else
<li><a href="javascript:changePermission('{{ $user->uid }}');">解封</a></li>
@if ($user->permission == "1" || $user->permission == "2")
<li><a href="javascript:;">无法封禁管理员</a></li>
@elseif ($user->permission == "0")
<li><a id="ban" href="javascript:changeBanStatus('{{ $user->uid }}');">封禁</a></li>
@else
<li><a id="ban" href="javascript:changeBanStatus('{{ $user->uid }}');">解封</a></li>
@endif
@endif
</ul>
</div>
{{-- If current user is super admin --}}
@if ($current_user->getPermission() == "2")
@if ($user->permission == "2")
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="超级管理员账号不能被这样删除的啦">删除用户</a>
@else
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $user->uid }}');">删除用户</a>
@endif
@if ($user->permission == "1")
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="管理员账号不能被这样删除的啦">删除用户</a>
@else
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $user->uid }}');">删除用户</a>
@if ($user->permission == "1" || $user->permission == "2")
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="你不能删除管理员账号哦">删除用户</a>
@else
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $user->uid }}');">删除用户</a>
@endif
@endif
</td>
</tr>
@ -134,3 +183,11 @@
</div><!-- /.content-wrapper -->
@endsection
@section('script')
<script type="text/javascript">
$(document).ready(function() {
$('.box-body').css('min-height', $('.content-wrapper').height() - $('.content-header').outerHeight() - 120);
});
</script>
@endsection