Fix templating errors, js errors

This commit is contained in:
= 2019-09-14 04:38:14 -05:00
parent 92c8eef214
commit 8d42d46d74
Signed by: kiichan
GPG Key ID: 619DFD67F0976616
8 changed files with 93 additions and 52 deletions

View File

@ -1,3 +1,14 @@
Sat, 14 Sep 2019 04:38:14 -0500
Keaton <kii-chan@tutanota.com>
Fix templating errors, js errors
- Javascript `urlparams` didn't handle being null
- Templates needed updating/cleaning
- Moved SQRL dropin CSS to its own file
- New example picture to show off changes to CSS/templates
--------------------
Sat, 14 Sep 2019 03:13:30 -0500 Sat, 14 Sep 2019 03:13:30 -0500
Keaton <kii-chan@tutanota.com> Keaton <kii-chan@tutanota.com>
Add `manage.py` for `tests` Add `manage.py` for `tests`

View File

@ -34,11 +34,12 @@ Once installed there are a few required changes in Django settings:
``` ```
INSTALLED_APPS = [ INSTALLED_APPS = [
..., ...,
'sqrl', 'sqrl',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
...
] ]
``` ```
@ -46,9 +47,10 @@ INSTALLED_APPS = [
``` ```
MIDDLEWARE_CLASSES = [ MIDDLEWARE_CLASSES = [
... ...
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
...
] ]
``` ```
@ -57,7 +59,7 @@ MIDDLEWARE_CLASSES = [
``` ```
AUTHENTICATION_BACKENDS = [ AUTHENTICATION_BACKENDS = [
'sqrl.backends.SQRLModelBackend', 'sqrl.backends.SQRLModelBackend',
] ]
``` ```
@ -69,10 +71,10 @@ overwrites some of them.
``` ```
INSTALLED_APPS = [ INSTALLED_APPS = [
..., ...,
'sqrl', 'sqrl',
'django.contrib.admin', 'django.contrib.admin',
... ...
] ]
``` ```
@ -85,7 +87,7 @@ to explicitly extend from `django.contrib.admin` `base.html` template:
import os import os
import django import django
TEMPLATE_DIRS = [ TEMPLATE_DIRS = [
os.path.dirname(django.__file__), os.path.dirname(django.__file__),
] ]
``` ```
@ -97,9 +99,9 @@ All of SQRL functionality is enabled by adding its URLs to the root URL config:
from django.urls import path, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
... ...
path('sqrl/', include('sqrl.urls', namespace="sqrl")), path('sqrl/', include('sqrl.urls', namespace="sqrl")),
... ...
] ]
``` ```
@ -114,13 +116,42 @@ page with three simple template tags:
``` ```
{% load sqrl %} {% load sqrl %}
{% sqrl as sqrl_session %} {% sqrl as sqrl_session %}
{% sqrl_login_dropin sqrl_session [[a named redirect]] %} {% sqrl_login_dropin sqrl_session "named:redirect" %}
``` ```
The [[named redirect]] is the page that should be redirected to after logging The `"named:redirect"` is the page that should be redirected to after logging
in. Any name that can be resolved by django's `reverse` function will work (i.e. in. Any name that can be resolved by django's `reverse` function will work. For
`path("scheme/", view, name="example")` in the app `app` with namespace "app" example, here are the necessary lines needed to resolve `"app:main"`:
could be selected as `app:example`).
* Main project's `urls.py`:
```
urlpatterns = [
...
path("", include('app.urls', namespace="app"))
...
]
```
* Your `app`'s `urls.py`:
```
urlpatterns = [
...
path("", main_view, name="main")
...
]
```
* Your `main_view`'s template:
```
...
{% load sqrl %}
{% sqrl as sqrl_session %}
{% sqrl_login_dropin sqrl_session "app:main" %}
...
```
These three tags will add a simple element to your login page: These three tags will add a simple element to your login page:
@ -133,7 +164,7 @@ following essential tags:
{% load sqrl %} {% load sqrl %}
{% sqrl as sqrl_session %} {% sqrl as sqrl_session %}
<a href="{{ sqrl_session.sqrl_url }}"> <a href="{{ sqrl_session.sqrl_url }}">
<div id="sqrl-qr" data-sqrl="{{ sqrl_session.sqrl_url }}"></div> <div id="sqrl-qr" data-sqrl="{{ sqrl_session.sqrl_url }}"></div>
</a> </a>
<script>SQRL_NEXT="{{ your desired redirect }}"; SQRL_CHECK_URL="{% sqrl_status_url_script_tag sqrl_session %}"</script> <script>SQRL_NEXT="{{ your desired redirect }}"; SQRL_CHECK_URL="{% sqrl_status_url_script_tag sqrl_session %}"</script>
<script type="application/javascript" src="{% static 'sqrl/sqrl.js' %}"></script> <script type="application/javascript" src="{% static 'sqrl/sqrl.js' %}"></script>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 322 KiB

