app-MAIL-temp/templates/dashboard/fido_setup.html

76 lines
2.6 KiB
HTML
Raw Normal View History

{% extends "default.html" %}
2020-05-05 10:32:49 +02:00
{% set active_page = "setting" %}
{% block title %}Security Key Setup{% endblock %}
2020-05-05 10:32:49 +02:00
{% block head %}
2020-05-05 10:32:49 +02:00
<script src="{{ url_for('static', filename='node_modules/qrious/dist/qrious.min.js') }}"></script>
<script src="{{ url_for('static', filename='assets/js/vendors/base64.js') }}"></script>
<script src="/static/assets/js/vendors/webauthn.js?v={{ VERSION }}"></script>
2020-05-05 10:32:49 +02:00
{% endblock %}
{% block default_content %}
2020-05-11 23:22:06 +02:00
<div class="card">
<div class="card-body">
<h1 class="h2 text-center">Register Your Security Key</h1>
<p class="text-center">
Follow your browser's steps to register your security key with SimpleLogin
</p>
2020-05-11 23:22:06 +02:00
<form id="formRegisterKey" method="post">
{{ fido_token_form.csrf_token }}
{{ fido_token_form.sk_assertion(class="form-control", placeholder="") }}
{{ fido_token_form.key_name(id="key-name", class="form-control", placeholder="Name of your key (Required)") }}
2020-05-18 11:55:41 +02:00
{{ render_field_errors(fido_token_form.key_name) }}
2020-05-18 22:45:02 +02:00
<div class="text-center">
<span id="btnRegisterKey"
class="btn btn-lg btn-primary mt-2"
onclick="registerKey();">Register Key</span>
2020-05-18 22:45:02 +02:00
</div>
2020-05-11 23:22:06 +02:00
</form>
<script>
// disable submit when enter
$('form input').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});
2020-05-11 23:22:06 +02:00
async function registerKey() {
// make sure key name is not empty
if (!$("#key-name").val()) {
toastr.error("Key name cannot be empty.");
return
}
2020-05-11 23:22:06 +02:00
$("#btnRegisterKey").prop('disabled', true);
$("#btnRegisterKey").text('Waiting for Security Key...');
const pkCredentialCreateOptions = transformCredentialCreateOptions(
JSON.parse('{{credential_create_options|tojson|safe}}')
)
2020-05-18 07:05:37 +02:00
2020-05-11 23:22:06 +02:00
let credential
try {
credential = await navigator.credentials.create({
publicKey: pkCredentialCreateOptions
});
} catch (err) {
toastr.error("An error occurred when we trying to register your key.");
$("#btnRegisterKey").prop('disabled', false);
$("#btnRegisterKey").text('Register Key');
return console.error("Error when trying to create credential:", err);
}
const skAssertion = transformNewAssertionForServer(credential);
$('#sk_assertion').val(JSON.stringify(skAssertion));
$('#formRegisterKey').submit();
2020-05-05 10:32:49 +02:00
}
2020-05-11 23:22:06 +02:00
</script>
</div>
2020-05-05 10:32:49 +02:00
</div>
{% endblock %}