# -*- 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() @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, redir): """ 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 REDIR %} REDIR is the registered name of the page to move to once the login is completed. 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, 'redir': reverse(redir)} @register.simple_tag def sqrl_status_url_script_tag(sqrl): url = reverse('sqrl:status', kwargs={'transaction': sqrl.nut.transaction_nonce}) return url