예제 #1
0
 def create(self, request, *args, **kwargs):
     candidate = User.objects.get(id=request.data['candidate'])
     challenge = Challenge(creator=request.user, candidate=candidate)
     challenge.status = 'SENT'
     challenge.save()
     easy_questions = random.sample(
         list(Question.objects.filter(difficulty='1')), 3)
     intermediate_questions = random.sample(
         list(Question.objects.filter(difficulty='2')), 2)
     hard_questions = random.sample(
         list(Question.objects.filter(difficulty='3')), 1)
     challenge.questions.set(easy_questions + intermediate_questions +
                             hard_questions)
     email = EmailMultiAlternatives()
     email.subject = 'Propulsion Academy - You have a new Challenge!'
     email.to = [candidate.email]
     if candidate.is_active:
         email.attach_alternative(
             generate_challenge_created_content(candidate), "text/html")
     else:
         email.attach_alternative(
             generate_challenge_created_when_inactive_content(candidate),
             "text/html")
     email.send(fail_silently=False)
     return Response(status=200)
예제 #2
0
def add_challenge( request ):
    result = ""
    if( request.method == 'POST' ):
        form = ChallengeForm( request.POST )
        if( form.is_valid() ):
            challenge = Challenge()
            challenge.name = form.cleaned_data['name']
            challenge.put( )
            return HttpResponseRedirect(reverse('challenge.views.show_challenge', kwargs={'id':str(challenge.key().id() ) }) )
    else:
        # default to GET
        form = ChallengeForm( )
    
    return render_to_response('challenge/new_challenge.html', {'form': form } )

    return HttpResponse( result )
예제 #3
0
파일: views.py 프로젝트: pmontu/Prism
def add(request):
	challenge_request = json.loads(request.body)

	challenge = Challenge(
		title = challenge_request['title'],
		frequency = challenge_request['frequency'],
		startdate = challenge_request['startdate'][0:10],
		numberofdays = challenge_request['numberofdays']
		)

	challenge.save()

	for challenger in challenge_request['friends']:
		challenge.challengers.add(User.objects.get(pk = challenger['pk']))
	
	return HttpResponse()
