django-sqrl-2/sqrl/templatetags/sqrl.py

46 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
from django import template
from django.urls import reverse
from django.template.defaultfilters import urlencode
from ..sqrl import SQRLInitialization
register = template.Library()
print(register)
@register.simple_tag(takes_context=True)
def sqrl(context):
return SQRLInitialization(context['request'])
@register.inclusion_tag('sqrl/sqrl-dropin.html')
def sqrl_login_dropin(session_sqrl, method="login"):
"""
Creates a drop-in SQRL element in your template pages.
Add it to your login template to make it SQRL-aware.
Usage:
{% load sqrl %}
{% sqrl as session_sqrl %}
{% sqrl_login_dropin session_sqrl [method=METHOD] %}
METHOD is an optional argument that changes the way the form
behaves. Possible arguments are:
- login: The default method. No special redirections occur
- manage: Will redirect the user to sqrl/manage
Notes:
The drop-in is defaulted to a max-width of 300px. Set the width
property of the parent if you want or need it smaller. You will
likely want to change the font-size as well in this case.
"""
return {'session_sqrl':session_sqrl, 'method': method}
@register.simple_tag
def sqrl_status_url_script_tag(sqrl):
url = reverse('sqrl:status', kwargs={'transaction': sqrl.nut.transaction_nonce})
return url