mother = $mother; add_action('wp_ajax_tfa_frontend', array($this, 'ajax')); add_shortcode('twofactor_user_settings', array($this, 'tfa_user_settings_front')); } public function ajax(){ $tfa = $this->mother->getTFA(); global $current_user; $return_array = array(); if (empty($_POST) || empty($_POST['subaction']) || !isset($_POST['nonce']) || !is_user_logged_in() || !wp_verify_nonce($_POST['nonce'], 'tfa_frontend_nonce')) die('Security check'); if('savesettings' == $_POST['subaction']) { if (empty($_POST['settings']) || !is_string($_POST['settings'])) die; parse_str($_POST['settings'], $posted_settings); //Added if(isset($posted_settings["tfa_enable_tfa"])) { $tfa->changeEnableTFA($current_user->ID, $posted_settings["tfa_enable_tfa"]); } if(isset($posted_settings["tfa_algorithm_type"])) { $old_algorithm = $tfa->getUserAlgorithm($current_user->ID); if($old_algorithm != $posted_settings['tfa_algorithm_type']) $tfa->changeUserAlgorithmTo($current_user->ID, $posted_settings['tfa_algorithm_type']); //Re-fetch the algorithm type, url and private string $variables = $this->tfa_fetch_assort_vars(); $return_array['qr'] = $this->mother->tfa_qr_code_url($variables['algorithm_type'], $variables['url'], $variables['tfa_priv_key']); $return_array['al_type_disp'] = $this->tfa_algorithm_info($variables['algorithm_type']); } $return_array['result'] = 'saved'; echo json_encode($return_array); } die; } //Make the algorithm information string easier to update public function tfa_algorithm_info($algorithm_type) { $al_type_disp = strtoupper($algorithm_type); $al_type_desc = ($algorithm_type == 'totp' ? __('a time based', 'two-factor-authentication') : __('an event based', 'two-factor-authentication')); return array('disp' => $al_type_disp, 'desc' => $al_type_desc); } /* Make the assorted required variables more accessible for ajax Returns: Site URl, private key, emergency codes, algorithm type */ public function tfa_fetch_assort_vars(){ global $current_user; $tfa = $this->mother->getTFA(); $url = preg_replace('/^https?:\/\//', '', site_url()); $tfa_priv_key_64 = get_user_meta($current_user->ID, 'tfa_priv_key_64', true); if(!$tfa_priv_key_64) $tfa_priv_key_64 = $tfa->addPrivateKey($current_user->ID); $tfa_priv_key = trim($tfa->getPrivateKeyPlain($tfa_priv_key_64, $current_user->ID)); $algorithm_type = $tfa->getUserAlgorithm($current_user->ID); return apply_filters('simba_tfa_fetch_assort_vars', array( 'url' => $url, 'tfa_priv_key_64' => $tfa_priv_key_64, 'tfa_priv_key' => $tfa_priv_key, 'emergency_str' => ''.__('No emergency codes left. Sorry.', 'two-factor-authentication').'', 'algorithm_type' => $algorithm_type ), $tfa, $current_user); } public function save_settings_button() { echo ''; } private function get_tfa() { if (empty($this->tfa)) $this->tfa = $this->mother->getTFA(); } public function settings_enable_or_disable_output() { $this->save_settings_javascript_output(); global $current_user; ?>

mother->tfaListEnableRadios($current_user->ID, true); ?>

get_tfa(); if(!$this->tfa->isActivatedForUser($current_user->ID)){ echo __('Two factor authentication is not available for your user.', 'two-factor-authentication'); } else { ?>
mother->settings_intro_notices(); ?> settings_enable_or_disable_output(); ?> mother->current_codes_box(false); ?> mother->advanced_settings_box(array($this, 'save_settings_button')); ?>
save_settings_javascript_output(); ?>