Currently we have some license issues. We are working on it.

Commit 4d95b1b1 authored by noplanman's avatar noplanman
Browse files

Merge branch '15-native_qr_code_generator' into 'develop'

Add native QR Code rendering

See merge request !15
parents 7b864c26 f636777a
Pipeline #4508 passed with stage
in 20 seconds
......@@ -9,6 +9,8 @@
namespace Wp_Otp;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use OTPHP\TOTP;
use ParagonIE\ConstantTime\Base32;
use WP_User;
......@@ -239,6 +241,7 @@ class Wp_Otp_Admin {
// Issuer isn't allowed to have any colon.
$otp->setIssuer( str_replace( [ ':', '%3a', '%3A' ], '', get_bloginfo( 'name' ) ) );
$qr_code_provisioning_uri_default = 'https://api.qrserver.com/v1/create-qr-code/?data={PROVISIONING_URI}&qzone=2';
/**
* Filter for the OTP QR code provisioning URI.
*
......@@ -248,10 +251,20 @@ class Wp_Otp_Admin {
*
* @param string $qr_code_provisioning_uri
*/
$otp_qr_code_uri = $otp->getQrCodeUri( apply_filters(
'wp_otp_qr_code_provisioning_uri',
'https://api.qrserver.com/v1/create-qr-code/?data={PROVISIONING_URI}&qzone=2&size=300x300'
), '{PROVISIONING_URI}' );
$qr_code_provisioning_uri = apply_filters( 'wp_otp_qr_code_provisioning_uri', $qr_code_provisioning_uri_default );
$otp_qr_code_img_uri = $otp->getQrCodeUri( $qr_code_provisioning_uri, '{PROVISIONING_URI}' );
// If no custom provisioning URI is set, opt for internal QR code processing, if possible.
if ( $qr_code_provisioning_uri === $qr_code_provisioning_uri_default ) {
try {
$qr_code_options = new QROptions( [ 'quietzoneSize' => 2 ] );
$qr_code = new QRCode( $qr_code_options );
$otp_qr_code_raw_uri = $otp->getProvisioningUri();
$otp_qr_code_img_uri = $qr_code->render( $otp_qr_code_raw_uri );
} catch ( \Throwable $e ) {
// Silently fail and fall back to online provisioning.
}
}
$otp_enabled = $user_meta_data->get( 'enabled' );
......
......@@ -42,7 +42,7 @@
<?php endif; ?>
</th>
<td>
<img src="<?php echo $otp_qr_code_uri; ?>"/><br>
<img src="<?php echo $otp_qr_code_img_uri; ?>" alt="<?php _e( 'QR Code to scan with mobile app', 'wp-otp' ); ?>"/><br>
</td>
<td>
<span class="description">
......
......@@ -24,7 +24,8 @@
],
"require": {
"php": "^7.2",
"spomky-labs/otphp": "^10.0"
"spomky-labs/otphp": "^10.0",
"chillerlan/php-qrcode": "^3.3"
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
......
......@@ -40,6 +40,7 @@ Also, if you have an idea you would like to see in this plugin or if you've foun
= Filters =
There are a multitude of filters to be adjusted.
* `wp_otp_qr_code_provisioning_uri`: URI for online QR Code rendering (must contain `{PROVISIONING_URI}` placeholder for QR Code data).
* `wp_otp_login_form_text`: Text for input field on the login screen.
* `wp_otp_login_form_text_sub`: Subtext for the input field on the login screen.
* `wp_otp_login_form_invalid_code_text`: Error text for an invalid code input on the login screen.
......@@ -96,6 +97,7 @@ This means that you will need to add your OTP (or recovery) code at the end of y
= Unreleased =
* Require at least PHP 7.2.
* Update OTPHP to 10.0.
* Add native QR code rendering.
= 0.4.1 =
* Fix nullable return type when checking if OTP is enabled.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment