/**
  * Get minimum protection type for given role.
  * If the protection type saved in settings is not available
  * for this consumer, then get the next available lower protection type.
  * 
  * @param string $role
  * @return string
  */
 static function getRoleProtectionType($role)
 {
     $settings = RublonHelper::getSettings('additional');
     $role_id = RublonHelper::prepareRoleId($role);
     if (isset($settings[$role_id])) {
         return self::getMinimumProtectionType($settings[$role_id]);
     } else {
         return RublonHelper::PROTECTION_TYPE_NONE;
     }
 }
示例#2
0
function rublon2factor_user_new_form()
{
    $roles = get_editable_roles();
    $roles_js = array();
    $roles_js['protection_levels'] = array();
    foreach ($roles as $role_name => $role) {
        $role_id = RublonHelper::prepareRoleId(esc_attr($role_name));
        $settings = RublonHelper::getSettings('additional');
        $role_protection_type = !empty($settings[$role_id]) ? $settings[$role_id] : '';
        switch ($role_protection_type) {
            case RublonHelper::PROTECTION_TYPE_MOBILE:
                $role_protection_level = 2;
                break;
            case RublonHelper::PROTECTION_TYPE_EMAIL:
                $role_protection_level = 1;
                break;
            default:
                $role_protection_level = 0;
        }
        $roles_js['protectionLevels'][esc_attr($role_name)] = $role_protection_level;
    }
    echo '<label class="hidden rublon-label rublon-label-newuserrole" for="rublon-newuserrole-dropdown">';
    echo '	<div class="rublon-lock-container rublon-locked-container rublon-newuserrole-locked"><img class="rublon-lock rublon-locked" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/locked.png" /></div>';
    echo '</label>';
    if (RublonFeature::isBusinessEdition()) {
        echo '<div class="hidden rublon-secured-role-description"><span class="description">' . sprintf(__('The new user account will be automatically protected by <a href="%s" target="_blank">Rublon</a>.', 'rublon'), RublonHelper::rubloncomUrl()) . '</span></div>';
        echo '<script>//<![CDATA[
    			document.addEventListener(\'DOMContentLoaded\', function() {
    				if (RublonWP) {
    					RublonWP.roleProtectionLevels = ' . json_encode($roles_js) . ';
    					RublonWP.setUpNewUserRoleChangeListener("your-profile", "rublon-confirmation-form");
    				}
    			}, false);
    		//]]></script>';
    }
}
示例#3
0
/**
 * Render "Email-based identity confirmation" settings.
 *
 * Callback for rendering the "Email-based identity confirmation"
 *  section settings on the plugin's page.
 *
 * @return void
 */
