core&ui: add webauthn support (#484)

Co-authored-by: panda <panda_dtdyy@outlook.com>
Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
pandaandundefined authored and GitHub committed 2023-01-23 17:49:40 +08:00
1 parent 3d3a5480e3
commit d069fe127b
29 files changed
+621 -195

No files matched your search

@@ -89,16 +89,55 @@
<div class="columns">
<div class="section">
<div class="section__header">
<h1 class="section__title" id="tfa" data-heading>{{ _('Two Factor Authentication') }}</h1>
<h1 class="section__title" id="authenticator" data-heading>{{ _('Authenticators') }}</h1>
<div class="section__tools">
{% if handler.user.tfa %}
<button class="primary rounded button" name="tfa_enabled"><span class="icon icon-check"></span> {{ _('Enabled') }}</button>
{% else %}
<button class="primary rounded button" name="tfa_enable"><span class="icon icon-wrench"></span> {{ _('Enable') }}</button>
{% endif %}
<button class="primary rounded button" name="auth_enable"><span class="icon icon-wrench"></span> {{ _('Add Authenticator') }}</button>
</div>
</div>
<div class="section__body"></div>
<div class="section__body">
<ul class="autherlist">
{%- if handler.user.tfa -%}
<li class="autherlist__item">
<div class="media">
<div class="media__left medium">
<span class="autherlist__icon icon icon-platform--mobile }}"></span>
</div>
<div class="media__body medium typo">
<p>{{ _('Authenticator') }}: {{ _('Two Factor Authentication') }}</p>
</div>
<div class="media__right medium">
<form method="POST">
<input type="hidden" name="operation" value="disable_tfa">
<input type="submit" value="{{ _('Remove') }}" class="rounded button">
</form>
</div>
</div>
</li>
{%- endif -%}
{%- for authenticator in authenticators -%}
<li class="autherlist__item">
<div class="media">
<div class="media__left medium">
<span class="autherlist__icon icon icon-{{ 'fingerprint' if authenticator.authenticatorAttachment === 'platform' else 'usb' }}"></span>
</div>
<div class="media__body medium typo">
<p>{{ _('Authenticator') }}: {{ authenticator.name }} ({{ authenticator.credentialID.buffer.toString('base64')|truncate(6, end='') }})</p>
<p>{{ _('Type') }}: {{ authenticator.fmt }} </p>
<p>{{ _('Device Type') }}: {{ authenticator.credentialDeviceType }} </p>
<p>{{ _('Registered at') }}: {{ datetimeSpan(authenticator.regat)|safe }}</p>
</div>
<div class="media__right medium">
<form method="POST">
<input type="hidden" name="id" value="{{ authenticator.credentialID.buffer.toString('base64') }}">
<input type="hidden" name="operation" value="disable_authn">
<input type="submit" value="{{ _('Remove') }}" class="rounded button">
</form>
</div>
</div>
</li>
{%- endfor -%}
</ul>
</div>
</div>
</div>
</div>
@@ -27,19 +27,15 @@
<input name="password" type="password">
</label>
</div></div>
<div class="row" style="display: none" id="tfa_div"><div class="columns">
<label class="material textbox">
{{ _('Two Factor Authentication Code') }}
<input name="tfa" type="number">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="checkbox">
<input type="checkbox" name="rememberme" class="checkbox">{{ _('Remember me') }}
</label>
</div></div>
<div class="row"><div class="columns">
<input type="submit" value="{{ _('Sign In') }}" class="expanded rounded primary button">
<input type="hidden" name="tfa" value="">
<input type="hidden" name="authnChallenge" value="">
<input type="submit" value="{{ _('Login') }}" name="login_submit" class="expanded rounded primary button">
</div></div>
{% endif %}
{%- for v in handler.loginMethods -%}
@@ -17,20 +17,16 @@
<input name="password" type="password">
</label>
</div></div>
<div class="row" style="display: none" id="tfa_div"><div class="columns">
<label class="inverse material textbox">
{{ _('Two Factor Authentication Code') }}
<input name="tfa" type="number">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material checkbox" style="color:#fff;">
<input type="checkbox" name="rememberme" class="checkbox">{{ _('Remember me') }}
</label>
</div></div>
<div class="row"><div class="columns">
<input type="hidden" name="tfa" value="">
<input type="hidden" name="authnChallenge" value="">
<div class="text-center">
<input type="submit" value="{{ _('Login') }}" class="inverse expanded rounded primary button">
<input type="submit" value="{{ _('Login') }}" name="login_submit" class="inverse expanded rounded primary button">
</div>
</div></div>
{% endif %}
+35 -14
View File
@@ -4,30 +4,51 @@
<div class="immersive--content immersive--center">
<h1>{{ _('Confirm Access') }}</h1>
<form method="POST">
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Password') }}
<input name="password" type="password" autofocus>
</label>
{% if UserContext.authn %}
<div class="row sudo-div confirm-div nojs--hide" data-sudo="authn"><div class="columns">
<input value="{{ _('Use Authenticator') }}" class="inverse expanded rounded primary button" name="webauthn_verify">
<input type="hidden" name="authnChallenge" value="">
</div></div>
<div class="row" style="display: none" id="tfa_div"><div class="columns">
{% endif %}
{% if UserContext.tfa %}
<div class="row sudo-div" data-sudo="tfa" style="display:none"><div class="columns">
<label class="inverse material textbox">
{{ _('Two Factor Authentication Code') }}
<input name="tfa" type="number">
</label>
</div></div>
<div class="row"><div class="columns">
<div class="text-center">
<input type="submit" value="{{ _('Confirm') }}" class="inverse expanded rounded primary button">
</div>
{% endif %}
<div class="row sudo-div" data-sudo="password"><div class="columns">
<label class="inverse material textbox">
{{ _('Password') }}
<input name="password" type="password">
</label>
</div></div>
<div class="row"><div class="columns">
<div class="text-center supplementary inverse">
<p><strong>Tip:</strong> You are entering <a href="https://docs.github.com/articles/sudo-mode">sudo mode</a>.</p>
<p>After you've performed a sudo-protected action, you'll only be asked to re-authenticate again after a few hours of inactivity.</p>
<div class="row confirm-div"><div class="columns">
<div class="text-center">
<input value="{{ _('Confirm') }}" class="inverse expanded rounded primary button" name="confirm">
</div>
</div></div>
</form>
<div class="row"><div class="columns">
<div class="text-center supplementary inverse">
<p><strong>Tip:</strong> You are entering <a href="https://docs.github.com/articles/sudo-mode">sudo mode</a>.</p>
<p>After you've performed a sudo-protected action, you'll only be asked to re-authenticate again after a few hours of inactivity.</p>
</div>
</div></div>
{% if UserContext.authn or UserContext.tfa %}
<br>
<div class="row nojs--hide"><div class="columns">
<div class="supplementary inverse typo">
<p><strong>{{ _('Or use other methods:') }}</strong></p>
<ol>
{% if UserContext.authn %}<li class="sudo-switch" data-sudo="authn"><a>{{ _('Use Authenticator') }}</a></li>{% endif %}
{% if UserContext.tfa %}<li class="sudo-switch" data-sudo="tfa"><a>{{ _('Use TFA Code') }}</a></li>{% endif %}
<li class="sudo-switch" data-sudo="password" style="display:none"><a>{{ _('Use Password') }}</a></li>
</ol>
</div>
</div></div>
{% endif %}
</div>
</div></div>
{% endblock %}