app-MAIL-temp/templates/dashboard/fido_setup.html
Adrià Casajús 046748c443
Update pre-commit (#1138)
* Update pre-commit

* Upgrade djlint, remove flake8 and add pylint

* Reformat with new djlint version

* Run pre-commit on CI

* Use only python3.10 on CI

* Reformat files with pre-commit

* Run pre-commit against all files

* Reformat

* Added global excludes

* Added pre-commit to the contributing file

* Set python 3.9 as default

* Set language version to python3

Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
Co-authored-by: Carlos Quintana <carlos.quintana@proton.ch>
2022-07-04 16:01:04 +02:00

73 lines
2.6 KiB
HTML

{% extends "default.html" %}
{% set active_page = "setting" %}
{% block title %}Security Key Setup{% endblock %}
{% block head %}
<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>
{% endblock %}
{% block default_content %}
<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>
<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)") }}
{{ render_field_errors(fido_token_form.key_name) }}
<div class="text-center">
<span id="btnRegisterKey"
class="btn btn-lg btn-primary mt-2"
onclick="registerKey();">Register Key</span>
</div>
</form>
<script>
// disable submit when enter
$('form input').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});
async function registerKey() {
// make sure key name is not empty
if (!$("#key-name").val()) {
toastr.error("Key name cannot be empty.");
return
}
$("#btnRegisterKey").prop('disabled', true);
$("#btnRegisterKey").text('Waiting for Security Key...');
const pkCredentialCreateOptions = transformCredentialCreateOptions(
JSON.parse('{{credential_create_options|tojson|safe}}')
)
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();
}
</script>
</div>
</div>
{% endblock %}