修复提交flag的code错误问题
This commit is contained in:
@@ -19,6 +19,7 @@ func hasAlreadySolved(uid int, cid int) (exists bool) {
|
||||
}
|
||||
return exists
|
||||
}
|
||||
|
||||
// isChallengeExisted 检查数据库中是否存在某个题目。
|
||||
func isChallengeExisted(id int) (exists bool) {
|
||||
Link()
|
||||
@@ -81,6 +82,7 @@ func addUserScore(username string, cid int) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// updateUserScores 操作数据库更新解出用户的分数。
|
||||
func updateUserScores(reducedScore, cid int) error {
|
||||
|
||||
@@ -158,19 +160,19 @@ func SubmitFlag(c *gin.Context) {
|
||||
}
|
||||
// 是否已经解出该题
|
||||
if hasAlreadySolved(user.ID, request.Cid) {
|
||||
c.JSON(400, gin.H{"code": 400, "msg": "Already solved!"})
|
||||
c.JSON(200, gin.H{"code": 400, "msg": "Already solved!"})
|
||||
return
|
||||
}
|
||||
// 获取flag
|
||||
flag, err := getFlag(request.Cid)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.JSON(400, gin.H{"code": 400, "msg": "Get flag failure!"})
|
||||
c.JSON(200, gin.H{"code": 400, "msg": "Get flag failure!"})
|
||||
return
|
||||
}
|
||||
// 检查flag是否正确
|
||||
if flag != request.Flag {
|
||||
c.JSON(400, gin.H{"code": 400, "msg": "Wrong flag!"})
|
||||
c.JSON(200, gin.H{"code": 400, "msg": "Wrong flag!"})
|
||||
return
|
||||
} else {
|
||||
// Solve记录
|
||||
@@ -181,7 +183,7 @@ func SubmitFlag(c *gin.Context) {
|
||||
}
|
||||
err = addSolve(solve)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"code": 400, "msg": "Record solve failure!"})
|
||||
c.JSON(200, gin.H{"code": 400, "msg": "Record solve failure!"})
|
||||
return
|
||||
}
|
||||
//加分
|
||||
|
Reference in New Issue
Block a user