Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Maximum Attempt Limit to Submit Flag #370

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Aryan51203
Copy link

No description provided.

@Aryan51203
Copy link
Author

PR for issue #371

api/submit.go Outdated
@@ -136,6 +146,40 @@ func submitFlagHandler(c *gin.Context) {
return
}

tryStatus, err := database.GetUserPreviousTriesStatus(user.ID, challenge.ID, challenge.FailSolveLimit)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@@ -122,6 +124,7 @@ type ChallengePreviewResp struct {
Tags []string `json:"tags" example:"['pwn','misc']"`
Assets []string `json:"assets" example:"['image1.png', 'zippy.zip']"`
AdditionalLinks []string `json:"additionalLinks" example:"['http://link1.abc:8080','http://link2.abc:8081']"`
PreReqs []string `json:"preReqs" example:"['web-php','simple']"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add failed solve limit

@@ -172,6 +216,7 @@ func submitFlagHandler(c *gin.Context) {
CreatedAt: time.Time{},
UserID: user.ID,
ChallengeID: challenge.ID,
Solved: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't store it for false status. I think there is no need for solved feild

@@ -150,6 +152,10 @@ func (config *ChallengeMetadata) ValidateRequiredFields() (error, bool) {
return fmt.Errorf("Name and Flag required for the challenge"), false
}

if config.FailSolveLimit <= 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if failSolve limit not declared or zero. Make it either negative or infinite


// Query the database to get the user's solved challenges
var userChallenges []UserChallenges
err := Db.Where("user_id = ? AND solved = ?", userID, true).Find(&userChallenges).Error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixx

}

// Create a map to quickly check if a challenge is solved
solvedChallenges := make(map[string]bool)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too

@@ -173,7 +173,7 @@ func CheckPreviousSubmissions(userId uint, challId uint) (bool, error) {
DBMux.Lock()
defer DBMux.Unlock()

tx := Db.Where("user_id = ? AND challenge_id = ?", userId, challId).Find(&userChallenges).Count(&count)
tx := Db.Where("user_id = ? AND challenge_id = ? AND solved = ?", userId, challId, true).Find(&userChallenges).Count(&count)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants