Skip to content

Commit

Permalink
Version 1.5.1
Browse files Browse the repository at this point in the history
* Updated Danish translations (primarily the two-factor settings and frontend).
* Fix: Our shortcode had unintentionally been renamed. We now support both `[gwapi]` and `[gatewayapi]`.
* Fix: Two-factor-module caused fatal error on PHP 5. Also fixed general notices in two-factor module.
* Fix: Two-factor module caused fatal error when creating new WordPress-users.
  • Loading branch information
bitnissen committed Aug 16, 2018
1 parent cd97c54 commit e7baceb
Show file tree
Hide file tree
Showing 6 changed files with 1,201 additions and 1,009 deletions.
2 changes: 1 addition & 1 deletion gatewayapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: GatewayAPI
Plugin URI: https://wordpress.org/plugins/gatewayapi/
Description: Send SMS'es through WordPress.
Version: 1.5.0
Version: 1.5.1
Author: OnlineCity ApS
Author URI: http://onlinecity.dk
License: MIT
Expand Down
76 changes: 44 additions & 32 deletions inc/security_two_factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GwapiSecurityTwoFactor
public static function getRoles()
{
$roles = wp_roles()->get_names();
$current_roles = get_option('gwapi_security_required_roles', []);
$current_roles = get_option('gwapi_security_required_roles') ? : [];

$out = [];
foreach ($roles as $k => $t) {
Expand Down Expand Up @@ -389,15 +389,18 @@ public static function sendInitialSms()
}

// vars for HTML
$html = (function () use ($mcc, $mno, $tmp_token) {
ob_start();
include _gwapi_dir() . '/tpl/wp-login-confirm-phone.php';
return ob_get_clean();
})();
$html = self::getHtmlLoginConfirmPhone($mcc, $mno, $tmp_token);

die(json_encode(['success' => true, 'html' => $html]));
}

private static function getHtmlLoginConfirmPhone($mcc, $mno, $tmp_token)
{
ob_start();
include _gwapi_dir() . '/tpl/wp-login-confirm-phone.php';
return ob_get_clean();
}

/**
* Send the confirmation SMS.
*/
Expand Down Expand Up @@ -443,14 +446,17 @@ public static function confirmSms()

// then show a message of the happy success
$redirect_to = $login_info['redirect_to'];
$html = (function () use ($redirect_to) {
ob_start();
include _gwapi_dir() . '/tpl/wp-login-confirmed-phone.php';
return ob_get_clean();
})();
$html = self::getHtmlLoginConfirmedPhone($redirect_to);

die(json_encode(['success' => true, 'html' => $html]));
}

private static function getHtmlLoginConfirmedPhone($redirect_to)
{
ob_start();
include _gwapi_dir() . '/tpl/wp-login-confirmed-phone.php';
return ob_get_clean();
}
}


Expand Down Expand Up @@ -497,26 +503,29 @@ public static function handleLogin(\WP_User $user)
}
}

(function () use ($mcc, $mno) {
// anonymize the phone number
$mno = str_repeat('·', strlen($mno) - 3) . substr($mno, -3, 3);
$tmp_token = GwapiSecurityTwoFactor::$TMP_TOKEN;

// enqueue css/js
GwapiSecurityTwoFactor::enqueueCssJs();

// tweak the form id, so the JS hooks in properly
add_filter('gwapi_confirm_phone_form_id', function ($c) {
return "gwapi_confirm_login_form";
});

// output!
login_header(__('Two-factor security check', 'gatewayapi'));
echo '<div class="step current">';
include _gwapi_dir() . '/tpl/wp-login-confirm-phone.php';
echo '</div>';
login_footer();
})();
self::getHtmlLoginConfirmPhone($mcc, $mno);
}

private static function getHtmlLoginConfirmPhone($mcc, $mno)
{
// anonymize the phone number
$mno = str_repeat('·', strlen($mno) - 3) . substr($mno, -3, 3);
$tmp_token = GwapiSecurityTwoFactor::$TMP_TOKEN;

// enqueue css/js
GwapiSecurityTwoFactor::enqueueCssJs();

// tweak the form id, so the JS hooks in properly
add_filter('gwapi_confirm_phone_form_id', function ($c) {
return "gwapi_confirm_login_form";
});

// output!
login_header(__('Two-factor security check', 'gatewayapi'));
echo '<div class="step current">';
include _gwapi_dir() . '/tpl/wp-login-confirm-phone.php';
echo '</div>';
login_footer();
}

/**
Expand Down Expand Up @@ -573,7 +582,10 @@ class GwapiSecurityTwoFactorUserProfile
{
public static function addContactMethod($methods, $user = null)
{
if (!is_a($user, 'WP_User')) $user = get_user_by('id', $user->ID);
if (!is_a($user, 'WP_User')) {
if (is_object($user) && isset($user->ID) && is_int($user->ID)) $user = get_user_by('id', $user->ID);
else return $methods; // unsupported on brand new users
}
if (!GwapiSecurityTwoFactor::userNeedsTwoFactor($user)) return $methods;

// only enable this for when editing own profile
Expand Down
6 changes: 4 additions & 2 deletions inc/shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ function _gwapi_shortcode_handle_send_sms($atts)
return [ $action_text, $action_note ];
}

add_shortcode('gatewayapi', function($atts) {
$shortcode_fn = function($atts) {

// validate: action
$valid_actions = ['signup', 'update', 'unsubscribe', 'send_sms'];
Expand Down Expand Up @@ -544,4 +544,6 @@ function _gwapi_shortcode_handle_send_sms($atts)

// end form
echo '</form>';
});
};
add_shortcode('gatewayapi', $shortcode_fn);
add_shortcode('gwapi', $shortcode_fn);
Binary file modified languages/gatewayapi-da_DK.mo
Binary file not shown.
Loading

0 comments on commit e7baceb

Please sign in to comment.