def get(self, request): try: User.test_authenticated(Context.from_request(request)) except LoginRequired: return redirect('hub') return TemplateResponse(request, 'profile.html', { 'profile_required': User.profile_required, })
def post(self, request): context = Context.from_request(request) try: User.test_authenticated(context) except LoginRequired: return redirect('hub') for pk in request.POST.getlist('terms'): Terms.get(context, pk=pk).agree(request.user.pk) return redirect('hub')
def post(self, request): try: kwargs = json.loads(request.body) kwargs = {k: kwargs[k] for k in kwargs if k in User.update_fields} user = User.get(Context.from_request(request), request.user.pk) user.update(**kwargs) return JsonResponse({}) except WrongFormat as e: return JsonResponse({'error': e.json}, status=400)
def post(self, request): body = json.loads(request.body) method = body['method'] args = body.get('args', {}) try: method = getattr(self, f'do_{method}') value = method(Context.from_request(request), **args) return JsonResponse({'value': value}) except Error as e: return JsonResponse({'error': e.json}, status=400)
def get(self, request): try: return TemplateResponse( request, self.template, { **site.each_context(request), **self.get_extra_context(Context.from_request(request)), 'title': self.title, }) except Error as e: messages.error(request, e.message) return redirect('hub')
def post(self, request): try: matches = Submission.submit(Context.from_request(request), request.user.pk, request.POST['challenge'], request.POST['flag'].strip()) if matches: messages.success(request, '答案正确') else: messages.error(request, '答案错误') except Error as e: messages.info(request, e.message) return redirect('hub')
def post(self, request): if not self.check(): return redirect('hub') eligible = request.POST['eligible'] if eligible == 'yes': UstcEligible.objects.create(user=request.user, eligible=True) user = User.get( Context.from_request(request).copy(elevated=True), request.user.pk) user.update(group='ustc') elif eligible == 'no': UstcEligible.objects.create(user=request.user, eligible=False) return redirect('hub')
def frontend(request): return { 'page': Page.get(), 'user_': (User.get(Context.from_request(request), request.user.pk) if request.user.is_authenticated else None), 'groups': User.groups, 'debug': settings.DEBUG, 'no_board_groups': User.no_board_groups, }
def get(self, request): context = Context.from_request(request) try: return TemplateResponse( request, 'first.html', { 'filters': { 'group': request.GET.get('group', None), }, 'users': {u.pk: u.json for u in User.get_all(context)}, 'challenges': [c.json for c in Challenge.get_enabled(context)], }) except Error as e: messages.error(request, e.message) return redirect('hub')
def get(self, request): context = Context.from_request(request) try: return TemplateResponse( request, 'board.html', { 'filters': { 'category': request.GET.get('category', None), 'group': request.GET.get('group', None), }, 'users': {u.pk: u.display_name for u in User.get_all(context)}, }) except Error as e: messages.error(request, e.message) return redirect('hub')
def get(self, request): if request.user.is_authenticated: if Account.objects.filter(provider='ustc', user=request.user).exists(): try: request.user.ustceligible except UstcEligible.DoesNotExist: return redirect('ustcprofile') context = Context.from_request(request) try: challenges = Challenge.get_enabled(context) challenges = {'value': [obj.json for obj in challenges]} except ProfileRequired as e: messages.info(request, e.message) return redirect('profile') except TermsRequired as e: messages.info(request, e.message) return redirect('terms') except Error as e: challenges = {'error': e.json} try: announcement = Announcement.get_latest(context).json except NotFound: announcement = None if request.user.is_authenticated: user = User.get(context, request.user.pk) if user.group == 'other': ranking = Submission.get_user_ranking(context, request.user.pk) else: ranking = Submission.get_user_ranking(context, request.user.pk, group=user.group) else: ranking = {} return TemplateResponse( request, 'hub.html', { 'announcement': announcement, 'challenges': challenges, 'progress': Submission.get_user_progress( context, request.user.pk), 'ranking': ranking, 'clear_count': Submission.get_clear_count(context), })
def get(self, request): context = Context.from_request(request) return TemplateResponse(request, 'announcements.html', { 'announcements': [i.json for i in Announcement.get_all(context)], })
def get(self, request): terms = Terms.get_enabled(Context.from_request(request)) return TemplateResponse(request, 'terms.html', {'terms': terms})