mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-04-11 19:18:26 +02:00
Update QrCode controller to work with new TwoFAccount model
This commit is contained in:
parent
8baa2156a8
commit
45a3f60fc6
@ -2,14 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use OTPHP\TOTP;
|
|
||||||
use OTPHP\Factory;
|
|
||||||
use Zxing\QrReader;
|
use Zxing\QrReader;
|
||||||
use App\TwoFAccount;
|
use App\TwoFAccount;
|
||||||
use App\Classes\Options;
|
use App\Classes\Options;
|
||||||
use Illuminate\Http\File;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Assert\AssertionFailedException;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use chillerlan\QRCode\{QRCode, QROptions};
|
use chillerlan\QRCode\{QRCode, QROptions};
|
||||||
|
|
||||||
@ -46,6 +42,8 @@ public function decode(Request $request)
|
|||||||
|
|
||||||
if( Options::get('useBasicQrcodeReader') || $request->inputFormat === 'fileUpload') {
|
if( Options::get('useBasicQrcodeReader') || $request->inputFormat === 'fileUpload') {
|
||||||
|
|
||||||
|
// The frontend send an image resource of the QR code
|
||||||
|
|
||||||
// input validation
|
// input validation
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'qrcode' => 'required|image',
|
'qrcode' => 'required|image',
|
||||||
@ -61,7 +59,7 @@ public function decode(Request $request)
|
|||||||
Storage::delete($path);
|
Storage::delete($path);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// The QR code has been flashed and the URI is already decoded
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'uri' => 'required|string',
|
'uri' => 'required|string',
|
||||||
]);
|
]);
|
||||||
@ -70,36 +68,10 @@ public function decode(Request $request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return the OTP object
|
// return the OTP object
|
||||||
try {
|
$twofaccount = new TwoFAccount;
|
||||||
|
$twofaccount->populateFromUri($uri);
|
||||||
|
|
||||||
$otp = Factory::loadFromProvisioningUri($uri);
|
return response()->json($twofaccount->makeVisible(['secret', 'algorithm']), 200);
|
||||||
|
|
||||||
if(!$otp->getIssuer()) {
|
|
||||||
$otp->setIssuer($otp->getLabel());
|
|
||||||
$otp->setLabel('');
|
|
||||||
}
|
|
||||||
|
|
||||||
// returned object
|
|
||||||
$twofaccount = (object) array(
|
|
||||||
'service' => $otp->getIssuer(),
|
|
||||||
'account' => $otp->getLabel(),
|
|
||||||
'uri' => $uri,
|
|
||||||
'icon' => '',
|
|
||||||
'options' => $otp->getParameters()
|
|
||||||
);
|
|
||||||
|
|
||||||
return response()->json($twofaccount, 200);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (AssertionFailedException $exception) {
|
|
||||||
|
|
||||||
$error = \Illuminate\Validation\ValidationException::withMessages([
|
|
||||||
'qrcode' => __('errors.response.no_valid_otp')
|
|
||||||
]);
|
|
||||||
|
|
||||||
throw $error;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user