forked from vidar-team/hctf_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e64e93
commit 630aa25
Showing
6 changed files
with
97 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,15 +73,14 @@ public function delete(Request $request) | |
return APIReturn::error('invalid_parameters', $validator->errors()->all(), 400); | ||
} | ||
|
||
try{ | ||
try { | ||
$bulletin = Bulletin::find($request->input('bulletinId')); | ||
if (!$bulletin){ | ||
if (!$bulletin) { | ||
return APIReturn::error("bulletin_not_found", "该公告不存在", 404); | ||
} | ||
$bulletin->delete(); | ||
return APIReturn::success(); | ||
} | ||
catch (\Exception $e){ | ||
} catch (\Exception $e) { | ||
return APIReturn::error("database_error", "数据库读写错误", 500); | ||
} | ||
} | ||
|
@@ -92,28 +91,28 @@ public function delete(Request $request) | |
* @return \Illuminate\Http\JsonResponse | ||
* @author Eridanus Sora <[email protected]> | ||
*/ | ||
public function edit(Request $request){ | ||
public function edit(Request $request) | ||
{ | ||
$validator = \Validator::make($request->only(['bulletinId', 'title', 'content']), [ | ||
'bulletinId' => 'required', | ||
'title' => 'required', | ||
'content' => 'required' | ||
'bulletinId' => 'required', | ||
'title' => 'required', | ||
'content' => 'required' | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return APIReturn::error('invalid_parameters', $validator->errors()->all(), 400); | ||
} | ||
|
||
try{ | ||
try { | ||
$bulletin = Bulletin::find($request->input('bulletinId')); | ||
if (!$bulletin){ | ||
if (!$bulletin) { | ||
return APIReturn::error("bulletin_not_found", "该公告不存在", 404); | ||
} | ||
$bulletin->title = $request->input('title'); | ||
$bulletin->content = $request->input('content'); | ||
$bulletin->save(); | ||
return APIReturn::success($bulletin); | ||
} | ||
catch (\Exception $e){ | ||
} catch (\Exception $e) { | ||
return APIReturn::error("database_error", "数据库读写错误", 500); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,58 @@ public function resetScore(Request $request) | |
} | ||
} | ||
|
||
/** | ||
* 查询已经完成题目的队伍 | ||
* @param Request $request | ||
* @return \Illuminate\Http\JsonResponse | ||
* @author Eridanus Sora <[email protected]> | ||
*/ | ||
public function getSolvedTeams(Request $request){ | ||
$validator = Validator::make($request->only(['challengeId']), [ | ||
'challengeId' => 'required' | ||
], [ | ||
'challengeId.required' => __('缺少 题目ID 字段') | ||
]); | ||
|
||
|
||
if ($validator->fails()) { | ||
return APIReturn::error('invalid_parameters', $validator->errors()->all(), 400); | ||
} | ||
|
||
try{ | ||
$team = JWTAuth::parseToken()->toUser(); | ||
$team->load(['logs' => function ($query) { | ||
$query->where('status', 'correct'); | ||
}]); | ||
$challenge = Challenge::where('challenge_id',$request->input('challengeId'))->with("level")->first(); | ||
if ($challenge->count() == 0){ | ||
return APIReturn::error("challenge_not_found", __("问题不存在"), 404); | ||
} | ||
$logs = Log::where([ | ||
["challenge_id", '=', $request->input("challengeId")], | ||
["status", "=", "correct"] | ||
])->with(['team'])->orderBy("created_at")->get(); | ||
$ruleValidator = new RuleValidator($team->team_id, $challenge->level->rules); | ||
if (!$ruleValidator->check($team->logs)){ | ||
// 题目未开放 | ||
return APIReturn::error("challenge_not_found", __("问题不存在"), 404); | ||
} | ||
$result = []; | ||
|
||
$logs->each(function($log) use(&$result){ | ||
array_push($result, [ | ||
'teamName' => $log->team->team_name, | ||
'solvedAt' => Carbon::parse($log->created_at)->toIso8601String() | ||
]); | ||
}); | ||
return APIReturn::success($result); | ||
} | ||
catch (\Exception $e){ | ||
dump($e); | ||
return APIReturn::error("database_error", "数据库读写错误", 500); | ||
} | ||
} | ||
|
||
/** | ||
* 获得 Flags 详情 | ||
* @param Request $request | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters