Exemple #1
0
 def get(self, request, *args, **kwargs):
     challenge = os.urandom(32)
     request.session['webauthn_attest'] = webauthn_encode(challenge)
     data = webauthn.WebAuthnMakeCredentialOptions(
         challenge=challenge,
         rp_id=settings.WEBAUTHN_RP_ID,
         rp_name=settings.SITE_NAME,
         user_id=request.profile.webauthn_id,
         username=request.user.username,
         display_name=request.user.username,
         user_verification='discouraged',
         icon_url=gravatar(request.user.email),
         attestation='none',
     ).registration_dict
     data['excludeCredentials'] = [{
         'type': 'public-key',
         'id': {
             '_bytes': credential.cred_id
         },
     } for credential in request.profile.webauthn_credentials.all()]
     return JsonResponse(data, encoder=WebAuthnJSONEncoder)
Exemple #2
0
    def get(self, request, *args, **kwargs):
        self.request = request
        self.kwargs = kwargs
        self.term = kwargs.get('term', request.GET.get('term', ''))
        self.gravatar_size = request.GET.get('gravatar_size', 128)
        self.gravatar_default = request.GET.get('gravatar_default', None)

        self.object_list = self.get_queryset().values_list('pk', 'user__username', 'user__email', 'display_rank')

        context = self.get_context_data()

        return JsonResponse({
            'results': [
                {
                    'text': username,
                    'id': username,
                    'gravatar_url': gravatar(email, self.gravatar_size, self.gravatar_default),
                    'display_rank': display_rank,
                } for pk, username, email, display_rank in context['object_list']],
            'more': context['page_obj'].has_next(),
        })
Exemple #3
0
    def get(self, request, *args, **kwargs):
        self.request = request
        self.kwargs = kwargs
        self.term = kwargs.get('term', request.GET.get('term', ''))
        self.gravatar_size = request.GET.get('gravatar_size', 128)
        self.gravatar_default = request.GET.get('gravatar_default', None)

        self.object_list = self.get_queryset().values_list('pk', 'user__username', 'user__email', 'display_rank')

        context = self.get_context_data()

        return JsonResponse({
            'results': [
                {
                    'text': username,
                    'id': username,
                    'gravatar_url': gravatar(email, self.gravatar_size, self.gravatar_default),
                    'display_rank': display_rank,
                } for pk, username, email, display_rank in context['object_list']],
            'more': context['page_obj'].has_next(),
        })
Exemple #4
0
def on_new_comment(comment_id):
    webhook = settings.DISCORD_WEBHOOK
    site_url = settings.SITE_FULL_URL
    if webhook is None or site_url is None:
        return

    comment = Comment.objects.get(pk=comment_id)
    url = site_url + comment.get_absolute_url()

    webhook = DiscordWebhook(url=webhook)
    embed = DiscordEmbed(
        title=f"New comment {url}",
        description=comment.body,
        color="03b2f8",
    )
    embed.set_author(
        name=comment.author.user.username,
        url=site_url + "/user/" + comment.author.user.username,
        icon_url=gravatar(comment.author),
    )
    webhook.add_embed(embed)
    webhook.execute()