finish i18n work of user/player management

This commit is contained in:
printempw 2016-12-31 21:16:04 +08:00
parent 932382d5c8
commit 3b96166ee8
11 changed files with 273 additions and 138 deletions

View File

@ -22,8 +22,19 @@ class AdminController extends Controller
return view('admin.index');
}
public function customize()
public function customize(Request $request)
{
if ($request->input('action') == "color") {
$this->validate($request, [
'color_scheme' => 'required'
]);
$color_scheme = str_replace('_', '-', $request->input('color_scheme'));
option(['color_scheme' => $color_scheme]);
return json('修改配色成功', 0);
}
$homepage = Option::form('homepage', '首页配置', function($form)
{
$form->text('home_pic_url', '首页图片地址')->hint('相对于首页的路径或者完整的 URL');
@ -165,14 +176,14 @@ class AdminController extends Controller
$users = User::select(['uid', 'email', 'nickname', 'score', 'permission', 'register_at']);
$permissionTextMap = [
User::BANNED => '封禁',
User::NORMAL => '正常',
User::ADMIN => '管理员',
User::SUPER_ADMIN => '超级管理员'
User::BANNED => trans('admin.users.status.banned'),
User::NORMAL => trans('admin.users.status.normal'),
User::ADMIN => trans('admin.users.status.admin'),
User::SUPER_ADMIN => trans('admin.users.status.super-admin')
];
return Datatables::of($users)->editColumn('email', function ($user) {
return $user->email ?: '[未填写邮箱]';
return $user->email ?: 'EMPTY';
})->editColumn('permission', function ($user) use ($permissionTextMap) {
return Arr::get($permissionTextMap, $user->permission);
})
@ -213,98 +224,86 @@ class AdminController extends Controller
public function userAjaxHandler(Request $request, UserRepository $users)
{
$action = $request->input('action');
if ($action == "color") {
$this->validate($request, [
'color_scheme' => 'required'
]);
$color_scheme = str_replace('_', '-', $request->input('color_scheme'));
\Option::set('color_scheme', $color_scheme);
return json('修改配色成功', 0);
}
$user = $users->get($request->input('uid'));
// current user
$cur_user = $users->get(session('uid'));
$user = $users->get($request->input('uid'));
if (!$user)
return json('用户不存在', 1);
return json(trans('admin.users.operations.non-existent'), 1);
if ($action == "email") {
$this->validate($request, [
'email' => 'required|email'
]);
if ($user->setEmail($request->input('email')))
return json('邮箱修改成功', 0);
$user->setEmail($request->input('email'));
return json(trans('admin.users.operations.email.success'), 0);
} elseif ($action == "nickname") {
$this->validate($request, [
'nickname' => 'required|nickname'
]);
if ($user->setNickName($request->input('nickname')))
return json('昵称已成功设置为 '.$request->input('nickname'), 0);
$user->setNickName($request->input('nickname'));
return json(trans('admin.users.operations.nickname.success', ['new' => $request->input('nickname')]), 0);
} elseif ($action == "password") {
$this->validate($request, [
'password' => 'required|min:8|max:16'
]);
if ($user->changePasswd($request->input('password')))
return json('密码修改成功', 0);
$user->changePasswd($request->input('password'));
return json(trans('admin.users.operations.password.success'), 0);
} elseif ($action == "score") {
$this->validate($request, [
'score' => 'required|integer'
]);
if ($user->setScore($request->input('score')))
return json('积分修改成功', 0);
$user->setScore($request->input('score'));
return json(trans('admin.users.operations.score.success'), 0);
} elseif ($action == "ban") {
if ($user->getPermission() == User::ADMIN) {
if ($cur_user->getPermission() != User::SUPER_ADMIN)
return json('非超级管理员无法封禁普通管理员');
if (app('user.current')->getPermission() != User::SUPER_ADMIN)
return json(trans('admin.users.operations.ban.cant-admin'));
} elseif ($user->getPermission() == User::SUPER_ADMIN) {
return json('超级管理员无法被封禁');
return json(trans('admin.users.operations.ban.cant-super-admin'));
}
$permission = $user->getPermission() == User::BANNED ? User::NORMAL : User::BANNED;
if ($user->setPermission($permission)) {
return json([
'errno' => 0,
'msg' => '账号已被' . ($permission == User::BANNED ? '封禁' : '解封'),
'permission' => $user->getPermission()
]);
}
$user->setPermission($permission);
return json([
'errno' => 0,
'msg' => trans('admin.users.operations.ban.'.($permission == User::BANNED ? 'ban' : 'unban').'.success'),
'permission' => $user->getPermission()
]);
} elseif ($action == "admin") {
if ($cur_user->getPermission() != User::SUPER_ADMIN)
return json('非超级管理员无法进行此操作');
if (app('user.current')->getPermission() != User::SUPER_ADMIN)
return json(trans('admin.users.operations.admin.cant-set'));
if ($user->getPermission() == User::SUPER_ADMIN)
return json('超级管理员无法被解除');
return json(trans('admin.users.operations.admin.cant-unset'));
$permission = $user->getPermission() == User::ADMIN ? User::NORMAL : User::ADMIN;
if ($user->setPermission($permission)) {
return json([
'errno' => 0,
'msg' => '账号已被' . ($permission == User::ADMIN ? '设为' : '解除') . '管理员',
'permission' => $user->getPermission()
]);
}
$user->setPermission($permission);
return json([
'errno' => 0,
'msg' => trans('admin.users.operations.admin.'.($permission == User::ADMIN ? 'set' : 'unset').'.success'),
'permission' => $user->getPermission()
]);
} elseif ($action == "delete") {
if ($user->delete())
return json('账号已被成功删除', 0);
$user->delete();
} else {
return json('非法参数', 1);
return json(trans('admin.users.operations.delete.success'), 0);
}
}
@ -325,8 +324,9 @@ class AdminController extends Controller
'preference' => 'required|preference'
]);
if ($player->setPreference($request->input('preference')))
return json('角色 '.$player->player_name.' 的优先模型已更改至 '.$request->input('preference'), 0);
$player->setPreference($request->input('preference'));
return json(trans('admin.players.preference.success', ['player' => $player->player_name, 'preference' => $request->input('preference')]), 0);
} elseif ($action == "texture") {
$this->validate($request, [
@ -335,10 +335,11 @@ class AdminController extends Controller
]);
if (!Texture::find($request->tid))
return json("材质 tid.{$request->tid} 不存在", 1);
return json(trans('admin.players.textures.non-existent', ['tid' => $request->tid]), 1);
if ($player->setTexture(['tid_'.$request->model => $request->tid]))
return json("角色 {$player->player_name} 的材质修改成功", 0);
$player->setTexture(['tid_'.$request->model => $request->tid]);
return json(trans('admin.players.textures.success', ['player' => $player->player_name]), 0);
} elseif ($action == "owner") {
$this->validate($request, [
@ -349,16 +350,16 @@ class AdminController extends Controller
$user = $users->get($request->input('uid'));
if (!$user)
return json('不存在的用户', 1);
return json(trans('admin.users.operations.non-existent'), 1);
if ($player->setOwner($request->input('uid')))
return json("角色 $player->player_name 已成功让渡至 ".$user->getNickName(), 0);
$player->setOwner($request->input('uid'));
return json(trans('admin.players.owner.success', ['player' => $player->player_name, 'user' => $user->getNickName()]), 0);
} elseif ($action == "delete") {
if ($player->delete())
return json('角色已被成功删除', 0);
} else {
return json('非法参数', 1);
$player->delete();
return json(trans('admin.players.delete.success'), 0);
}
}

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-22 14:02:44
* @Last Modified by: printempw
* @Last Modified time: 2016-12-31 10:54:41
* @Last Modified time: 2016-12-31 19:54:01
*/
'use strict';
@ -23,7 +23,7 @@ $('#layout-skins-list [data-skin]').click(function(e) {
$('#color-submit').click(function() {
$.ajax({
type: "POST",
url: "./users?action=color",
url: "./customize?action=color",
dataType: "json",
data: { "color_scheme": current_skin },
success: function(json) {
@ -36,19 +36,6 @@ $('#color-submit').click(function() {
});
});
$('#page-select').on('change', function() {
// if has query strings
if (getQueryString('filter') != "" || getQueryString('q') != "") {
if (getQueryString('page') == "")
window.location = location.href + "&page=" + $(this).val();
else
window.location = "?filter="+getQueryString('filter')+"&q="+getQueryString('q')+"&page="+$(this).val();
} else {
window.location = "?page=" + $(this).val();
}
});
function changeUserEmail(uid) {
var email = prompt(trans('admin.newUserEmail'));

View File

@ -5,6 +5,69 @@ index:
disk-usage: Disk Usage
overview: Overview
users:
status:
title: Status
normal: Normal
banned: Banned
admin: Admin
super-admin: Super Admin
score:
tip: Press enter to submit new score
operations:
title: Operations
non-existent: No such user.
email:
change: Edit Email
success: Email changed successfully.
nickname:
change: Edit Nickname
success: Nickname changed successfully.
password:
change: Edit Password
success: Password changed successfully.
score:
success: Score changed successfully.
admin:
set:
text: Set as Admin
success: The account has been set as admin.
unset:
text: Remove Admin
success: The account's admin privilege has been removed.
cant-set: Only super admins can do the operation
cant-unset: Can't remove super admin privilege
ban:
ban:
text: Ban
success: The account has been banned.
unban:
text: Unban
success: The account has been unbanned.
cant-super-admin: You can't ban super admin.
cant-admin: Only super admins are able to ban admins.
delete:
delete: Delete User
success: The account has been deleted successfully.
cant-super-admin: You can't delete super admin in this way
cant-admin: You can't delete admins.
players:
operations:
title: Operations
preference:
success: The preference of player [:player] has been changed to :preference
textures:
change: Change Textures
non-existent: No such texture tid.:tid
success: The textures of :player has been updated.
owner:
change: Change Owner
success: The player :player was transferred to user :user.
delete:
delete: Delete
success: The player has been deleted successfully.
customize:
change-color: Change theme color

View File

@ -50,3 +50,21 @@ unexistent-player: Un-existent player.
texture-deleted: The requested texture has been deleted.
texture-not-uploaded: The user haven not uploaded the texture of :type model yet.
operations: Operations
user:
uid: UID
email: Email
nickname: Nickname
password: Password
score: Score
register-at: Registered At
player:
pid: PID
owner: Owner
player-name: Player Name
preference: Preference
previews: Texture Previews
last-modified: Last Modified

View File

@ -5,6 +5,69 @@ index:
disk-usage: 占用空间大小
overview: 概览
users:
status:
title: 状态
normal: 正常
banned: 封禁
admin: 管理员
super-admin: 超级管理员
score:
tip: 输入修改后的积分,回车提交
operations:
title: 更多操作
non-existent: 用户不存在
email:
change: 修改邮箱
success: 邮箱修改成功
nickname:
change: 修改昵称
success: 昵称已成功设置为 :new
password:
change: 更改密码
success: 密码修改成功
score:
success: 积分修改成功
admin:
set:
text: 设为管理员
success: 账号已被设置为管理员
unset:
text: 解除管理员
success: 账号已被解除管理员
cant-set: 非超级管理员无法进行此操作
cant-unset: 无法解除超级管理员
ban:
ban:
text: 封禁
success: 账号已被封禁
unban:
text: 解封
success: 账号已被解封
cant-super-admin: 无法封禁超级管理员
cant-admin: 非超级管理员无法封禁普通管理员
delete:
delete: 删除用户
success: 账号已被成功删除
cant-super-admin: 超级管理员账号不能被这样删除的啦
cant-admin: 你不能删除管理员账号哦
players:
operations:
title: 更多操作
preference:
success: 角色 :player 的优先模型已更改至 :preference
textures:
change: 更换材质
non-existent: 材质 tid.:tid 不存在
success: 角色 :player 的材质修改成功
owner:
change: 更换角色拥有者
success: 角色 :player 已成功让渡至 :user
delete:
delete: 删除角色
success: 角色已被成功删除
customize:
change-color: 更改配色

View File

@ -50,3 +50,21 @@ unexistent-player: 角色不存在
texture-deleted: 请求的材质已被删除
texture-not-uploaded: 该用户尚未上传请求的材质类型 :type
operations: 操作
user:
uid: UID
email: 邮箱
nickname: 昵称
password: 密码
score: 积分
register-at: 注册时间
player:
pid: PID
owner: 拥有者
player-name: 角色名
preference: 优先模型
previews: 预览材质
last-modified: 修改时间

View File

@ -21,13 +21,13 @@
<table id="player-table" class="table table-hover">
<thead>
<tr>
<th>PID</th>
<th>拥有者</th>
<th>角色名</th>
<th>优先模型</th>
<th>预览材质</th>
<th>修改时间</th>
<th>操作</th>
<th>{{ trans('general.player.pid') }}</th>
<th>{{ trans('general.player.owner') }}</th>
<th>{{ trans('general.player.player-name') }}</th>
<th>{{ trans('general.player.preference') }}</th>
<th>{{ trans('general.player.previews') }}</th>
<th>{{ trans('general.player.last-modified') }}</th>
<th>{{ trans('general.operations') }}</th>
</tr>
</thead>
</table>

View File

@ -21,13 +21,13 @@
<table id="user-table" class="table table-hover">
<thead>
<tr>
<th>UID</th>
<th>邮箱</th>
<th>昵称</th>
<th>积分</th>
<th>状态</th>
<th>注册时间</th>
<th>操作</th>
<th>{{ trans('general.user.uid') }}</th>
<th>{{ trans('general.user.email') }}</th>
<th>{{ trans('general.user.nickname') }}</th>
<th>{{ trans('general.user.score') }}</th>
<th>{{ trans('admin.users.status.title') }}</th>
<th>{{ trans('general.user.register-at') }}</th>
<th>{{ trans('general.operations') }}</th>
</tr>
</thead>
</table>

View File

@ -1,11 +1,11 @@
<div class="btn-group">
<button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
更多操作 <span class="caret"></span>
{{ trans('admin.players.operations.title') }} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="javascript:changeTexture('{{ $pid }}');">更换材质</a></li>
<li><a href="javascript:changeOwner('{{ $pid }}');">更换角色拥有者</a></li>
<li><a href="javascript:changeTexture('{{ $pid }}');">{{ trans('admin.players.textures.change') }}</a></li>
<li><a href="javascript:changeOwner('{{ $pid }}');">{{ trans('admin.players.owner.change') }}</a></li>
</ul>
</div>
<a class="btn btn-danger btn-sm" href="javascript:deletePlayer('{{ $pid }}');">删除角色</a>
<a class="btn btn-danger btn-sm" href="javascript:deletePlayer('{{ $pid }}');">{{ trans('admin.players.delete.delete') }}</a>

View File

@ -1,65 +1,50 @@
<?php use App\Models\User; ?>
<div class="btn-group">
<button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
更多操作 <span class="caret"></span>
{{ trans('admin.users.operations.title') }} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="javascript:changeUserEmail('{{ $uid }}');">修改邮箱</a></li>
<li><a href="javascript:changeUserNickName('{{ $uid }}');">修改昵称</a></li>
<li><a href="javascript:changeUserPwd('{{ $uid }}');">更改密码</a></li>
<li class="divider"></li>
<li><a href="{{ url('admin/players?filter=uid&q='.$uid) }}">查看该用户拥有的角色</a></li>
<li class="divider"></li>
<li><a href="javascript:changeUserEmail('{{ $uid }}');">{{ trans('admin.users.operations.email.change') }}</a></li>
<li><a href="javascript:changeUserNickName('{{ $uid }}');">{{ trans('admin.users.operations.nickname.change') }}</a></li>
<li><a href="javascript:changeUserPwd('{{ $uid }}');">{{ trans('admin.users.operations.password.change') }}</a></li>
{{-- If current user is super admin --}}
@if (app('user.current')->getPermission() == App\Models\User::SUPER_ADMIN)
@if ($permission == "1")
<li><a id="admin" href="javascript:changeAdminStatus('{{ $uid }}');">解除管理员</a></li>
@elseif ($permission == "2")
<li><a href="javascript:;">无法解除超级管理员</a></li>
@else
<li><a id="admin" href="javascript:changeAdminStatus('{{ $uid }}');">设为管理员</a></li>
@unless ($permission == User::SUPER_ADMIN)
<li class="divider"></li>
{{-- If current user is super admin --}}
@if (app('user.current')->getPermission() == User::SUPER_ADMIN)
@if ($permission == User::ADMIN)
<li><a id="admin" href="javascript:changeAdminStatus('{{ $uid }}');">{{ trans('admin.users.operations.admin.unset.text') }}</a></li>
@else
<li><a id="admin" href="javascript:changeAdminStatus('{{ $uid }}');">{{ trans('admin.users.operations.admin.set.text') }}</a></li>
@endif
@endif
<li class="divider"></li>
@if ($permission == "2")
<li><a href="javascript:;">无法封禁超级管理员</a></li>
@elseif ($permission == "-1")
<li><a id="ban" href="javascript:changeBanStatus('{{ $uid }}');">解封</a></li>
@if ($permission == User::BANNED)
<li><a id="ban" href="javascript:changeBanStatus('{{ $uid }}');">{{ trans('admin.users.operations.ban.unban.text') }}</a></li>
@else
<li><a id="ban" href="javascript:changeBanStatus('{{ $uid }}');">封禁</a></li>
<li><a id="ban" href="javascript:changeBanStatus('{{ $uid }}');">{{ trans('admin.users.operations.ban.ban.text') }}</a></li>
@endif
{{-- If current user is ordinary admin --}}
@else
@if ($permission == "1" || $permission == "2")
<li><a href="javascript:;">无法封禁管理员</a></li>
@elseif ($permission == "0")
<li><a id="ban" href="javascript:changeBanStatus('{{ $uid }}');">封禁</a></li>
@else
<li><a id="ban" href="javascript:changeBanStatus('{{ $uid }}');">解封</a></li>
@endif
@endif
@endunless
</ul>
</div>
{{-- If current user is super admin --}}
@if (app('user.current')->getPermission() == App\Models\User::SUPER_ADMIN)
@if (app('user.current')->getPermission() == User::SUPER_ADMIN)
@if ($permission == "2")
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="超级管理员账号不能被这样删除的啦">删除用户</a>
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ trans('admin.users.operations.delete.cant-super-admin') }}">{{ trans('admin.users.operations.delete.delete') }}</a>
@else
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $uid }}');">删除用户</a>
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $uid }}');">{{ trans('admin.users.operations.delete.delete') }}</a>
@endif
@else
@if ($permission == "1" || $permission == "2")
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="你不能删除管理员账号哦">删除用户</a>
<a class="btn btn-danger btn-sm" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ trans('admin.users.operations.delete-cant-admin') }}">{{ trans('admin.users.operations.delete.delete') }}</a>
@else
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $uid }}');">删除用户</a>
<a class="btn btn-danger btn-sm" href="javascript:deleteUserAccount('{{ $uid }}');">{{ trans('admin.users.operations.delete.delete') }}</a>
@endif
@endif

View File

@ -1 +1 @@
<input type="text" class="form-control score" value="{{ $score }}" title="输入修改后的积分,回车提交" data-toggle="tooltip" data-placement="right">
<input type="text" class="form-control score" value="{{ $score }}" title="{{ trans('admin.users.score.tip') }}" data-toggle="tooltip" data-placement="right">