View File

@ -0,0 +1,19 @@
.sqrl-parent {
padding: 15px;
background-color: #fff;
text-align: center;
max-width: 300px;
border-radius: 5%;
}
#sqrl-qr img {
margin: auto;
width: 100%;
padding-top: 3px;
}
.sqrl-wrap a {
font-size: 50%;
}
.sqrl-form input {
margin: auto;
}

View File

@ -2,8 +2,10 @@
var get_next_url = function() { var get_next_url = function() {
// A Next defined in the URL has priority // A Next defined in the URL has priority
var urlparam = document.URL.match(/next=([^&#]+)/) var urlparam = document.URL.match(/next=([^&#]+)/)
if (urlparam.length == 2) { if (urlparam) {
return urlparam[1] if (urlparam.length == 2) {
return urlparam[1]
}
} }
// Next highest priority is a defined SQRL_NEXT // Next highest priority is a defined SQRL_NEXT
if (typeof SQRL_NEXT !== "undefined") { if (typeof SQRL_NEXT !== "undefined") {

View File

@ -1,6 +1,5 @@
{% extends "sqrl/sqrl_base.html" %} {% extends "sqrl/sqrl_base.html" %}
{% load sqrl %} {% load sqrl %}
{% load static %}
{% block title %}Log in via SQRL{% endblock %} {% block title %}Log in via SQRL{% endblock %}
@ -12,7 +11,7 @@
</p> </p>
{% sqrl as sqrl_session %} {% sqrl as sqrl_session %}
{% sqrl_login_dropin sqrl_session "sqrl:login" %} {% sqrl_login_dropin sqrl_session %}
{% endblock %} {% endblock %}
{% comment %} {% comment %}

View File

@ -1,6 +1,5 @@
{% extends "sqrl/sqrl_base.html" %} {% extends "sqrl/sqrl_base.html" %}
{% load sqrl %} {% load sqrl %}
{% load static %}
{% block title %}Manage SQRL Identity{% endblock %} {% block title %}Manage SQRL Identity{% endblock %}
@ -33,11 +32,7 @@
{% endif %} {% endif %}
{% sqrl as sqrl_session %} {% sqrl as sqrl_session %}
{% sqrl_login_dropin sqrl_session method="manage" %} {% sqrl_login_dropin sqrl_session %}
{% endblock %}
{% block scripts %}
<script src="{% static 'sqrl/sqrl.js' %}"></script>
{% endblock %} {% endblock %}

View File

@ -1,24 +1,8 @@
{% load static %} {% load static %}
{% load sqrl %} {% load sqrl %}
<style> <link type="text/css" rel="stylesheet" href="{% static 'sqrl/dropin.css' %}"/>
.sqrl-wrap { <div class="sqrl-parent">
padding: 15px; <form class="sqrl-form" method="get" action="{{ sqrl_session.sqrl_url }}">
background-color: #fff;
text-align: center;
max-width: 300px;
border-radius: 5%;
}
#sqrl-qr img {
margin: auto;
width: 100%;
padding-top: 3px;
}
.sqrl-wrap a {
font-size: 50%;
}
</style>
<div>
<form method="get" action="{{ sqrl_session.sqrl_url }}">
<div class="sqrl-wrap"> <div class="sqrl-wrap">
SQRL Login SQRL Login
<a href="{{ sqrl_session.sqrl_url }}"> <a href="{{ sqrl_session.sqrl_url }}">