up
This commit is contained in:
@@ -41,25 +41,33 @@ class Crawler extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function getUserConfig()
|
public function getUserConfig()
|
||||||
{
|
{
|
||||||
|
// 强制返回JSON,设置响应头
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
$username = Session::get('username', '');
|
try {
|
||||||
|
$username = Session::get('username', '');
|
||||||
if (empty($username)) {
|
|
||||||
|
if (empty($username)) {
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '未登录',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$configService = new UserConfigService();
|
||||||
|
$config = $configService->getUserConfig($username);
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 1,
|
||||||
|
'data' => $config,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
return json([
|
return json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '未登录',
|
'msg' => '获取失败: ' . $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$configService = new UserConfigService();
|
|
||||||
$config = $configService->getUserConfig($username);
|
|
||||||
|
|
||||||
return json([
|
|
||||||
'code' => 1,
|
|
||||||
'data' => $config,
|
|
||||||
'msg' => '获取成功',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,30 +75,38 @@ class Crawler extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function saveUserConfig()
|
public function saveUserConfig()
|
||||||
{
|
{
|
||||||
|
// 强制返回JSON,设置响应头
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
$username = Session::get('username', '');
|
try {
|
||||||
|
$username = Session::get('username', '');
|
||||||
if (empty($username)) {
|
|
||||||
|
if (empty($username)) {
|
||||||
|
return json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '未登录',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = [
|
||||||
|
'jsessionid1' => $this->request->param('jsessionid1', ''),
|
||||||
|
'jsessionid2' => $this->request->param('jsessionid2', ''),
|
||||||
|
'serverid' => $this->request->param('serverid', ''),
|
||||||
|
'examid' => $this->request->param('examid', ''),
|
||||||
|
'bmid' => $this->request->param('bmid', ''),
|
||||||
|
'userid' => $this->request->param('userid', ''),
|
||||||
|
];
|
||||||
|
|
||||||
|
$configService = new UserConfigService();
|
||||||
|
$result = $configService->saveUserConfig($username, $config);
|
||||||
|
|
||||||
|
return json($result);
|
||||||
|
} catch (\Exception $e) {
|
||||||
return json([
|
return json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '未登录',
|
'msg' => '保存失败: ' . $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = [
|
|
||||||
'jsessionid1' => $this->request->param('jsessionid1', ''),
|
|
||||||
'jsessionid2' => $this->request->param('jsessionid2', ''),
|
|
||||||
'serverid' => $this->request->param('serverid', ''),
|
|
||||||
'examid' => $this->request->param('examid', ''),
|
|
||||||
'bmid' => $this->request->param('bmid', ''),
|
|
||||||
'userid' => $this->request->param('userid', ''),
|
|
||||||
];
|
|
||||||
|
|
||||||
$configService = new UserConfigService();
|
|
||||||
$result = $configService->saveUserConfig($username, $config);
|
|
||||||
|
|
||||||
return json($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,9 +20,16 @@ class Auth
|
|||||||
// 检查是否已登录
|
// 检查是否已登录
|
||||||
$username = session('username');
|
$username = session('username');
|
||||||
|
|
||||||
|
// 获取路径信息
|
||||||
|
$pathinfo = $request->pathinfo();
|
||||||
|
|
||||||
|
// 判断是否为API请求(非index页面)
|
||||||
|
$isApiRequest = $pathinfo !== 'crawler' && strpos($pathinfo, 'crawler/') === 0;
|
||||||
|
|
||||||
if (empty($username)) {
|
if (empty($username)) {
|
||||||
// 如果是AJAX请求,返回JSON
|
// 如果是API请求,返回JSON
|
||||||
if ($request->isAjax()) {
|
if ($isApiRequest || $request->isAjax()) {
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
return json([
|
return json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '请先登录',
|
'msg' => '请先登录',
|
||||||
|
|||||||
Reference in New Issue
Block a user