function rublon2factor_render_protection_types()
{
    echo '<p class="rublon-settings-desc">' . __('Every user is protected via email by default. You can turn this off for selected roles. For more security, you can also require selected roles to use the Rublon mobile app.', 'rublon') . '</p>';
    echo '<p class="rublon-settings-desc"><strong>' . __('Notice:', 'rublon') . ' </strong>' . __('Users of the Rublon mobile app are always protected, regardless of this setting. Users with no minimum protection can turn on protection via email themselves in their profile. Users with any level of minimum protection cannot turn it off.', 'rublon') . '</p>';
    $settings = RublonHelper::getSettings('additional');
    // Retrieve the roles used on this site.
    $roles = RublonHelper::getUserRoles();
    $role_ids = array();
    echo '<div class="rublon-settings-setting-name">';
    echo '  <div class="rublon-settings-setting-label"></div>';
    echo '  <div class="rublon-setting-header"><strong>' . __('Minimum Protection', 'rublon') . '</strong></div>';
    echo '</div>';
    foreach ($roles as $role) {
        $checked = '';
        // Prepare role IDs used as the option keys.
        $role_id = RublonHelper::prepareRoleId($role);
        $role_ids[] = '\'' . $role_id . '\'';
        if (!empty($settings[$role_id])) {
            $mobileSelected = '';
            $emailSelected = '';
            $noneSelected = '';
            $lock1Visibility = '';
            $lock2Visibility = '';
            $lock3Visibility = '';
            // 			switch ($settings[$role_id]) {
            switch (RublonRolesProtection::getRoleProtectionType($role)) {
                case RublonHelper::PROTECTION_TYPE_MOBILE_EVERYTIME:
                    $mobileEverytimeSelected = ' selected';
                    $lock1Visibility = 'hidden';
                    $lock2Visibility = 'visible';
                    $lock3Visibility = 'visible';
                    $lock4Visibility = 'visible';
                    break;
                case RublonHelper::PROTECTION_TYPE_MOBILE:
                    $mobileSelected = ' selected';
                    $lock1Visibility = 'hidden';
                    $lock2Visibility = 'visible';
                    $lock3Visibility = 'visible';
                    $lock4Visibility = 'hidden';
                    break;
                case RublonHelper::PROTECTION_TYPE_EMAIL:
                    $emailSelected = ' selected';
                    $lock1Visibility = 'hidden';
                    $lock2Visibility = 'visible';
                    $lock3Visibility = 'hidden';
                    $lock4Visibility = 'hidden';
                    break;
                case RublonHelper::PROTECTION_TYPE_NONE:
                    $noneSelected = ' selected';
                    $lock1Visibility = 'visible';
                    $lock2Visibility = 'hidden';
                    $lock3Visibility = 'hidden';
                    $lock4Visibility = 'hidden';
                    break;
            }
        }
        if (!empty($settings[$role_id]) && $settings[$role_id] == 'on') {
            $checked = ' checked';
        }
        echo '<div class="rublon-settings-setting-name">';
        echo '	<label for="rublon-role-' . $role_id . '-dropdown" class="rublon-settings-setting-label"><div class="rublon-settings-setting-label">' . translate_user_role(before_last_bar($role)) . '</div></label>';
        echo '	<select id="rublon-role-' . $role_id . '-dropdown" name="' . RublonHelper::RUBLON_ADDITIONAL_SETTINGS_KEY . '[' . $role_id . ']">';
        $forceMobileApp = RublonFeature::checkFeature(RublonAPIGetAvailableFeatures::FEATURE_FORCE_MOBILE_APP);
        if ($forceMobileApp and RublonFeature::checkFeature(RublonAPIGetAvailableFeatures::FEATURE_IGNORE_TRUSTED_DEVICE)) {
            echo '		<option value="mobileEverytime"' . $mobileEverytimeSelected . '>' . __('Mobile app everytime', 'rublon') . '</option>';
        }
        if ($forceMobileApp) {
            echo '		<option value="mobile"' . $mobileSelected . '>' . __('Mobile app', 'rublon') . '</option>';
        }
        echo '		<option value="email"' . $emailSelected . '>' . __('Email', 'rublon') . '</option>';
        echo '		<option value="none"' . $noneSelected . '>' . __('None', 'rublon') . '</option>';
        echo '	</select>';
        echo '<label class="rublon-label rublon-label-' . $role_id . '" for="rublon-role-' . $role_id . '-dropdown">';
        echo '	<div class="rublon-lock-container rublon-unlocked-container rublon-' . $role_id . '-unlocked ' . $lock1Visibility . '"><img class="rublon-lock rublon-unlocked" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/unlocked.png" /></div>';
        echo '	<div class="rublon-lock-container rublon-locked-container rublon-' . $role_id . '-locked ' . $lock2Visibility . '"><img class="rublon-lock rublon-locked" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/locked.png" /></div>';
        echo '	<div class="rublon-lock-container rublon-locked-container rublon-' . $role_id . '-locked2 ' . $lock3Visibility . '"><img class="rublon-lock rublon-locked" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/locked.png" /></div>';
        echo '	<div class="rublon-lock-container rublon-locked-container rublon-' . $role_id . '-locked3 ' . $lock4Visibility . '"><img class="rublon-lock rublon-locked" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/locked.png" /></div>';
        echo '</label>';
        echo '</div>';
    }
    echo '<script>//<![CDATA[
		if (RublonWP) {
			RublonWP.roles = [' . implode(', ', $role_ids) . '];
			RublonWP.setUpRoleProtectionTypeChangeListener();  
		}
	//]]></script>';
}