def post(self, request, cid):
    if not request.user.is_authenticated:
      messages.error(request, "请先登录。")
    else:
      invitation_code = request.POST.get('code', '')
      try:
        invitation = ContestInvitation.objects.get(code=invitation_code)
        add_participant_with_invitation(cid, invitation.pk, request.user)
        messages.success(request, "你已成功加入。")
      except ContestInvitation.DoesNotExist:
        messages.error(request, "邀请码有误。")
    return HttpResponseRedirect(reverse('contest:dashboard', kwargs={'cid': cid}))