Skip to content

Commit

Permalink
Rename methods and variables (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoraddatz authored Apr 22, 2024
1 parent fe3a7af commit f88d105
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions resources/views/code.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="https://cdn.tailwindcss.com"></script>

<script>
const code_length = {{ config('totp-login.code.length') }};
const totp_code_length = {{ config('totp-login.code.length') }};
</script>
</head>
<body class="antialiased">
Expand Down Expand Up @@ -50,7 +50,7 @@

{{-- Code inputs --}}
<div class="flex justify-center" x-data="code()">
<template x-for="(l,i) in code_length" :key="`code_field_${i}`">
<template x-for="(l,i) in totp_code_length" :key="`code_field_${i}`">
<input :id="`code_field_${i}`"
:autofocus="i === 0"
:aria-label="`Code Element ${i + 1}`"
Expand Down Expand Up @@ -127,12 +127,12 @@ class="bg-transparent cursor-pointer text-light dark:text-gray-200 hover:underli
paste = paste.replace(/\s+/g, '');
if (isNaN(parseInt(paste)) || paste.length !== pin_length) {
if (isNaN(parseInt(paste)) || paste.length !== totp_code_length) {
return;
}
for (let i = 0; i < paste.length; i++) {
document.getElementById(`pin_field_${i}`).value = paste[i];
document.getElementById(`code_field_${i}`).value = paste[i];
}
document.getElementById(`submit`).focus();
Expand All @@ -143,27 +143,27 @@ class="bg-transparent cursor-pointer text-light dark:text-gray-200 hover:underli
function code() {
return {
resetValue(i) {
for (let x = 0; x < pin_length; x++) {
if (x >= i) document.getElementById(`pin_field_${x}`).value = '';
for (let x = 0; x < totp_code_length; x++) {
if (x >= i) document.getElementById(`code_field_${x}`).value = '';
}
},
stepForward(i) {
// Last input has been filled; there is no next input
if (document.getElementById(`pin_field_${i}`).value && i === pin_length - 1) {
if (document.getElementById(`code_field_${i}`).value && i === totp_code_length - 1) {
document.getElementById(`submit`).focus();
return;
}
// Return if the next input is already filled (conflict with paste)
if (document.getElementById(`pin_field_${i + 1}`).value) {
if (document.getElementById(`code_field_${i + 1}`).value) {
return;
}
// Next input is empty
if (document.getElementById(`pin_field_${i}`).value && i !== pin_length - 1) {
document.getElementById(`pin_field_${i + 1}`).focus();
document.getElementById(`pin_field_${i + 1}`).value = '';
if (document.getElementById(`code_field_${i}`).value && i !== totp_code_length - 1) {
document.getElementById(`code_field_${i + 1}`).focus();
document.getElementById(`code_field_${i + 1}`).value = '';
}
},
Expand All @@ -172,8 +172,8 @@ function code() {
return;
}
document.getElementById(`pin_field_${i - 1}`).focus();
document.getElementById(`pin_field_${i - 1}`).value = '';
document.getElementById(`code_field_${i - 1}`).focus();
document.getElementById(`code_field_${i - 1}`).value = '';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/notification.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{!! $introLines[0] !!}

<div style="text-align:center;width:100%;margin:50px 0">
@foreach($pin as $digit)
@foreach($code as $digit)
<strong style="border:1px solid blue;padding:15px;font-size:20px;border-radius:5px;margin:0 2px">{{ $digit }}</strong>
@endforeach
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/HandleCodeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class HandleCodeRequest extends Controller
{
protected ?string $pin = null;
protected ?string $code = null;

/**
* @var \Illuminate\Database\Eloquent\Model
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/LoginCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class LoginCode extends Notification
{
public function __construct(protected readonly string $pin, protected readonly string $ip)
public function __construct(protected readonly string $code, protected readonly string $ip)
{
}

Expand Down

0 comments on commit f88d105

Please sign in to comment.