2019-09-02 02:03:23 -05:00
|
|
|
# -*- 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()
|
|
|
|
|
|
|
|
|
2019-09-02 04:56:45 -05:00
|
|
|
@register.simple_tag(takes_context=True)
|
2019-09-02 02:03:23 -05:00
|
|
|
def sqrl(context):
|
|
|
|
return SQRLInitialization(context['request'])
|
|
|
|
|
|
|
|
|
|
|
|
@register.inclusion_tag('sqrl/sqrl-dropin.html')
|
2019-09-02 09:42:24 -05:00
|
|
|
def sqrl_login_dropin(session_sqrl, redir):
|
2019-09-02 02:03:23 -05:00
|
|
|
"""
|
|
|
|
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 %}
|
2019-09-02 09:42:24 -05:00
|
|
|
{% sqrl_login_dropin session_sqrl REDIR %}
|
2019-09-02 02:03:23 -05:00
|
|
|
|
2019-09-02 09:42:24 -05:00
|
|
|
REDIR is the registered name of the page to move to once the login
|
|
|
|
is completed.
|
2019-09-02 02:03:23 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2019-09-02 09:42:24 -05:00
|
|
|
return {'session_sqrl':session_sqrl, 'redir': reverse(redir)}
|
2019-09-02 02:03:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
@register.simple_tag
|
|
|
|
def sqrl_status_url_script_tag(sqrl):
|
|
|
|
url = reverse('sqrl:status', kwargs={'transaction': sqrl.nut.transaction_nonce})
|
2019-09-02 04:56:45 -05:00
|
|
|
return url
|