diff --git a/ctfpad/forms.py b/ctfpad/forms.py index 165bbdc..881c505 100644 --- a/ctfpad/forms.py +++ b/ctfpad/forms.py @@ -126,14 +126,21 @@ class Meta: "tags", ] - is_update = True - def cleaned_tags(self): data = [x.lower() for x in self.cleaned_data['tags'].split()] return data + def clean_flag(self): + flag = self.cleaned_data.get("flag") + prefix = self.instance.ctf.flag_prefix + + if flag and prefix and not flag.startswith(prefix): + self.add_error("flag", f"Unexpected format for flag (missing '{prefix}')") + + return flag + -class ChallengeSetFlagForm(forms.ModelForm): +class ChallengeSetFlagForm(ChallengeUpdateForm): class Meta: model = Challenge fields = [ diff --git a/ctfpad/templates/ctfpad/challenges/create.html b/ctfpad/templates/ctfpad/challenges/create.html index 9cf0949..d24d4d7 100644 --- a/ctfpad/templates/ctfpad/challenges/create.html +++ b/ctfpad/templates/ctfpad/challenges/create.html @@ -80,7 +80,7 @@