Skip to content

Commit 0b968e9

Browse files
authored
Merge pull request #27 from maxdestors/fix/laravel12
Fix laravel12
2 parents 11220f9 + 6bef14b commit 0b968e9

File tree

8 files changed

+84
-46
lines changed

8 files changed

+84
-46
lines changed

src/App/Http/Controllers/TwoStepController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace jeremykenedy\laravel2step\App\Http\Controllers;
44

55
use App\Http\Controllers\Controller;
6-
use Auth;
76
use Carbon\Carbon;
87
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Support\Facades\Validator;
910
use jeremykenedy\laravel2step\App\Traits\Laravel2StepTrait;
10-
use Validator;
1111

1212
class TwoStepController extends Controller
1313
{
@@ -122,7 +122,7 @@ public function showVerification()
122122
if (!$sentTimestamp) {
123123
$this->sendVerificationCodeNotification($twoStepAuth);
124124
} else {
125-
$timeBuffer = config('laravel2step.laravel2stepTimeResetBufferSeconds');
125+
$timeBuffer = (int) config('laravel2step.laravel2stepTimeResetBufferSeconds');
126126
$timeAllowedToSendCode = $sentTimestamp->addSeconds($timeBuffer);
127127
if ($now->gt($timeAllowedToSendCode)) {
128128
$this->sendVerificationCodeNotification($twoStepAuth);

src/App/Traits/Laravel2StepTrait.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace jeremykenedy\laravel2step\App\Traits;
44

5-
use Auth;
65
use Carbon\Carbon;
76
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Auth;
88
use jeremykenedy\laravel2step\App\Models\TwoStepAuth;
99
use jeremykenedy\laravel2step\App\Notifications\SendVerificationCodeEmail;
1010

@@ -47,7 +47,7 @@ public function twoStepVerification($request)
4747
*/
4848
private function checkTimeSinceVerified($twoStepAuth)
4949
{
50-
$expireMinutes = config('laravel2step.laravel2stepVerifiedLifetimeMinutes');
50+
$expireMinutes = (int) config('laravel2step.laravel2stepVerifiedLifetimeMinutes');
5151
$now = Carbon::now();
5252
$expire = Carbon::parse($twoStepAuth->authDate)->addMinutes($expireMinutes);
5353
$expired = $now->gt($expire);
@@ -143,8 +143,10 @@ protected function getTwoStepAuthStatus(int $userId)
143143
*/
144144
protected function exceededTimeParser($time)
145145
{
146-
$tomorrow = Carbon::parse($time)->addMinutes(config('laravel2step.laravel2stepExceededCountdownMinutes'))->format('l, F jS Y h:i:sa');
147-
$remaining = $time->addMinutes(config('laravel2step.laravel2stepExceededCountdownMinutes'))->diffForHumans(null, true);
146+
$exceededCountdownMinutes = (int) config('laravel2step.laravel2stepExceededCountdownMinutes');
147+
$exceededTime = Carbon::parse($time)->addMinutes($exceededCountdownMinutes);
148+
$tomorrow = $exceededTime->format('l, F jS Y h:i:sa');
149+
$remaining = $exceededTime->diffForHumans(null, true);
148150

149151
$data = [
150152
'tomorrow' => $tomorrow,
@@ -157,14 +159,15 @@ protected function exceededTimeParser($time)
157159
/**
158160
* Check if time since account lock has expired and return true if account verification can be reset.
159161
*
160-
* @param datetime $time
162+
* @param string $time
161163
*
162164
* @return bool
163165
*/
164166
protected function checkExceededTime($time)
165167
{
166168
$now = Carbon::now();
167-
$expire = Carbon::parse($time)->addMinutes(config('laravel2step.laravel2stepExceededCountdownMinutes'));
169+
$exceededCountdownMinutes = (int) config('laravel2step.laravel2stepExceededCountdownMinutes');
170+
$expire = Carbon::parse($time)->addMinutes($exceededCountdownMinutes);
168171
$expired = $now->gt($expire);
169172

170173
if ($expired) {

src/Laravel2stepFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace jeremykenedy\laravel2step;
44

55
use Illuminate\Support\Facades\Facade;
6+
use jeremykenedy\laravel2step\App\Http\Middleware\Laravel2step;
67

78
class Laravel2stepFacade extends Facade
89
{

src/Laravel2stepServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function publishFiles()
8686

8787
$this->publishes(
8888
[
89-
__DIR__.'/resources/lang' => base_path('resources/lang/vendor/laravel2step'),
89+
__DIR__.'/resources/lang' => resource_path('lang/vendor/laravel2step'),
9090
],
9191
$publishTag
9292
);

src/config/laravel2step.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
'laravel2stepDatabaseConnection' => env('LARAVEL_2STEP_DATABASE_CONNECTION', 'mysql'),
20-
'laravel2stepDatabaseTable' => env('LARAVEL_2STEP_DATABASE_TABLE', 'twoStepAuth'),
20+
'laravel2stepDatabaseTable' => env('LARAVEL_2STEP_DATABASE_TABLE', 'laravel2step'),
2121

2222
/*
2323
|--------------------------------------------------------------------------
@@ -33,7 +33,7 @@
3333
|--------------------------------------------------------------------------
3434
*/
3535

36-
'verificationEmailFrom' => env('LARAVEL_2STEP_EMAIL_FROM', env('MAIL_USERNAME')),
36+
'verificationEmailFrom' => env('LARAVEL_2STEP_EMAIL_FROM', env('MAIL_FROM_ADDRESS')),
3737
'verificationEmailFromName' => env('LARAVEL_2STEP_EMAIL_FROM_NAME', config('app.name').' 2-Step Verification'),
3838

3939
/*

src/resources/views/scripts/input-parsing-auto-stepper.blade.php

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,82 @@
11
<script>
22
$(function() {
33
4-
// Check for on keypress
5-
$("input").on("keyup", function(event){
4+
// Special check for copy and paste because of maxlength="1" on inputs
5+
$("input").on("paste", function(event){
6+
var clipboard = event.originalEvent.clipboardData || window.clipboardData;
67
7-
var self = $(this);
8+
if (!clipboard) {
9+
return;
10+
}
811
9-
// Keyboard Controls
10-
var controls = [8,16,18,17,20,35,36,37,38,39,40,45,46,9,91,93,224,13,127,27,32];
12+
event.preventDefault();
1113
12-
// Special Chars
13-
var specialChars = [43,61,186,187,188,189,190,191,192, 219,220,221,222];
14+
// get and sanitize value
15+
var regexp = /[^a-zA-Z0-9]/g;
16+
var chars = (clipboard.getData('text') || '').replace(regexp, '').split('');
1417
15-
// Numbers
16-
var numbers = [48,49,50,51,52,53,54,55,56,57];
18+
if (!chars.length) {
19+
return;
20+
}
1721
18-
var preCombined = controls.concat(numbers);
19-
var combined = preCombined;
22+
var current = $(this);
23+
var lastFilled = current;
2024
21-
// Allow Letter
22-
for(var i = 65; i <= 90; i++){
23-
combined.push(i);
24-
}
25+
// fill each inputs with one char
26+
while (current.length && chars.length) {
27+
current.val(chars.shift());
28+
lastFilled = current;
29+
30+
if (!chars.length) {
31+
break;
32+
}
2533
26-
// handle Input
27-
if($.inArray(event.which, combined) === -1){
28-
event.preventDefault();
34+
// find next input
35+
var nextContainer = current.parent().parent().next();
36+
if (!nextContainer.length) {
37+
break;
38+
}
39+
var nextInput = nextContainer.find('input');
40+
if (!nextInput.length) {
41+
break;
42+
}
43+
current = nextInput;
2944
}
3045
31-
// Handle Autostepper
32-
if($.inArray(event.which, controls.concat(specialChars)) === -1){
33-
setTimeout(function(){
34-
if (self.hasClass('last-input')) {
35-
$('#submit_verification').focus();
36-
} else {
37-
self.parent().parent().next().find('input').focus();
38-
}
39-
}, 1);
46+
// focus on the last empty input or on the submit button if none left
47+
var nextContainer = lastFilled.parent().parent().next();
48+
if (nextContainer.length) {
49+
var nextInput = nextContainer.find('input');
50+
if (nextInput.length) {
51+
nextInput.focus();
52+
return;
53+
}
4054
}
4155
56+
$('#submit_verification').focus();
4257
});
43-
// Check for cop and paste
58+
4459
$("input").on("input", function(){
60+
61+
// get and sanitize value
62+
var self = $(this);
4563
var regexp = /[^a-zA-Z0-9]/g;
46-
if($(this).val().match(regexp)){
47-
$(this).val( $(this).val().replace(regexp,'') );
64+
var val = (self.val() || '').replace(regexp, '').slice(0, 1);
65+
66+
self.val(val);
67+
68+
// focus on the next empty input or on the submit button if none left
69+
if (val.length === 1) {
70+
var nextContainer = self.parent().parent().next();
71+
if (nextContainer.length) {
72+
var nextInput = nextContainer.find('input');
73+
if (nextInput.length) {
74+
nextInput.focus();
75+
return;
76+
}
77+
}
78+
79+
$('#submit_verification').focus();
4880
}
4981
});
5082

src/resources/views/twostep/verification.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<label for="v_input_1" class="sr-only control-label">
5151
{{ trans('laravel2step::laravel-verification.inputAlt1') }}
5252
</label>
53-
<input type="text" id="v_input_1" class="form-control text-center required" required name="v_input_1" value="" autofocus maxlength="1" minlength="1" tabindex="1" placeholder="">
53+
<input type="text" id="v_input_1" class="form-control text-center required" required name="v_input_1" value="" autofocus maxlength="1" minlength="1" tabindex="1" placeholder="">
5454
@if ($errors->has('v_input_1'))
5555
<span class="help-block">
5656
<strong>{{ $errors->first('v_input_1') }}</strong>
@@ -63,7 +63,7 @@
6363
<label for="v_input_2" class="sr-only control-label">
6464
{{ trans('laravel2step::laravel-verification.inputAlt2') }}
6565
</label>
66-
<input type="text" id="v_input_2" class="form-control text-center required" required name="v_input_2" value="" maxlength="1" minlength="1" tabindex="2" placeholder="">
66+
<input type="text" id="v_input_2" class="form-control text-center required" required name="v_input_2" value="" maxlength="1" minlength="1" tabindex="2" placeholder="">
6767
@if ($errors->has('v_input_2'))
6868
<span class="help-block">
6969
<strong>{{ $errors->first('v_input_2') }}</strong>
@@ -76,7 +76,7 @@
7676
<label for="v_input_3" class="sr-only control-label">
7777
{{ trans('laravel2step::laravel-verification.inputAlt3') }}
7878
</label>
79-
<input type="text" id="v_input_3" class="form-control text-center required" required name="v_input_3" value="" maxlength="1" minlength="1" tabindex="3" placeholder="">
79+
<input type="text" id="v_input_3" class="form-control text-center required" required name="v_input_3" value="" maxlength="1" minlength="1" tabindex="3" placeholder="">
8080
@if ($errors->has('v_input_3'))
8181
<span class="help-block">
8282
<strong>{{ $errors->first('v_input_3') }}</strong>
@@ -89,7 +89,7 @@
8989
<label for="v_input_4" class="sr-only control-label">
9090
{{ trans('laravel2step::laravel-verification.inputAlt4') }}
9191
</label>
92-
<input type="text" id="v_input_4" class="form-control text-center required last-input " required name="v_input_4" value="" maxlength="1" minlength="1" tabindex="4" placeholder="">
92+
<input type="text" id="v_input_4" class="form-control text-center required last-input " required name="v_input_4" value="" maxlength="1" minlength="1" tabindex="4" placeholder="">
9393
@if ($errors->has('v_input_4'))
9494
<span class="help-block">
9595
<strong>{{ $errors->first('v_input_4') }}</strong>

src/routes/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Illuminate\Support\Facades\Route;
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Laravel 2-Step Verification Web Routes

0 commit comments

Comments
 (0)