2016-07-22 19:36:24 +08:00
|
|
|
<?php
|
|
|
|
|
2016-08-28 10:05:21 +08:00
|
|
|
namespace App\Http\Controllers;
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2019-03-21 12:44:15 +08:00
|
|
|
use Cache;
|
2016-11-12 23:50:41 +08:00
|
|
|
use Option;
|
2018-02-24 13:32:30 +08:00
|
|
|
use Carbon\Carbon;
|
2016-07-22 19:36:24 +08:00
|
|
|
use App\Models\User;
|
2016-07-23 15:20:10 +08:00
|
|
|
use App\Models\Player;
|
|
|
|
use App\Models\Texture;
|
2019-03-16 19:56:50 +08:00
|
|
|
use Illuminate\Support\Str;
|
2016-12-31 23:28:09 +08:00
|
|
|
use App\Services\OptionForm;
|
2019-03-02 22:58:37 +08:00
|
|
|
use Illuminate\Http\Request;
|
2019-03-19 23:35:13 +08:00
|
|
|
use Illuminate\Support\Collection;
|
2018-07-20 14:42:43 +08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2019-03-21 22:51:30 +08:00
|
|
|
use Illuminate\Support\Facades\Redis;
|
2016-10-23 11:41:52 +08:00
|
|
|
use App\Services\Repositories\UserRepository;
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
class AdminController extends Controller
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
2019-03-19 19:16:03 +08:00
|
|
|
public function chartData()
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
2018-02-24 13:32:30 +08:00
|
|
|
$today = Carbon::today()->timestamp;
|
|
|
|
|
2019-03-19 23:35:13 +08:00
|
|
|
$xAxis = Collection::times(30, function ($number) use ($today) {
|
|
|
|
$time = Carbon::createFromTimestamp($today - (31 - $number) * 86400);
|
|
|
|
return $time->format('m-d');
|
|
|
|
});
|
2018-02-24 13:32:30 +08:00
|
|
|
|
2019-03-19 23:35:13 +08:00
|
|
|
$oneMonthAgo = Carbon::createFromTimestamp($today - 30 * 86400);
|
|
|
|
|
2019-03-19 23:48:45 +08:00
|
|
|
$grouping = function ($field) {
|
|
|
|
return function ($item) use ($field) {
|
|
|
|
return substr($item->$field, 5, 5);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
$mapping = function ($item) {
|
|
|
|
return count($item);
|
|
|
|
};
|
|
|
|
$aligning = function ($data) {
|
|
|
|
return function ($day) use ($data) {
|
|
|
|
return $data->get($day) ?? 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-19 23:35:13 +08:00
|
|
|
$userRegistration = User::where('register_at', '>=', $oneMonthAgo)
|
|
|
|
->select('register_at')
|
|
|
|
->get()
|
2019-03-19 23:48:45 +08:00
|
|
|
->groupBy($grouping('register_at'))
|
|
|
|
->map($mapping);
|
2019-03-19 23:35:13 +08:00
|
|
|
|
|
|
|
$textureUploads = Texture::where('upload_at', '>=', $oneMonthAgo)
|
|
|
|
->select('upload_at')
|
|
|
|
->get()
|
2019-03-19 23:48:45 +08:00
|
|
|
->groupBy($grouping('upload_at'))
|
|
|
|
->map($mapping);
|
2018-02-24 13:32:30 +08:00
|
|
|
|
2019-03-19 19:16:03 +08:00
|
|
|
return [
|
|
|
|
'labels' => [
|
|
|
|
trans('admin.index.user-registration'),
|
|
|
|
trans('admin.index.texture-uploads')
|
2019-03-02 22:58:37 +08:00
|
|
|
],
|
2019-03-19 19:16:03 +08:00
|
|
|
'xAxis' => $xAxis,
|
2019-03-19 23:35:13 +08:00
|
|
|
'data' => [
|
2019-03-19 23:48:45 +08:00
|
|
|
$xAxis->map($aligning($userRegistration)),
|
|
|
|
$xAxis->map($aligning($textureUploads)),
|
2019-03-19 23:35:13 +08:00
|
|
|
]
|
2018-02-24 17:08:32 +08:00
|
|
|
];
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
|
2016-12-31 21:16:04 +08:00
|
|
|
public function customize(Request $request)
|
2016-07-23 15:20:10 +08:00
|
|
|
{
|
2019-03-02 22:58:37 +08:00
|
|
|
if ($request->input('action') == 'color') {
|
2016-12-31 21:16:04 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'color_scheme' => 'required',
|
2016-12-31 21:16:04 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$color_scheme = str_replace('_', '-', $request->input('color_scheme'));
|
|
|
|
option(['color_scheme' => $color_scheme]);
|
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
return json(trans('admin.customize.change-color.success'), 0);
|
2016-12-31 21:16:04 +08:00
|
|
|
}
|
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
$homepage = Option::form('homepage', OptionForm::AUTO_DETECT, function ($form) {
|
2017-01-18 22:57:15 +08:00
|
|
|
$form->text('home_pic_url')->hint();
|
2016-12-27 23:05:09 +08:00
|
|
|
|
2017-01-18 22:57:15 +08:00
|
|
|
$form->text('favicon_url')->hint()->description();
|
2016-12-31 13:36:46 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->select('copyright_prefer')
|
2016-12-30 20:55:33 +08:00
|
|
|
->option('0', 'Powered with ❤ by Blessing Skin Server.')
|
|
|
|
->option('1', 'Powered by Blessing Skin Server.')
|
2016-12-31 23:28:09 +08:00
|
|
|
->option('2', 'Proudly powered by Blessing Skin Server.')
|
|
|
|
->option('3', '由 Blessing Skin Server 强力驱动.')
|
|
|
|
->option('4', '自豪地采用 Blessing Skin Server.')
|
2017-01-18 22:57:15 +08:00
|
|
|
->description();
|
2016-12-29 23:14:09 +08:00
|
|
|
|
2017-01-18 22:57:15 +08:00
|
|
|
$form->textarea('copyright_text')->rows(6)->description();
|
2018-07-22 16:46:37 +08:00
|
|
|
})->handle(function () {
|
|
|
|
Option::set('copyright_prefer_'.config('app.locale'), request('copyright_prefer'));
|
2018-06-19 19:52:16 +08:00
|
|
|
Option::set('copyright_text_'.config('app.locale'), request('copyright_text'));
|
|
|
|
});
|
2016-12-27 23:05:09 +08:00
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
$customJsCss = Option::form('customJsCss', OptionForm::AUTO_DETECT, function ($form) {
|
2016-12-29 23:14:09 +08:00
|
|
|
$form->textarea('custom_css', 'CSS')->rows(6);
|
|
|
|
$form->textarea('custom_js', 'JavaScript')->rows(6);
|
2017-01-18 22:57:15 +08:00
|
|
|
})->addMessage()->handle();
|
2016-12-29 23:14:09 +08:00
|
|
|
|
|
|
|
return view('admin.customize', ['forms' => compact('homepage', 'customJsCss')]);
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2016-07-29 11:52:45 +08:00
|
|
|
public function score()
|
|
|
|
{
|
2019-03-02 22:58:37 +08:00
|
|
|
$rate = Option::form('rate', OptionForm::AUTO_DETECT, function ($form) {
|
2017-01-18 22:57:15 +08:00
|
|
|
$form->group('score_per_storage')->text('score_per_storage')->addon();
|
2016-12-21 22:53:53 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->group('private_score_per_storage')
|
2017-01-18 22:57:15 +08:00
|
|
|
->text('private_score_per_storage')->addon()->hint();
|
2016-12-21 22:53:53 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->group('score_per_closet_item')
|
2017-01-18 22:57:15 +08:00
|
|
|
->text('score_per_closet_item')->addon();
|
2016-12-28 13:08:17 +08:00
|
|
|
|
2017-01-18 22:57:15 +08:00
|
|
|
$form->checkbox('return_score')->label();
|
2016-12-21 22:53:53 +08:00
|
|
|
|
2017-01-18 22:57:15 +08:00
|
|
|
$form->group('score_per_player')->text('score_per_player')->addon();
|
2016-12-21 22:53:53 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->text('user_initial_score');
|
2016-12-21 22:53:53 +08:00
|
|
|
})->handle();
|
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
$sign = Option::form('sign', OptionForm::AUTO_DETECT, function ($form) {
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->group('sign_score')
|
2017-07-14 09:17:42 +08:00
|
|
|
->text('sign_score_from')->addon(trans('options.sign.sign_score.addon1'))
|
|
|
|
->text('sign_score_to')->addon(trans('options.sign.sign_score.addon2'));
|
2016-12-29 23:14:09 +08:00
|
|
|
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->group('sign_gap_time')->text('sign_gap_time')->addon();
|
2016-12-29 23:14:09 +08:00
|
|
|
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->checkbox('sign_after_zero')->label()->hint();
|
2019-03-02 22:58:37 +08:00
|
|
|
})->after(function () {
|
2017-11-02 16:50:00 +08:00
|
|
|
$sign_score = request('sign_score_from').','.request('sign_score_to');
|
2016-12-29 23:14:09 +08:00
|
|
|
Option::set('sign_score', $sign_score);
|
|
|
|
})->with([
|
|
|
|
'sign_score_from' => @explode(',', option('sign_score'))[0],
|
2019-03-02 22:58:37 +08:00
|
|
|
'sign_score_to' => @explode(',', option('sign_score'))[1],
|
2017-11-02 16:50:00 +08:00
|
|
|
])->handle();
|
2016-12-29 23:14:09 +08:00
|
|
|
|
2019-03-20 23:28:04 +08:00
|
|
|
$sharing = Option::form('sharing', OptionForm::AUTO_DETECT, function ($form) {
|
|
|
|
$form->group('score_award_per_texture')
|
|
|
|
->text('score_award_per_texture')
|
|
|
|
->addon(trans('general.user.score'));
|
|
|
|
$form->checkbox('take_back_scores_after_deletion')->label();
|
|
|
|
$form->group('score_award_per_like')
|
|
|
|
->text('score_award_per_like')
|
|
|
|
->addon(trans('general.user.score'));
|
|
|
|
})->handle();
|
|
|
|
|
|
|
|
return view('admin.score', ['forms' => compact('rate', 'sign', 'sharing')]);
|
2016-07-29 11:52:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
public function options()
|
|
|
|
{
|
2019-03-02 22:58:37 +08:00
|
|
|
$general = Option::form('general', OptionForm::AUTO_DETECT, function ($form) {
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->text('site_name');
|
2018-07-06 14:49:39 +08:00
|
|
|
$form->text('site_description')->description();
|
|
|
|
|
2017-11-02 16:50:00 +08:00
|
|
|
$form->text('site_url')
|
|
|
|
->hint()
|
|
|
|
->format(function ($url) {
|
2017-11-07 21:40:53 +08:00
|
|
|
if (ends_with($url, '/')) {
|
2017-11-02 16:50:00 +08:00
|
|
|
$url = substr($url, 0, -1);
|
2017-11-07 21:40:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ends_with($url, '/index.php')) {
|
|
|
|
$url = substr($url, 0, -10);
|
|
|
|
}
|
|
|
|
|
2017-11-02 16:50:00 +08:00
|
|
|
return $url;
|
|
|
|
});
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->checkbox('user_can_register')->label();
|
2018-08-17 17:03:38 +08:00
|
|
|
$form->checkbox('register_with_player_name')->label();
|
2018-08-17 12:32:44 +08:00
|
|
|
$form->checkbox('require_verification')->label();
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->text('regs_per_ip');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2017-06-28 19:50:34 +08:00
|
|
|
$form->select('ip_get_method')
|
|
|
|
->option('0', trans('options.general.ip_get_method.HTTP_X_FORWARDED_FOR'))
|
|
|
|
->option('1', trans('options.general.ip_get_method.REMOTE_ADDR'))
|
|
|
|
->hint();
|
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->group('max_upload_file_size')
|
2016-12-28 23:28:15 +08:00
|
|
|
->text('max_upload_file_size')->addon('KB')
|
2017-01-17 22:16:03 +08:00
|
|
|
->hint(trans('options.general.max_upload_file_size.hint', ['size' => ini_get('upload_max_filesize')]));
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2018-06-19 11:51:34 +08:00
|
|
|
$form->select('player_name_rule')
|
|
|
|
->option('official', trans('options.general.player_name_rule.official'))
|
|
|
|
->option('cjk', trans('options.general.player_name_rule.cjk'))
|
|
|
|
->option('custom', trans('options.general.player_name_rule.custom'));
|
|
|
|
|
|
|
|
$form->text('custom_player_name_regexp')->hint()->placeholder();
|
|
|
|
|
|
|
|
$form->group('player_name_length')
|
|
|
|
->text('player_name_length_min')
|
2018-09-08 10:30:24 +08:00
|
|
|
->addon('~')
|
2018-06-19 11:51:34 +08:00
|
|
|
->text('player_name_length_max')
|
2018-09-08 10:30:24 +08:00
|
|
|
->addon(trans('options.general.player_name_length.suffix'));
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->select('api_type')
|
2016-12-28 23:28:15 +08:00
|
|
|
->option('0', 'CustomSkinLoader API')
|
|
|
|
->option('1', 'UniversalSkinAPI');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->checkbox('auto_del_invalid_texture')->label()->hint();
|
2016-12-28 23:28:15 +08:00
|
|
|
|
2018-07-22 09:38:42 +08:00
|
|
|
$form->checkbox('allow_downloading_texture')->label();
|
|
|
|
|
2018-07-20 15:41:15 +08:00
|
|
|
$form->text('texture_name_regexp')->hint()->placeholder();
|
|
|
|
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->textarea('comment_script')->rows(6)->description();
|
2018-07-06 14:49:39 +08:00
|
|
|
})->handle(function () {
|
|
|
|
Option::set('site_name_'.config('app.locale'), request('site_name'));
|
|
|
|
Option::set('site_description_'.config('app.locale'), request('site_description'));
|
|
|
|
});
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2018-06-19 19:52:16 +08:00
|
|
|
$announ = Option::form('announ', OptionForm::AUTO_DETECT, function ($form) {
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->textarea('announcement')->rows(10)->description();
|
2018-07-06 14:49:39 +08:00
|
|
|
})->renderWithOutTable()->handle(function () {
|
2018-06-19 19:52:16 +08:00
|
|
|
Option::set('announcement_'.config('app.locale'), request('announcement'));
|
|
|
|
});
|
2016-12-29 13:11:46 +08:00
|
|
|
|
2019-03-20 10:01:42 +08:00
|
|
|
$meta = Option::form('meta', OptionForm::AUTO_DETECT, function ($form) {
|
2019-03-20 23:28:04 +08:00
|
|
|
$form->text('meta_keywords')->hint();
|
|
|
|
$form->text('meta_description')->hint();
|
|
|
|
$form->textarea('meta_extras')->rows(6);
|
2019-03-20 10:01:42 +08:00
|
|
|
})->handle();
|
|
|
|
|
|
|
|
return view('admin.options')
|
|
|
|
->with('forms', compact('general', 'announ', 'meta'));
|
|
|
|
}
|
|
|
|
|
2019-03-21 12:44:15 +08:00
|
|
|
public function resource(Request $request)
|
2019-03-20 10:01:42 +08:00
|
|
|
{
|
2019-03-02 22:58:37 +08:00
|
|
|
$resources = Option::form('resources', OptionForm::AUTO_DETECT, function ($form) {
|
2017-01-17 22:16:03 +08:00
|
|
|
$form->checkbox('force_ssl')->label()->hint();
|
|
|
|
$form->checkbox('auto_detect_asset_url')->label()->description();
|
2018-07-22 16:42:58 +08:00
|
|
|
$form->checkbox('return_204_when_notfound')->label()->description();
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2016-12-31 23:28:09 +08:00
|
|
|
$form->text('cache_expire_time')->hint(OptionForm::AUTO_DETECT);
|
2019-03-16 19:56:50 +08:00
|
|
|
$form->text('cdn_address')
|
|
|
|
->hint(OptionForm::AUTO_DETECT)
|
|
|
|
->description(OptionForm::AUTO_DETECT);
|
|
|
|
})
|
2019-03-20 10:01:42 +08:00
|
|
|
->type('primary')
|
2019-03-16 19:56:50 +08:00
|
|
|
->hint(OptionForm::AUTO_DETECT)
|
|
|
|
->after(function () {
|
|
|
|
$cdnAddress = request('cdn_address');
|
|
|
|
if ($cdnAddress == null) {
|
|
|
|
$cdnAddress = '';
|
|
|
|
}
|
|
|
|
if (Str::endsWith($cdnAddress, '/')) {
|
|
|
|
$cdnAddress = substr($cdnAddress, 0, -1);
|
|
|
|
}
|
|
|
|
Option::set('cdn_address', $cdnAddress);
|
|
|
|
})
|
|
|
|
->handle();
|
2016-11-12 23:50:41 +08:00
|
|
|
|
2019-03-20 11:00:14 +08:00
|
|
|
$redis = Option::form('redis', 'Redis', function ($form) {
|
2019-03-21 12:44:15 +08:00
|
|
|
$form->checkbox('enable_redis')->label()->description();
|
2019-03-20 11:00:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (option('enable_redis')) {
|
|
|
|
try {
|
|
|
|
Redis::ping();
|
|
|
|
$redis->addMessage(trans('options.redis.connect.success'), 'success');
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$redis->addMessage(
|
|
|
|
trans('options.redis.connect.failed', ['msg' => $e->getMessage()]),
|
|
|
|
'danger'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$redis->handle();
|
|
|
|
|
2019-03-21 12:44:15 +08:00
|
|
|
$cache = Option::form('cache', OptionForm::AUTO_DETECT, function ($form) {
|
|
|
|
$form->checkbox('enable_avatar_cache')->label();
|
|
|
|
$form->checkbox('enable_preview_cache')->label();
|
|
|
|
$form->checkbox('enable_json_cache', 'JSON Profile')->label();
|
|
|
|
$form->checkbox('enable_notfound_cache', '404')->label();
|
|
|
|
})
|
|
|
|
->type('warning')
|
|
|
|
->addButton([
|
|
|
|
'text' => trans('options.cache.clear'),
|
|
|
|
'type' => 'a',
|
|
|
|
'class' => 'pull-right',
|
|
|
|
'style' => 'warning',
|
|
|
|
'href' => '?clear-cache',
|
|
|
|
])
|
|
|
|
->addMessage(trans('options.cache.driver', ['driver' => config('cache.default')]), 'info');
|
|
|
|
|
|
|
|
if ($request->has('clear-cache')) {
|
|
|
|
Cache::flush();
|
|
|
|
$cache->addMessage(trans('options.cache.cleared'), 'success');
|
|
|
|
}
|
|
|
|
$cache->handle();
|
|
|
|
|
2019-03-20 10:01:42 +08:00
|
|
|
return view('admin.resource')
|
2019-03-21 12:44:15 +08:00
|
|
|
->with('forms', compact('resources', 'redis', 'cache'));
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2017-04-27 18:02:05 +08:00
|
|
|
public function getUserData(Request $request)
|
2016-12-31 11:38:07 +08:00
|
|
|
{
|
2018-08-13 11:08:14 +08:00
|
|
|
$isSingleUser = $request->has('uid');
|
2017-04-27 18:02:05 +08:00
|
|
|
|
2018-08-13 11:08:14 +08:00
|
|
|
if ($isSingleUser) {
|
2018-08-17 12:32:44 +08:00
|
|
|
$users = User::select(['uid', 'email', 'nickname', 'score', 'permission', 'register_at', 'verified'])
|
2018-08-13 11:08:14 +08:00
|
|
|
->where('uid', intval($request->input('uid')))
|
|
|
|
->get();
|
2017-04-27 18:02:05 +08:00
|
|
|
} else {
|
2018-08-13 11:08:14 +08:00
|
|
|
$search = $request->input('search', '');
|
|
|
|
$sortField = $request->input('sortField', 'uid');
|
|
|
|
$sortType = $request->input('sortType', 'asc');
|
|
|
|
$page = $request->input('page', 1);
|
|
|
|
$perPage = $request->input('perPage', 10);
|
|
|
|
|
2018-08-17 12:32:44 +08:00
|
|
|
$users = User::select(['uid', 'email', 'nickname', 'score', 'permission', 'register_at', 'verified'])
|
2019-03-02 22:58:37 +08:00
|
|
|
->where('uid', 'like', '%'.$search.'%')
|
|
|
|
->orWhere('email', 'like', '%'.$search.'%')
|
|
|
|
->orWhere('nickname', 'like', '%'.$search.'%')
|
|
|
|
->orWhere('score', 'like', '%'.$search.'%')
|
2018-08-13 11:08:14 +08:00
|
|
|
->orderBy($sortField, $sortType)
|
|
|
|
->offset(($page - 1) * $perPage)
|
|
|
|
->limit($perPage)
|
|
|
|
->get();
|
2017-04-27 18:02:05 +08:00
|
|
|
}
|
2016-12-31 11:38:07 +08:00
|
|
|
|
2018-08-13 11:08:14 +08:00
|
|
|
$users->transform(function ($user) {
|
|
|
|
$user->operations = auth()->user()->permission;
|
|
|
|
$user->players_count = $user->players->count();
|
2019-03-02 22:58:37 +08:00
|
|
|
|
2018-08-13 11:08:14 +08:00
|
|
|
return $user;
|
|
|
|
});
|
|
|
|
|
|
|
|
return [
|
|
|
|
'totalRecords' => $isSingleUser ? 1 : User::count(),
|
2019-03-02 22:58:37 +08:00
|
|
|
'data' => $users,
|
2018-08-13 11:08:14 +08:00
|
|
|
];
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2017-04-27 18:02:05 +08:00
|
|
|
public function getPlayerData(Request $request)
|
2016-12-31 13:07:00 +08:00
|
|
|
{
|
2018-08-13 11:08:14 +08:00
|
|
|
$isSpecifiedUser = $request->has('uid');
|
|
|
|
|
|
|
|
if ($isSpecifiedUser) {
|
2019-03-13 13:16:51 +08:00
|
|
|
$players = Player::select(['pid', 'uid', 'name', 'tid_skin', 'tid_cape', 'last_modified'])
|
2018-08-13 11:08:14 +08:00
|
|
|
->where('uid', intval($request->input('uid')))
|
|
|
|
->get();
|
2017-04-27 18:02:05 +08:00
|
|
|
} else {
|
2018-08-13 11:08:14 +08:00
|
|
|
$search = $request->input('search', '');
|
|
|
|
$sortField = $request->input('sortField', 'pid');
|
|
|
|
$sortType = $request->input('sortType', 'asc');
|
|
|
|
$page = $request->input('page', 1);
|
|
|
|
$perPage = $request->input('perPage', 10);
|
|
|
|
|
2019-03-13 13:16:51 +08:00
|
|
|
$players = Player::select(['pid', 'uid', 'name', 'tid_skin', 'tid_cape', 'last_modified'])
|
2019-03-02 22:58:37 +08:00
|
|
|
->where('pid', 'like', '%'.$search.'%')
|
|
|
|
->orWhere('uid', 'like', '%'.$search.'%')
|
2019-03-13 13:16:51 +08:00
|
|
|
->orWhere('name', 'like', '%'.$search.'%')
|
2018-08-13 11:08:14 +08:00
|
|
|
->orderBy($sortField, $sortType)
|
|
|
|
->offset(($page - 1) * $perPage)
|
|
|
|
->limit($perPage)
|
|
|
|
->get();
|
2017-04-27 18:02:05 +08:00
|
|
|
}
|
2016-12-31 13:07:00 +08:00
|
|
|
|
2018-08-13 11:08:14 +08:00
|
|
|
return [
|
|
|
|
'totalRecords' => $isSpecifiedUser ? 1 : Player::count(),
|
2019-03-02 22:58:37 +08:00
|
|
|
'data' => $players,
|
2018-08-13 11:08:14 +08:00
|
|
|
];
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-02 22:58:37 +08:00
|
|
|
* Handle ajax request from /admin/users.
|
2016-09-04 15:35:12 +08:00
|
|
|
*
|
|
|
|
* @param Request $request
|
2018-07-20 14:42:43 +08:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2016-07-23 15:20:10 +08:00
|
|
|
*/
|
2016-10-23 11:41:52 +08:00
|
|
|
public function userAjaxHandler(Request $request, UserRepository $users)
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
2016-09-04 15:35:12 +08:00
|
|
|
$action = $request->input('action');
|
2018-07-20 14:42:43 +08:00
|
|
|
$user = $users->get($request->input('uid'));
|
|
|
|
$currentUser = Auth::user();
|
2016-07-29 15:31:05 +08:00
|
|
|
|
2017-07-14 08:21:29 +08:00
|
|
|
if (! $user) {
|
2016-12-31 21:16:04 +08:00
|
|
|
return json(trans('admin.users.operations.non-existent'), 1);
|
2017-07-14 08:21:29 +08:00
|
|
|
}
|
|
|
|
|
2019-03-18 13:24:03 +08:00
|
|
|
if ($user->uid !== $currentUser->uid && $user->permission >= $currentUser->permission) {
|
|
|
|
return json(trans('admin.users.operations.no-permission'), 1);
|
2017-07-14 08:21:29 +08:00
|
|
|
}
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
if ($action == 'email') {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'email' => 'required|email',
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2017-04-27 09:25:42 +08:00
|
|
|
if ($users->get($request->input('email'), 'email')) {
|
|
|
|
return json(trans('admin.users.operations.email.existed', ['email' => $request->input('email')]), 1);
|
|
|
|
}
|
|
|
|
|
2016-12-31 21:16:04 +08:00
|
|
|
$user->setEmail($request->input('email'));
|
|
|
|
|
|
|
|
return json(trans('admin.users.operations.email.success'), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'verification') {
|
|
|
|
$user->verified = ! $user->verified;
|
2018-08-17 12:32:44 +08:00
|
|
|
$user->save();
|
|
|
|
|
|
|
|
return json(trans('admin.users.operations.verification.success'), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'nickname') {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'nickname' => 'required|no_special_chars',
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-12-31 21:16:04 +08:00
|
|
|
$user->setNickName($request->input('nickname'));
|
|
|
|
|
2017-07-14 08:21:29 +08:00
|
|
|
return json(trans('admin.users.operations.nickname.success', [
|
2019-03-02 22:58:37 +08:00
|
|
|
'new' => $request->input('nickname'),
|
2017-07-14 08:21:29 +08:00
|
|
|
]), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'password') {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'password' => 'required|min:8|max:16',
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2018-07-19 10:31:44 +08:00
|
|
|
$user->changePassword($request->input('password'));
|
2016-12-31 21:16:04 +08:00
|
|
|
|
|
|
|
return json(trans('admin.users.operations.password.success'), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'score') {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'score' => 'required|integer',
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-12-31 21:16:04 +08:00
|
|
|
$user->setScore($request->input('score'));
|
|
|
|
|
|
|
|
return json(trans('admin.users.operations.score.success'), 0);
|
2019-03-18 13:24:03 +08:00
|
|
|
} elseif ($action == 'permission') {
|
|
|
|
$user->permission = $this->validate($request, [
|
|
|
|
'permission' => 'required|in:-1,0,1'
|
|
|
|
])['permission'];
|
|
|
|
$user->save();
|
2016-12-31 21:16:04 +08:00
|
|
|
|
|
|
|
return json([
|
2019-03-18 13:24:03 +08:00
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans('admin.users.operations.permission'),
|
2016-12-31 21:16:04 +08:00
|
|
|
]);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'delete') {
|
2016-12-31 21:16:04 +08:00
|
|
|
$user->delete();
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-12-31 21:16:04 +08:00
|
|
|
return json(trans('admin.users.operations.delete.success'), 0);
|
2017-11-02 16:50:00 +08:00
|
|
|
} else {
|
|
|
|
return json(trans('admin.users.operations.invalid'), 1);
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
/**
|
2019-03-02 22:58:37 +08:00
|
|
|
* Handle ajax request from /admin/players.
|
2016-07-23 15:20:10 +08:00
|
|
|
*/
|
2016-10-23 11:41:52 +08:00
|
|
|
public function playerAjaxHandler(Request $request, UserRepository $users)
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
2017-11-02 16:50:00 +08:00
|
|
|
$action = $request->input('action');
|
2018-07-20 14:42:43 +08:00
|
|
|
$currentUser = Auth::user();
|
2016-10-16 18:16:15 +08:00
|
|
|
$player = Player::find($request->input('pid'));
|
|
|
|
|
2017-07-14 08:21:29 +08:00
|
|
|
if (! $player) {
|
2017-11-02 16:50:00 +08:00
|
|
|
return json(trans('general.unexistent-player'), 1);
|
2017-07-14 08:21:29 +08:00
|
|
|
}
|
|
|
|
|
2018-07-20 14:42:43 +08:00
|
|
|
if ($player->user()->first()->uid !== $currentUser->uid) {
|
|
|
|
if ($player->user->permission >= $currentUser->permission) {
|
2017-08-06 22:53:02 +08:00
|
|
|
return json(trans('admin.players.no-permission'), 1);
|
|
|
|
}
|
2017-07-14 08:21:29 +08:00
|
|
|
}
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
if ($action == 'texture') {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 21:13:17 +08:00
|
|
|
'type' => 'required',
|
2019-03-02 22:58:37 +08:00
|
|
|
'tid' => 'required|integer',
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
if (! Texture::find($request->tid) && $request->tid != 0) {
|
2016-12-31 21:16:04 +08:00
|
|
|
return json(trans('admin.players.textures.non-existent', ['tid' => $request->tid]), 1);
|
2019-03-02 22:58:37 +08:00
|
|
|
}
|
2016-12-31 21:16:04 +08:00
|
|
|
|
2019-03-02 21:13:17 +08:00
|
|
|
$player->setTexture(['tid_'.$request->type => $request->tid]);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2019-03-13 13:16:51 +08:00
|
|
|
return json(trans('admin.players.textures.success', ['player' => $player->name]), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'owner') {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'uid' => 'required|integer',
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
$user = $users->get($request->input('uid'));
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2019-03-02 22:58:37 +08:00
|
|
|
if (! $user) {
|
2016-12-31 21:16:04 +08:00
|
|
|
return json(trans('admin.users.operations.non-existent'), 1);
|
2019-03-02 22:58:37 +08:00
|
|
|
}
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-12-31 21:16:04 +08:00
|
|
|
$player->setOwner($request->input('uid'));
|
|
|
|
|
2019-03-13 13:16:51 +08:00
|
|
|
return json(trans('admin.players.owner.success', ['player' => $player->name, 'user' => $user->getNickName()]), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'delete') {
|
2016-12-31 21:16:04 +08:00
|
|
|
$player->delete();
|
|
|
|
|
|
|
|
return json(trans('admin.players.delete.success'), 0);
|
2019-03-02 22:58:37 +08:00
|
|
|
} elseif ($action == 'name') {
|
2017-11-02 16:50:00 +08:00
|
|
|
$this->validate($request, [
|
2019-03-02 22:58:37 +08:00
|
|
|
'name' => 'required|player_name|min:'.option('player_name_length_min').'|max:'.option('player_name_length_max'),
|
2017-11-02 16:50:00 +08:00
|
|
|
]);
|
|
|
|
|
2017-04-27 08:52:55 +08:00
|
|
|
$player->rename($request->input('name'));
|
|
|
|
|
2019-03-13 13:16:51 +08:00
|
|
|
return json(trans('admin.players.name.success', ['player' => $player->name]), 0, ['name' => $player->name]);
|
2017-11-02 16:50:00 +08:00
|
|
|
} else {
|
|
|
|
return json(trans('admin.users.operations.invalid'), 1);
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
|
2017-04-26 15:28:53 +08:00
|
|
|
/**
|
2019-03-02 22:58:37 +08:00
|
|
|
* Get one user information.
|
2017-04-26 15:28:53 +08:00
|
|
|
*
|
|
|
|
* @param string $uid
|
2017-11-02 16:50:00 +08:00
|
|
|
* @param UserRepository $users
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2017-04-26 15:28:53 +08:00
|
|
|
*/
|
|
|
|
public function getOneUser($uid, UserRepository $users)
|
|
|
|
{
|
|
|
|
$user = $users->get(intval($uid));
|
|
|
|
if ($user) {
|
|
|
|
return json('success', 0, ['user' => $user->makeHidden([
|
2019-03-02 22:58:37 +08:00
|
|
|
'password', 'ip', 'last_sign_at', 'register_at', 'remember_token',
|
2017-04-26 15:28:53 +08:00
|
|
|
])->toArray()]);
|
|
|
|
} else {
|
|
|
|
return json('No such user.', 1);
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|