@@ -33,14 +33,14 @@ def __init__(self, user, hint):
3333 self .hint = hint .id
3434 self .challenge = hint .challenge_id
3535
36- def get_modified_challenge_points (challenge ):
36+ def get_modified_challenge_points (challenge_id , challenge_value ):
3737 user = get_current_user ()
3838 hintids = DelayedHints .query .filter (
39- DelayedHints .challenge == challenge . id ,
39+ DelayedHints .challenge == challenge_id ,
4040 DelayedHints .user == user .id ,
4141 ).all ()
4242
43- score = challenge . value
43+ score = challenge_value
4444 if hintids :
4545 for hid in hintids :
4646 hint = Hints .query .filter (
@@ -50,10 +50,10 @@ def get_modified_challenge_points(challenge):
5050
5151 return score
5252
53- def apply_delayed_hints (challenge ):
53+ def apply_delayed_hints (challenge_id ):
5454 user = get_current_user ()
5555 hintids = DelayedHints .query .filter (
56- DelayedHints .challenge == challenge . id ,
56+ DelayedHints .challenge == challenge_id ,
5757 DelayedHints .user == user .id ,
5858 ).all ()
5959
@@ -103,6 +103,7 @@ def apply_delayed_hints(challenge):
103103)
104104
105105def load (app ):
106+
106107 app .db .create_all ()
107108
108109 #jinja globals
@@ -115,7 +116,6 @@ def load(app):
115116 @admins_only
116117 def hintpoint_config ():
117118 standard = get_config ("hintpointdelay" )
118-
119119 if standard :
120120 standard = "enabled"
121121 else :
@@ -141,9 +141,11 @@ def modify_award(res):
141141 user = get_current_user ()
142142
143143 Model = get_class_by_tablename (req ["type" ])
144- hint = Model .query .filter_by (id = req ["target" ]).first_or_404 ()
145-
144+ target = Model .query .filter_by (id = req ["target" ]).first_or_404 ()
145+
146+ # replace costly hint with non cost hint
146147 if (req ["type" ] == "hints" ):
148+ hint = target
147149 name = hint .name
148150 description = hint .description
149151 category = hint .category
@@ -175,117 +177,20 @@ def modify_award(res):
175177
176178 db .session .commit ()
177179 clear_standings ()
178-
179180
180181 run_after_route (app ,'api.unlocks_unlock_list' ,modify_award )
181182
182- @during_ctf_time_only
183- @require_verified_emails
184- @authed_only
185- def post (self ):
186- req = request .get_json ()
187- user = get_current_user ()
188-
189- target_type = req ["type" ]
190-
191- req ["user_id" ] = user .id
192- req ["team_id" ] = user .team_id
193-
194- Model = get_class_by_tablename (req ["type" ])
195- target = Model .query .filter_by (id = req ["target" ]).first_or_404 ()
196-
197- if target_type == "hints" :
198- # We should use the team's score if in teams mode
199- # user.account gives the appropriate account based on team mode
200- # Use get_score with admin to get the account's full score value
201- if target .cost > user .account .get_score (admin = True ):
202- return (
203- {
204- "success" : False ,
205- "errors" : {
206- "score" : "You do not have enough points to unlock this hint"
207- },
208- },
209- 400 ,
210- )
211-
212- schema = UnlockSchema ()
213- response = schema .load (req , session = db .session )
214-
215- if response .errors :
216- return {"success" : False , "errors" : response .errors }, 400
183+ def modify_challenge_correct (res ):
184+ response = res [0 ].get_json ()
185+ log ('registrations' ,format = "########################## {response}" ,
186+ response = response ['data' ]['status' ] )
187+ if (response ['success' ] and response ['data' ]['status' ] == 'correct' ):
188+ if not request .is_json :
189+ request_data = request .form
190+ else :
191+ request_data = request .get_json ()
217192
218- # Search for an existing unlock that matches the target and type
219- # And matches either the requesting user id or the requesting team id
220- existing = Unlocks .query .filter (
221- Unlocks .target == req ["target" ],
222- Unlocks .type == req ["type" ],
223- Unlocks .account_id == user .account_id ,
224- ).first ()
225- if existing :
226- return (
227- {
228- "success" : False ,
229- "errors" : {"target" : "You've already unlocked this target" },
230- },
231- 400 ,
232- )
193+ challenge_id = request_data .get ("challenge_id" )
194+ apply_delayed_hints (challenge_id )
233195
234- db .session .add (response .data )
235-
236- award_schema = AwardSchema ()
237- award = {
238- "user_id" : user .id ,
239- "team_id" : user .team_id ,
240- "name" : target .name ,
241- "description" : target .description ,
242- "value" : (- target .cost ),
243- "category" : target .category ,
244- }
245-
246- award = award_schema .load (award )
247- db .session .add (award .data )
248- db .session .commit ()
249- clear_standings ()
250-
251- response = schema .dump (response .data )
252-
253- return {"success" : True , "data" : response .data }
254-
255- elif target_type == "solutions" :
256- schema = UnlockSchema ()
257- response = schema .load (req , session = db .session )
258-
259- if response .errors :
260- return {"success" : False , "errors" : response .errors }, 400
261-
262- # Search for an existing unlock that matches the target and type
263- # And matches either the requesting user id or the requesting team id
264- existing = Unlocks .query .filter (
265- Unlocks .target == req ["target" ],
266- Unlocks .type == req ["type" ],
267- Unlocks .account_id == user .account_id ,
268- ).first ()
269- if existing :
270- return (
271- {
272- "success" : False ,
273- "errors" : {"target" : "You've already unlocked this target" },
274- },
275- 400 ,
276- )
277-
278- db .session .add (response .data )
279- db .session .commit ()
280-
281- response = schema .dump (response .data )
282-
283- return {"success" : True , "data" : response .data }
284- else :
285- return (
286- {
287- "success" : False ,
288- "errors" : {"type" : "Unknown target type" },
289- },
290- 400 ,
291- )
196+ run_after_route (app ,'api.challenges_challenge_attempt' ,modify_challenge_correct )
0 commit comments