Skip to content

Commit

Permalink
feat: auto submit token from oauth path
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Feb 1, 2024
1 parent b099592 commit f8f531e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ianm-twofactor:
reset_password:
two_factor_token_label: 2FA Token
two_factor_token:
title: Two-Factor Authentication
submit_button: Submit Token

blomstra-gdpr:
Expand Down
17 changes: 15 additions & 2 deletions views/oauth/verify.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@

<h3>{{ $translator->trans('ianm-twofactor.forum.log_in.two_factor_required_message') }}</h3>

<form class="form" method="POST" action="{{ $url->to('forum')->route('twoFactor.oauth.verify') }}">
<form class="form" method="POST" action="{{ $url->to('forum')->route('twoFactor.oauth.verify') }}" id="twoFactorForm">
<input type="hidden" name="csrfToken" value="{{ $csrfToken }}">

<p class="form-group">
<input type="text" class="form-control" name="twoFactorToken" placeholder="{{ $translator->trans('ianm-twofactor.forum.log_in.two_factor_placeholder') }}" required>
<input type="text" class="form-control" name="twoFactorToken" id="twoFactorTokenInput" placeholder="{{ $translator->trans('ianm-twofactor.forum.log_in.two_factor_placeholder') }}" inputmode="numeric" pattern="[0-9]*" autocomplete="one-time-code" required>
</p>

<p class="form-group">
<button type="submit" class="button">{{ $translator->trans('ianm-twofactor.views.two_factor_token.submit_button') }}</button>
</p>
</form>

<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('twoFactorForm');
const tokenInput = document.getElementById('twoFactorTokenInput');
tokenInput.addEventListener('input', function() {
if (tokenInput.value.length === 6) {
form.submit();
}
});
});
</script>
@endsection

0 comments on commit f8f531e

Please sign in to comment.