예제 #4
0
파일: views.py 프로젝트: nkait/coderatops
 def create(self, request):
     serializer = ChallengeSpecSerializer(data=request.DATA)
     if serializer.is_valid():
         try:
             serializer.object.challenger = request.user
             challenger = FBUser.objects.filter(user=request.user).first()
             fbuser = FBUser.objects.filter(fbid=serializer.object.challenged)
             challenged = fbuser.first()
             message = serializer.object.message
             puzzle_instance = PuzzleInstance.create(challenger, challenged, {})
             challenge = Challenge(challenger=challenger, challenged=challenged,
                     message=message, puzzle_instance=puzzle_instance)
             challenge.save()
             result_serializer = ChallengeSerializer(challenge)
             self.publish_list(request.user)
         except Exception as ex:
             traceback.print_exc()
         return Response(result_serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #5
0
def show_challenge( request, id ):
    challenge = Challenge.get_by_id( int(id ) )
    reports = challenge.report_set.order("-reported_date")
    top_reporters = challenge.top_reporters( )[0:3]
    
    if( request.method == 'POST' ):
        return _new_activity_report( request, challenge, reports, top_reporters )
    else:
        form = ActivityReportForm(
            initial = { 'challenge_id': id } )
        return object_list(request, reports, paginate_by=15, extra_context=locals(), template_name='challenge/activity_report.html' )
예제 #6
0
def spark_line( request, challenge_id, reporter_id ):
    challenge = Challenge.get_by_id( int( challenge_id ) )
    reporter = Reporter.get_by_id( int( reporter_id ) )
    return HttpResponseRedirect(reporter.spark_line_url( challenge ) )
예제 #7
0
def list_reports( request, challenge_id, reporter_id ):
    challenge = Challenge.get_by_id( int(challenge_id ) )
    reporter = Reporter.get_by_id( int(reporter_id) )
    reports = challenge.report_set.filter( 'reporter = ', reporter ).order("-reported_date" )
    
    return object_list( request, reports, paginate_by=10, extra_context=locals() )
예제 #8
0
def list_challenges(request):
    return object_list(request, Challenge.all(), paginate_by=10)
예제 #9
0
 def get_queryset(self):
     if self.request.method not in permissions.SAFE_METHODS:
         return self.queryset
     return Challenge.get_unlocked_annotated_queryset(self.request.user)
예제 #10
0
 def setUp(self):
     category = Category(name='test',
                         display_order=0,
                         contained_type='test',
                         description='')
     category.save()
     challenge1 = Challenge(name='test1',
                            category=category,
                            description='a',
                            challenge_type='basic',
                            challenge_metadata={},
                            flag_type='plaintext',
                            flag_metadata={'flag': 'ractf{a}'},
                            author='dave',
                            score=1000)
     challenge2 = Challenge(name='test2',
                            category=category,
                            description='a',
                            challenge_type='basic',
                            challenge_metadata={},
                            flag_type='plaintext',
                            flag_metadata={'flag': 'ractf{a}'},
                            author='dave',
                            score=1000,
                            auto_unlock=True)
     challenge3 = Challenge(name='test3',
                            category=category,
                            description='a',
                            challenge_type='basic',
                            challenge_metadata={},
                            flag_type='plaintext',
                            flag_metadata={'flag': 'ractf{a}'},
                            author='dave',
                            score=1000,
                            auto_unlock=False)
     challenge1.save()
     challenge2.save()
     challenge3.save()
     challenge2.unlocks.add(challenge1)
     challenge2.save()
     hint1 = Hint(name='hint1', challenge=challenge1, text='a', penalty=100)
     hint2 = Hint(name='hint2', challenge=challenge1, text='a', penalty=100)
     hint3 = Hint(name='hint3', challenge=challenge2, text='a', penalty=100)
     hint1.save()
     hint2.save()
     hint3.save()
     user = get_user_model()(username='******',
                             email='*****@*****.**')
     user.save()
     team = Team(name='team', password='******', owner=user)
     team.save()
     user.team = team
     user.save()
     user2 = get_user_model()(username='******',
                              email='*****@*****.**')
     user2.team = team
     user2.save()
     user3 = get_user_model()(username='******',
                              email='*****@*****.**')
     user3.save()
     team2 = Team(name='team2', password='******', owner=user3)
     team2.save()
     user3.team = team2
     user3.save()
     self.user = user
     self.user2 = user2
     self.user3 = user3
     self.team = team
     self.team2 = team2
     self.category = category
     self.challenge1 = challenge1
     self.challenge2 = challenge2
     self.challenge3 = challenge3
     self.hint1 = hint1
     self.hint2 = hint2
     self.hint3 = hint3
    def handle(self, *args, **options):
        print('Creating 10 categories...')
        for i in range(10):
            category = Category(name='category-' + str(i), display_order=i, contained_type='test',
                                description='Category ' + str(i))
            category.save()

        print('Creating 100 challenges for each category...')
        for i in range(10):
            category = Category.objects.get(name='category-' + str(i))
            for j in range(50):
                challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category,
                                      description='An example challenge ' + str(j),
                                      flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True, score=j,
                                      challenge_metadata={})
                challenge.save()
            for j in range(50, 100, 2):
                challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category,
                                      description='An example challenge ' + str(j),
                                      flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True,
                                      score=j, challenge_metadata={})
                challenge2 = Challenge(name='cat-' + str(i) + '-chal-' + str(j + 1), category=category,
                                       description='An example challenge ' + str(j + 1),
                                       flag_metadata={'flag': f'ractf{{{j + 1}}}'}, author='dave', auto_unlock=False,
                                       score=j, challenge_metadata={})
                challenge2.save()
                challenge.save()
                challenge.unlocks.add(challenge2)

        print('Creating 20000 users with 10000 teams with 100 solves per team...')
        for i in range(10000):
            user = get_user_model()(username='******' + str(i), email='user-' + str(i) + '@example.org')
            user.save()
            team = Team(name='team-' + str(i), password='******', owner=user)
            team.save()
            user2 = get_user_model()(username='******' + str(i) + '-second', email='user-' + str(i) + '*****@*****.**',
                                     team=team)
            user2.save()
            for j in range(50):
                challenge = Category.objects.get(name='category-' + str(j % 5))\
                    .category_challenges.get(name='cat-' + str(j % 5) + '-chal-' + str(j))
                points = random.randint(0, 1000)
                score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True)
                score.save()
                solve = Solve(team=team, solved_by=user, challenge=challenge, first_blood=challenge.first_blood is None,
                              flag='ractf{}', score=score, correct=True)
                solve.save()
                user.points += points
                team.points += points
                user.leaderboard_points += points
                team.leaderboard_points += points
            for j in range(50):
                challenge = Category.objects.get(name='category-' + str(j % 5 + 5))\
                    .category_challenges.get(name='cat-' + str(j % 5 + 5) + '-chal-' + str(j))
                points = random.randint(0, 1000)
                score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True)
                score.save()
                solve = Solve(team=team, solved_by=user2, challenge=challenge,
                              first_blood=challenge.first_blood is None, flag='ractf{}', score=score, correct=True)
                solve.save()
                user2.points += points
                team.points += points
                user.leaderboard_points += points
                team.leaderboard_points += points