mirror of https://github.com/Bubka/2FAuth.git
Compare commits
3 Commits
9c8d349e1c
...
dd7d3d95df
Author | SHA1 | Date |
---|---|---|
Bubka | dd7d3d95df | |
Bubka | 2e296ba3c1 | |
Bubka | 2db5adfe3b |
|
@ -45,7 +45,8 @@ class Handler extends ExceptionHandler
|
|||
|
||||
$this->renderable(function (InvalidQrCodeException $exception, $request) {
|
||||
return response()->json([
|
||||
'message' => 'not a valid QR code', ], 400);
|
||||
'message' => $exception->getMessage(),
|
||||
], 400);
|
||||
});
|
||||
|
||||
$this->renderable(function (InvalidSecretException $exception, $request) {
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace App\Services;
|
|||
use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Zxing\ChecksumException;
|
||||
use Zxing\FormatException;
|
||||
use Zxing\NotFoundException;
|
||||
use Zxing\QrReader;
|
||||
|
||||
class QrCodeService
|
||||
|
@ -37,12 +40,39 @@ class QrCodeService
|
|||
public static function decode(\Illuminate\Http\UploadedFile $file)
|
||||
{
|
||||
$qrcode = new QrReader($file->get(), QrReader::SOURCE_TYPE_BLOB);
|
||||
$data = urldecode($qrcode->text());
|
||||
$text = $qrcode->text();
|
||||
|
||||
if (! $data) {
|
||||
throw new \App\Exceptions\InvalidQrCodeException;
|
||||
if (! $text) {
|
||||
$text = $qrcode->text([
|
||||
'TRY_HARDER' => true,
|
||||
'NR_ALLOW_SKIP_ROWS' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
// At this point, if we do not have a text, QR code cannot be detected or decoded
|
||||
// so we check the error to provide the user a relevant error message
|
||||
if (! $text) {
|
||||
switch (get_class($qrcode->getError())) {
|
||||
case NotFoundException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_detect_qrcode_in_image'));
|
||||
break;
|
||||
|
||||
case FormatException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_decode_detected_qrcode'));
|
||||
break;
|
||||
|
||||
case ChecksumException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.qrcode_has_invalid_checksum'));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.no_readable_qrcode'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$data = urldecode($qrcode->text());
|
||||
|
||||
Log::info('QR code decoded');
|
||||
|
||||
return $data;
|
||||
|
|
|
@ -9,12 +9,31 @@ echo "supervisord version: $(supervisord version)"
|
|||
php-fpm81 -v | head -n 1
|
||||
nginx -v
|
||||
|
||||
# Database creation
|
||||
if [ "${DB_CONNECTION}" = "sqlite" ]; then
|
||||
if [ ! -f /2fauth/database.sqlite ]; then
|
||||
touch /2fauth/database.sqlite
|
||||
# DB_DATABASE is trimmed if necessary
|
||||
if [[ $DB_DATABASE == \"* ]] && [[ $DB_DATABASE == *\" ]] ; then
|
||||
dbpath=${DB_DATABASE:1:${#DB_DATABASE}-2}
|
||||
else
|
||||
dbpath=${DB_DATABASE}
|
||||
fi
|
||||
if [ $dbpath != "/srv/database/database.sqlite" ]; then
|
||||
echo "DB_DATABASE sets with custom path: ${dbpath}"
|
||||
if [ ! -f ${dbpath} ]; then
|
||||
echo "${dbpath} does not exist, we create it"
|
||||
touch ${dbpath}
|
||||
fi
|
||||
else
|
||||
echo "DB_DATABASE sets with default path, we will use a symlink"
|
||||
echo "Actual db file will be /2fauth/database.sqlite"
|
||||
if [ ! -f /2fauth/database.sqlite ]; then
|
||||
echo "/2fauth/database.sqlite does not exist, we create it"
|
||||
touch /2fauth/database.sqlite
|
||||
fi
|
||||
rm -f /srv/database/database.sqlite
|
||||
ln -s /2fauth/database.sqlite /srv/database/database.sqlite
|
||||
echo "/srv/database/database.sqlite is now a symlink to /2fauth/database.sqlite"
|
||||
fi
|
||||
rm -f /srv/database/database.sqlite
|
||||
ln -s /2fauth/database.sqlite /srv/database/database.sqlite
|
||||
fi
|
||||
|
||||
# Inject storage in /2fauth and use it with a symlink
|
||||
|
@ -30,7 +49,8 @@ if [ -f /2fauth/installed ]; then
|
|||
INSTALLED_COMMIT="$(cat /2fauth/installed)"
|
||||
if [ "${INSTALLED_COMMIT}" != "${COMMIT}" ]; then
|
||||
echo "Installed commit ${INSTALLED_COMMIT} is different from program commit ${COMMIT}, we are migrating..."
|
||||
php artisan optimize:clear
|
||||
php artisan cache:clear
|
||||
php artisan config:clear
|
||||
php artisan migrate --force
|
||||
fi
|
||||
else
|
||||
|
@ -40,6 +60,7 @@ fi
|
|||
|
||||
echo "${COMMIT}" > /2fauth/installed
|
||||
php artisan storage:link --quiet
|
||||
php artisan optimize:clear
|
||||
php artisan config:cache
|
||||
php artisan route:cache
|
||||
php artisan view:cache
|
||||
|
|
|
@ -27,7 +27,7 @@ return [
|
|||
'confirm' => [
|
||||
'delete_user' => 'Are you sure you want to delete this user? There is no going back.',
|
||||
'request_password_reset' => 'Are you sure you want to reset this user\'s password?',
|
||||
'purge_password_reset_request' => 'Are you sure you want to purge the request?',
|
||||
'purge_password_reset_request' => 'Are you sure you want to revoke the previous request?',
|
||||
'delete_account' => 'Are you sure you want to delete this user?',
|
||||
'edit_own_account' => 'This is your own account. Are you sure?',
|
||||
'change_admin_role' => 'This will have serious impacts on this user\'s permissions. Are you sure?',
|
||||
|
|
|
@ -22,7 +22,7 @@ return [
|
|||
'sign_out' => 'Sign out',
|
||||
'sign_in' => 'Sign in',
|
||||
'sign_in_using' => 'Sign in using',
|
||||
'or_continue_with' => 'You an also continue with:',
|
||||
'or_continue_with' => 'You can also continue with:',
|
||||
'sign_in_using_security_device' => 'Sign in using a security device',
|
||||
'login_and_password' => 'login & password',
|
||||
'register' => 'Register',
|
||||
|
|
|
@ -79,7 +79,6 @@ return [
|
|||
'nothing' => 'nothing',
|
||||
'no_result' => 'No result',
|
||||
'information' => 'Information',
|
||||
'permissions' => 'Permissions',
|
||||
'send' => 'Send',
|
||||
'optimize' => 'Optimize',
|
||||
];
|
||||
|
|
|
@ -67,5 +67,8 @@ return [
|
|||
'account_managed_by_external_provider' => 'Account managed by an external provider',
|
||||
'data_cannot_be_refreshed_from_server' => 'Data cannot be refreshed from server',
|
||||
'no_pwd_reset_for_this_user_type' => 'Password reset unavailable for this user',
|
||||
'app_key_is_not_set' => 'The APP_KEY environment variable is not set',
|
||||
'cannot_detect_qrcode_in_image' => 'Cannot detect a QR code in the image, try to crop the image',
|
||||
'cannot_decode_detected_qrcode' => 'Cannot decode detected QR code, try to crop or sharpen the image',
|
||||
'qrcode_has_invalid_checksum' => 'QR code has invalid checksum',
|
||||
'no_readable_qrcode' => 'No readable QR code',
|
||||
];
|
Loading…
Reference in New Issue