# -*- 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(sqrl_session, redir="sqrl: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 sqrl_session %} {% sqrl_login_dropin sqrl_session REDIR %} REDIR is the registered name of the page to move to once the login is completed. It can be blank to not define a redirection. 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 {'sqrl_session':sqrl_session, '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