Administrators can remove two factor authentication

This commit is contained in:
2022-04-19 17:14:05 +02:00
parent 630ebe2ddd
commit 78d70af510
5 changed files with 44 additions and 10 deletions

View File

@ -68,6 +68,25 @@
</div>
</div>
<!-- Two-Factor authentication -->
<input type="hidden" name="two_factor" value=""/>
{% if u.has_two_factor() %}
<fieldset class="form-group">
<legend class="mt-4">Two factor authentication</legend>
<strong>If you uncheck a factor, it will be DELETED</strong>
{% for f in u.two_factor.as_deref().unwrap_or_default() %}
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input two-fact-checkbox"
value="{{ f.id.0 }}"
checked=""/>
{{ f.name }} ({{ f.type_str() }})
</label>
</div>
{% endfor %}
</fieldset>
{% endif %}
<!-- Granted clients -->
<fieldset class="form-group">
<legend class="mt-4">Granted clients</legend>
@ -161,11 +180,15 @@
document.querySelector("input[name=granted_clients]").value = authorized_clients;
const factors_to_keep = [...document.querySelectorAll(".two-fact-checkbox")]
.filter(e => e.checked)
.map(e => e.value)
.join(";")
document.querySelector("input[name=two_factor]").value = factors_to_keep;
form.submit();
});
</script>
{% endblock content %}

View File

@ -23,7 +23,7 @@
</tr>
</thead>
<tbody>
{% for f in user.second_factors.as_deref().unwrap_or_default() %}
{% for f in user.two_factor.as_deref().unwrap_or_default() %}
<tr id="factor-{{ f.id.0 }}">
<td>{{ f.type_str() }}</td>
<td>{{ f.name }}</td>