PluginProbe
Two Factor Authentication / 1.14.14
Two Factor Authentication v1.14.14
1.12.2 1.13.0 1.14.10 1.14.11 1.14.14 1.14.15 1.14.16 1.14.17 1.14.23 1.14.24 1.14.26 1.14.27 1.14.3 1.14.4 1.14.5 1.14.7 1.14.8 1.15.5 1.16.0 1.2.10 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 All 98 releases
two-factor-authentication / simba-tfa / includes / login-form-integrations.php

login-form-integrations.php in Two Factor Authentication 1.14.14, at simba-tfa/includes/login-form-integrations.php

143 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access.');
4
5 /**
6 * Purpose of this class: abstract out code handling integrations with login forms
7 */
8
9 class Simba_TFA_Login_Form_Integrations {
10
11 // Main class
12 private $tfa;
13
14 /**
15 * Plugin constructor
16 *
17 * @param Object $tfa
18 */
19 public function __construct($tfa) {
20
21 $this->tfa = $tfa;
22
23 $enqueue_upon_actions = array(
24 // This is needed for the login form on the dedicated payment page (e.g. /checkout/order-pay/123456/?pay_for_order=true&key=wc_order_blahblahblah)
25 'woocommerce_login_form_start',
26 'woocommerce_before_customer_login_form',
27 // The login form on the checkout doesn't call the woocommerce_before_customer_login_form action
28 'woocommerce_before_checkout_form',
29 'affwp_login_fields_before',
30 );
31
32 foreach ($enqueue_upon_actions as $action) {
33 add_action($action, array($this->tfa, 'login_enqueue_scripts'));
34 }
35
36 if (!defined('TWO_FACTOR_DISABLE') || !TWO_FACTOR_DISABLE) {
37 add_action('affwp_process_login_form', array($this, 'affwp_process_login_form'));
38 }
39
40 add_filter('tml_display', array($this, 'tml_display'));
41 add_filter('wppb_login_form_bottom', array($this, 'pb_login_form'));
42
43 // We want to run first if possible, so that we're not aborted by JavaScript exceptions in other components (our code is critical to the login process for TFA users)
44 // Unfortunately, though, people start enqueuing from init onwards (before that is buggy - https://core.trac.wordpress.org/ticket/11526), so, we try to detect the login page and go earlier there.
45 if (isset($GLOBALS['pagenow']) && 'wp-login.php' === $GLOBALS['pagenow']) {
46 add_action('init', array($this->tfa, 'login_enqueue_scripts'), -99999999999);
47 } else {
48 add_action('login_enqueue_scripts', array($this->tfa, 'login_enqueue_scripts'), -99999999999);
49 }
50
51 add_filter('do_shortcode_tag', array($this, 'do_shortcode_tag'), 10, 2);
52
53 add_filter('simba_tfa_login_enqueue_localize', array($this, 'simba_tfa_login_enqueue_localize'), 9);
54
55 }
56
57 /**
58 * Catch TML login widgets (other TML login forms already trigger)
59 *
60 * @param Mixed $whatever
61 *
62 * @return Mixed
63 */
64 public function tml_display($whatever) {
65 $this->tfa->login_enqueue_scripts();
66 return $whatever;
67 }
68
69 /**
70 * Catch Profile Builder login form
71 *
72 * @param Mixed $whatever
73 *
74 * @return Mixed
75 */
76 public function pb_login_form($whatever) {
77 $this->tfa->login_enqueue_scripts();
78 return $whatever;
79 }
80
81 /**
82 * Runs upon the WP filter simba_tfa_login_enqueue_localize.
83 *
84 * @param Array $localize
85 *
86 * @return Array
87 */
88 public function simba_tfa_login_enqueue_localize($localize) {
89 // WP login form is #loginform
90 // Ultimate Membership Pro - April 2018
91 // Theme My Login 6.x - .tml-login form[name="loginform"]
92 // Theme My Login 7.x - .tml-login form[name="login"] (July 2018)
93 // WP Members - March 2018
94 // bbPress - June 2021
95 // WooCommerce - ported over from the separate wooextend.js code, June 2021
96 // Affiliates WP - ported over from the separate wooextend.js code, June 2021
97 $localize['login_form_selectors'] .= '.tml-login form[name="loginform"], .tml-login form[name="login"], #loginform, #wpmem_login form, form#ihc_login_form, .bbp-login-form, .woocommerce form.login, #affwp-login-form, #wppb-loginform';
98 $localize['login_form_off_selectors'] .= '#ihc_login_form';
99 return $localize;
100 }
101
102 /**
103 * Runs upon the WP action affwp_process_login_form
104 */
105 public function affwp_process_login_form() {
106
107 if (!function_exists('affiliate_wp')) return;
108
109 $affiliate_wp = affiliate_wp();
110 $login = $affiliate_wp->login;
111
112 $params = array(
113 'log' => stripslashes($_POST['affwp_user_login']),
114 'caller'=> $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'],
115 'two_factor_code' => isset($_POST['two_factor_code']) ? stripslashes((string) $_POST['two_factor_code']) : '',
116 );
117 $code_ok = $this->tfa->authorise_user_from_login($params, true);
118
119 $code_ok = apply_filters('simbatfa_affwp_process_login_form_auth_result', $code_ok, $params);
120
121 if (is_wp_error($code_ok)) {
122 $login->add_error($code_ok->get_error_code, $code_ok->get_error_message());
123 } elseif (!$code_ok) {
124 $login->add_error('authentication_failed', __('Error:', 'two-factor-authentication').' '.apply_filters('simba_tfa_message_code_incorrect', __('The one-time password (TFA code) you entered was incorrect.', 'two-factor-authentication')));
125 }
126
127 }
128
129 /**
130 * Ultimate Membership Pro support
131 *
132 * @param String $output
133 * @param String $tag
134 *
135 * @return String
136 */
137 public function do_shortcode_tag($output, $tag) {
138 if ('ihc-login-form' == $tag) $this->tfa->login_enqueue_scripts();
139 return $output;
140 }
141
142 }
143