forked from XiaoLFeng/XF_Index
Modify: 管理员修改友链
管理员修改友链操作,强制修改 Signed-off-by: XiaoLFeng <gm@x-lf.cn>
This commit is contained in:
parent
8b4782379b
commit
09b3c1e924
|
@ -12,10 +12,13 @@
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Response;
|
use Illuminate\Support\Facades\Response;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class Link extends Controller
|
class Link extends Controller
|
||||||
{
|
{
|
||||||
|
@ -124,11 +127,99 @@ protected function ViewSort(): Factory|View|Application
|
||||||
|
|
||||||
protected function ViewColor(): Factory|View|Application
|
protected function ViewColor(): Factory|View|Application
|
||||||
{
|
{
|
||||||
return view('console.friends-link.color',$this->data);
|
return view('console.friends-link.color', $this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function apiConsoleAdd() {
|
public function apiConsoleAdd()
|
||||||
|
{
|
||||||
// 检查数据
|
// 检查数据
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function apiConsoleEdit(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
// 检查用户是否登录
|
||||||
|
if (Auth::check()) {
|
||||||
|
if (Auth::user()->admin) {
|
||||||
|
// 处理获取数据
|
||||||
|
$dataCheck = Validator::make($request->all(), [
|
||||||
|
'userId' => 'required|int',
|
||||||
|
'userEmail' => 'required|email',
|
||||||
|
'userServerHost' => 'required|string',
|
||||||
|
'userBlog' => 'required|string',
|
||||||
|
'userUrl' => 'required|regex:#[a-zA-z]+://[^\s]*#',
|
||||||
|
'userDescription' => 'required|string',
|
||||||
|
'userIcon' => 'required|regex:#[a-zA-z]+://[^\s]*#',
|
||||||
|
'checkRssJudge' => 'boolean',
|
||||||
|
'userRss' => 'string|regex:#[a-zA-z]+://[^\s]*#',
|
||||||
|
'userSelColor' => 'required|int',
|
||||||
|
'userLocation' => 'required|string',
|
||||||
|
]);
|
||||||
|
if ($dataCheck->fails()) {
|
||||||
|
$errorType = array_keys($dataCheck->failed());
|
||||||
|
$i = 0;
|
||||||
|
foreach ($dataCheck->failed() as $valueData) {
|
||||||
|
$errorInfo[$errorType[$i]] = array_keys($valueData);
|
||||||
|
if ($i == 0) {
|
||||||
|
$errorSingle = [
|
||||||
|
'info' => $errorType[$i],
|
||||||
|
'need' => $errorInfo[$errorType[$i]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$returnData = [
|
||||||
|
'output' => 'DataFormatError',
|
||||||
|
'code' => 403,
|
||||||
|
'data' => [
|
||||||
|
'message' => '输入内容有错误',
|
||||||
|
'errorSingle' => $errorSingle,
|
||||||
|
'error' => $errorInfo,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// 更新数据库
|
||||||
|
DB::table('blog_link')
|
||||||
|
->where([['id', '=', $request->userId]])
|
||||||
|
->update([
|
||||||
|
'blogOwnEmail' => $request->userEmail,
|
||||||
|
'blogServerHost' => $request->userServerHost,
|
||||||
|
'blogName' => $request->userBlog,
|
||||||
|
'blogUrl' => $request->userUrl,
|
||||||
|
'blogDescription' => $request->userDescription,
|
||||||
|
'blogIcon' => $request->userIcon,
|
||||||
|
'blogRssJudge' => $request->checkRssJudge,
|
||||||
|
'blogRSS' => $request->userRss,
|
||||||
|
'blogSetColor' => $request->userSelColor,
|
||||||
|
'blogLocation' => $request->userLocation,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
]);
|
||||||
|
$returnData = [
|
||||||
|
'output' => 'Success',
|
||||||
|
'code' => 200,
|
||||||
|
'data' => [
|
||||||
|
'message' => '数据成功更新',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$returnData = [
|
||||||
|
'output' => 'NoPermission',
|
||||||
|
'code' => 403,
|
||||||
|
'data' => [
|
||||||
|
'message' => '没有权限',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$returnData = [
|
||||||
|
'output' => 'PleaseLogin',
|
||||||
|
'code' => 403,
|
||||||
|
'data' => [
|
||||||
|
'message' => '请登录',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return Response::json($returnData, $returnData['code']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,9 @@ class="text-black dark:text-white"></b> 条</p>
|
||||||
<div class="block lg:hidden col-span-10">
|
<div class="block lg:hidden col-span-10">
|
||||||
<div class="items-center justify-center rounded bg-gray-50 dark:bg-gray-800 shadow grid grid-cols-1">
|
<div class="items-center justify-center rounded bg-gray-50 dark:bg-gray-800 shadow grid grid-cols-1">
|
||||||
<div class="p-2 xl:p-8 grid grid-cols-2">
|
<div class="p-2 xl:p-8 grid grid-cols-2">
|
||||||
<button type="submit" class="m-2 text-white bg-green-500 hover:bg-green-600 focus:ring-4 focus:outline-none focus:ring-blue-300
|
<button onclick="ajax()" type="submit" class="m-2 text-white bg-green-500 hover:bg-green-600 focus:ring-4 focus:outline-none
|
||||||
font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-green-600 dark:hover:bg-green-700 dark:focus:ring-blue-800">
|
focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-green-600 dark:hover:bg-green-700
|
||||||
|
dark:focus:ring-blue-800">
|
||||||
<i class="bi bi-send"></i>
|
<i class="bi bi-send"></i>
|
||||||
<span class="ps-1">提交修改</span>
|
<span class="ps-1">提交修改</span>
|
||||||
</button>
|
</button>
|
||||||
|
@ -59,7 +60,7 @@ class="text-black dark:text-white"></b> 条</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-span-10 lg:col-span-7 items-center justify-center rounded bg-gray-50 dark:bg-gray-800 shadow">
|
<div class="col-span-10 lg:col-span-7 items-center justify-center rounded bg-gray-50 dark:bg-gray-800 shadow">
|
||||||
<div class="px-10 py-5">
|
<div class="px-10 py-5">
|
||||||
<form>
|
<form id="FormData" action="#" onsubmit="return false" method="POST">
|
||||||
<div class="grid gap-6 mb-6 md:grid-cols-2">
|
<div class="grid gap-6 mb-6 md:grid-cols-2">
|
||||||
<div>
|
<div>
|
||||||
<label for="userEmail" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">博主邮箱 <span class="text-red-700">*</span></label>
|
<label for="userEmail" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">博主邮箱 <span class="text-red-700">*</span></label>
|
||||||
|
@ -165,7 +166,8 @@ class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus
|
||||||
<div class="mb-6 grid grid-cols-1 md:grid-cols-3 items-end">
|
<div class="mb-6 grid grid-cols-1 md:grid-cols-3 items-end">
|
||||||
<div class="col-span-1 mb-3 md:mb-0">
|
<div class="col-span-1 mb-3 md:mb-0">
|
||||||
<label class="relative inline-flex">
|
<label class="relative inline-flex">
|
||||||
<input type="checkbox" id="checkRssJudge" value="1" @if($blog[0]->blogRssJudge) checked @endif class="sr-only peer">
|
<input type="checkbox" name="checkRssJudge" id="checkRssJudge" value="1" @if($blog[0]->blogRssJudge) checked @endif
|
||||||
|
class="sr-only peer">
|
||||||
<div
|
<div
|
||||||
class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
|
class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
|
||||||
<span class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300">我的博客拥有 RSS 地址</span>
|
<span class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300">我的博客拥有 RSS 地址</span>
|
||||||
|
@ -187,7 +189,7 @@ class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-w
|
||||||
</div>
|
</div>
|
||||||
<input type="text" name="userRss" id="userRss" value="{{ $blog[0]->blogRSS }}" placeholder="https://blog.x-lf.com/atom.xml"
|
<input type="text" name="userRss" id="userRss" value="{{ $blog[0]->blogRSS }}" placeholder="https://blog.x-lf.com/atom.xml"
|
||||||
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
|
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
|
||||||
disabled>
|
@if($blog[0]->blogRssJudge == 0)disabled @endif>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -196,7 +198,7 @@ class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus
|
||||||
<div>
|
<div>
|
||||||
<label for="userLocation" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">所属板块 <span
|
<label for="userLocation" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">所属板块 <span
|
||||||
class="text-red-700">*</span></label>
|
class="text-red-700">*</span></label>
|
||||||
<select id="userLocation"
|
<select id="userLocation" name="userLocation"
|
||||||
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
||||||
<option>请选择一个板块</option>
|
<option>请选择一个板块</option>
|
||||||
@if(empty($blogSort[0]))
|
@if(empty($blogSort[0]))
|
||||||
|
@ -229,7 +231,7 @@ class="w-16 h-16 p-1 rounded-full ring-2 ring-gray-300 dark:ring-gray-500 me-2 s
|
||||||
</div>
|
</div>
|
||||||
<div class="tooltip-arrow" data-popper-arrow></div>
|
<div class="tooltip-arrow" data-popper-arrow></div>
|
||||||
</div>
|
</div>
|
||||||
<select id="userSelColor"
|
<select id="userSelColor" name="userSelColor"
|
||||||
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
|
||||||
<option>请选择一个颜色</option>
|
<option>请选择一个颜色</option>
|
||||||
@if(empty($blogColor[0]))
|
@if(empty($blogColor[0]))
|
||||||
|
@ -242,6 +244,9 @@ class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus
|
||||||
@endif
|
@endif
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<label>
|
||||||
|
<input name="userId" id="userId" value="{{ $blog[0]->id }}" hidden="hidden"/>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -249,8 +254,9 @@ class="bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus
|
||||||
<div class="sm:hidden lg:block col-span-3">
|
<div class="sm:hidden lg:block col-span-3">
|
||||||
<div class="items-center justify-center rounded bg-gray-50 dark:bg-gray-800 shadow grid grid-cols-1 mb-4">
|
<div class="items-center justify-center rounded bg-gray-50 dark:bg-gray-800 shadow grid grid-cols-1 mb-4">
|
||||||
<div class="p-2 xl:p-8 grid grid-cols-2">
|
<div class="p-2 xl:p-8 grid grid-cols-2">
|
||||||
<button type="submit" class="m-2 text-white bg-green-500 hover:bg-green-600 focus:ring-4 focus:outline-none focus:ring-blue-300
|
<button onclick="ajax()" type="submit" class="m-2 text-white bg-green-500 hover:bg-green-600 focus:ring-4 focus:outline-none
|
||||||
font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-green-600 dark:hover:bg-green-700 dark:focus:ring-blue-800">
|
focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-green-600 dark:hover:bg-green-700
|
||||||
|
dark:focus:ring-blue-800">
|
||||||
<i class="bi bi-send"></i>
|
<i class="bi bi-send"></i>
|
||||||
<span class="ps-1">提交修改</span>
|
<span class="ps-1">提交修改</span>
|
||||||
</button>
|
</button>
|
||||||
|
@ -307,6 +313,15 @@ class="w-16 h-16 p-1 rounded-full ring-2 ring-gray-300 dark:ring-gray-500 me-2 s
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Toast -->
|
||||||
|
<div id="toast"
|
||||||
|
class="z-[9999] fixed top-5 left-5 hidden items-center w-full max-w-xs p-4 space-x-4 text-gray-500 bg-white divide-x divide-gray-200 rounded-lg shadow dark:text-gray-400 dark:divide-gray-700 space-x dark:bg-gray-800"
|
||||||
|
role="alert">
|
||||||
|
<div class="pl-4 text-sm font-normal">
|
||||||
|
<span id="toast-icon" class="pe-1"><i class="bi bi-info-circle text-blue-500"></i></span>
|
||||||
|
<span id="toast-info">Message sent successfully.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script src="{{ asset('js/app.js') }}"></script>
|
<script src="{{ asset('js/app.js') }}"></script>
|
||||||
<script src="{{ asset('js/jquery.js') }}"></script>
|
<script src="{{ asset('js/jquery.js') }}"></script>
|
||||||
|
@ -348,5 +363,65 @@ class="w-16 h-16 p-1 rounded-full ring-2 ring-gray-300 dark:ring-gray-500 me-2 s
|
||||||
$('#colorLight').addClass(colorLight);
|
$('#colorLight').addClass(colorLight);
|
||||||
$('#colorDark').addClass(colorDark);
|
$('#colorDark').addClass(colorDark);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
class Toast {
|
||||||
|
static toggle(data, icon) {
|
||||||
|
this.set(data, icon);
|
||||||
|
$('#toast').fadeIn(300);
|
||||||
|
setTimeout(function () {
|
||||||
|
$('#toast').fadeOut(300);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
static set(data, icon) {
|
||||||
|
$('#toast-icon').html(icon);
|
||||||
|
$('#toast-info').text(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Enum {
|
||||||
|
static userEmail = '用户邮箱';
|
||||||
|
static userServerHost = '服务商';
|
||||||
|
static userBlog = '博客名字';
|
||||||
|
static userUrl = '博客地址';
|
||||||
|
static userDescription = '博客描述';
|
||||||
|
static userIcon = '图片地址';
|
||||||
|
static checkRssJudge = 'RSS选项';
|
||||||
|
static userRss = 'RSS地址';
|
||||||
|
static userLocation = '所属位置';
|
||||||
|
static userSelColor = '选择颜色';
|
||||||
|
}
|
||||||
|
|
||||||
|
function ajax() {
|
||||||
|
$.ajax({
|
||||||
|
async: true,
|
||||||
|
method: "POST",
|
||||||
|
data: $('#FormData').serialize(),
|
||||||
|
url: '{{ route('api.link.console.edit') }}',
|
||||||
|
dataType: "json",
|
||||||
|
success: function (returnData) {
|
||||||
|
if (returnData.output === "Success") {
|
||||||
|
Toast.toggle('友链修改成功', '<i class="bi bi-check-circle text-green-500"></i>');
|
||||||
|
setTimeout(function () {
|
||||||
|
location.href = '{{ route('console.friends-link.list') }}';
|
||||||
|
}, 3000);
|
||||||
|
} else {
|
||||||
|
Toast('未知错误', '<i class="bi bi-x-circle text-red-500"></i>');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (returnData) {
|
||||||
|
Toast.set('其他错误', '<i class="bi bi-x-circle text-red-500"></i>');
|
||||||
|
if (returnData.responseJSON.output === 'DataFormatError') {
|
||||||
|
for (let key in Enum) {
|
||||||
|
if (returnData.responseJSON.data.errorSingle.info === key) {
|
||||||
|
Toast.toggle(Enum[key] + '错误,注意格式', '<i class="bi bi-x-circle text-red-500"></i>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.toggle('未知错误', '<i class="bi bi-x-circle text-red-500"></i>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Http\Controllers\Authme;
|
use App\Http\Controllers\Authme;
|
||||||
|
use App\Http\Controllers\Console\Link as ConsoleLink;
|
||||||
use App\Http\Controllers\Function\Link;
|
use App\Http\Controllers\Function\Link;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
@ -40,7 +41,8 @@
|
||||||
// 友链类
|
// 友链类
|
||||||
Route::prefix('link')->group(function () {
|
Route::prefix('link')->group(function () {
|
||||||
Route::prefix('console')->group(function () {
|
Route::prefix('console')->group(function () {
|
||||||
|
Route::post('add', [ConsoleLink::class, 'apiConsoleAdd'])->name('api.link.console.add');
|
||||||
|
Route::post('edit', [ConsoleLink::class, 'apiConsoleEdit'])->name('api.link.console.edit');
|
||||||
});
|
});
|
||||||
Route::prefix('custom')->group(function () {
|
Route::prefix('custom')->group(function () {
|
||||||
Route::post('add', [Link::class, 'apiCustomAdd'])->name('api.link.custom.add');
|
Route::post('add', [Link::class, 'apiCustomAdd'])->name('api.link.custom.add');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user