PluginProbe ʕ •ᴥ•ʔ
Firebase Authentication / 1.7.1
Firebase Authentication v1.7.1
1.7.1 1.7.0 trunk 1.0.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9
firebase-authentication / firebase-authentication.php
firebase-authentication Last commit date
admin 3 weeks ago includes 3 weeks ago languages 3 weeks ago public 3 weeks ago views 3 weeks ago README.txt 3 weeks ago class-mo-firebase-config.php 3 weeks ago class-mo-firebase-contact-us.php 3 weeks ago firebase-authentication.php 3 weeks ago index.php 3 weeks ago uninstall.php 3 weeks ago
firebase-authentication.php
657 lines
1 <?php //phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase -- Not changing file name because this is the main plugin file, and changing this would lead to deacivation of plugin for the active users.
2 /**
3 * Initial File for Firebase Authentication plugin.
4 *
5 * @link https://miniorange.com
6 * @since 1.0.0
7 * @package Firebase_Authentication
8 *
9 * @wordpress-plugin
10 * Plugin Name: Firebase Authentication
11 * Plugin URI: https://wordpress.org/plugins/firebase-authentication/
12 * Description: This plugin allows login into WordPress using Firebase as Identity provider.
13 * Version: 1.7.1
14 * Author: miniOrange
15 * Author URI: https://miniorange.com
16 * License: Expat
17 * License URI: https://plugins.miniorange.com/mit-license
18 */
19
20 // If this file is called directly, abort.
21 if ( ! defined( 'WPINC' ) ) {
22 die;
23 }
24
25 /**
26 * Currently plugin version.
27 * Start at version 1.0.0 and use SemVer - https://semver.org
28 * Rename this for your plugin and update it as you release new versions.
29 */
30 define( 'MO_FIREBASE_AUTHENTICATION_VERSION', '1.7.1' );
31 define( 'MO_FIREBASE_AUTHENTICATION_DIR', plugin_dir_path( __FILE__ ) );
32 define( 'MO_FIREBASE_AUTHENTICATION_URL', plugin_dir_url( __FILE__ ) );
33
34 /**
35 * The code that runs during plugin deactivation.
36 * This action is documented in includes/class-mo-firebase-authentication-deactivator.php
37 */
38 function mo_firebase_deactivate_firebase_authentication() {
39 require_once MO_FIREBASE_AUTHENTICATION_DIR . 'includes' . DIRECTORY_SEPARATOR . 'class-mo-firebase-authentication-deactivator.php';
40 MO_Firebase_Authentication_Deactivator::deactivate();
41 }
42
43 register_deactivation_hook( __FILE__, 'mo_firebase_deactivate_firebase_authentication' );
44
45 /**
46 * The core plugin class that is used to define internationalization,
47 * admin-specific hooks, and public-facing site hooks.
48 */
49 require MO_FIREBASE_AUTHENTICATION_DIR . 'includes' . DIRECTORY_SEPARATOR . 'class-mo-firebase-authentication.php';
50 require_once 'class-mo-firebase-config.php';
51 require 'views' . DIRECTORY_SEPARATOR . 'feedback-form.php';
52 require 'class-mo-firebase-contact-us.php';
53 require 'admin' . DIRECTORY_SEPARATOR . 'class-mo-firebase-customer.php';
54
55
56 /**
57 * Begins execution of the plugin.
58 *
59 * Since everything within the plugin is registered via hooks,
60 * then kicking off the plugin from this point in the file does
61 * not affect the page life cycle.
62 *
63 * @since 1.0.0
64 */
65 function mo_firebase_run_firebase_authentication() {
66
67 $plugin = new MO_Firebase_Authentication();
68 $plugin->run();
69
70 }
71 mo_firebase_run_firebase_authentication();
72
73 /**
74 * Check if the customer key exists.
75 */
76 function mo_firebase_authentication_is_customer_registered() {
77 $email = get_option( 'mo_firebase_authentication_admin_email' );
78 $customer_key = get_option( 'mo_firebase_authentication_admin_customer_key' );
79 if ( ! $email || ! $customer_key || ! is_numeric( trim( $customer_key ) ) ) {
80 return 0;
81 } else {
82 return 1;
83 }
84 }
85 /**
86 * Check is license key verified
87 */
88 function mo_firebase_authentication_is_clv() {
89 $license_key = get_option( 'mo_firebase_authentication_lk' );
90 $isverified = get_option( 'mo_firebase_authentication_lv' );
91 if ( $isverified ) {
92 $isverified = mo_firebase_authentication_decrypt( $isverified );
93 }
94
95 if ( ! empty( $license_key ) && 'true' === $isverified ) {
96 return 1;
97 }
98 return 0;
99 }
100 /**
101 * Encryption for license key
102 *
103 * @param string $str .
104 */
105 function mo_firebase_authentication_encrypt( $str ) {
106 $pass = get_option( 'mo_firebase_authentication_customer_token' );
107 $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) );
108 $stra = str_split( $str );
109 foreach ( $stra as $k => $v ) {
110 $tmp = ord( $v ) + ord( $pass[ $k ] );
111 $stra[ $k ] = chr( $tmp > 255 ? ( $tmp - 256 ) : $tmp );
112 }
113 return base64_encode( join( '', $stra ) ); //phpcs:ignore -- ignoring DiscouragedPHPFunctions warning as this line of code is used for a valid code consisting license key encryption.
114 }
115 /**
116 * Decryption for license key
117 *
118 * @param string $str .
119 */
120 function mo_firebase_authentication_decrypt( $str ) {
121 $str = base64_decode( $str ); //phpcs:ignore -- ignoring DiscouragedPHPFunctions warning as this line of code is used for a valid code consisting license key ncryption.
122 $pass = get_option( 'mo_firebase_authentication_customer_token' );
123 $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) );
124 $stra = str_split( $str );
125 foreach ( $stra as $k => $v ) {
126 $tmp = ord( $v ) - ord( $pass[ $k ] );
127 $stra[ $k ] = chr( $tmp < 0 ? ( $tmp + 256 ) : $tmp );
128 }
129 return join( '', $stra );
130 }
131
132 /**
133 * Firebase Authentication Main Class
134 */
135 class Miniorange_Firebase_Authentication {
136 /**
137 * Constructor
138 */
139 public function __construct() {
140 add_action( 'init', array( $this, 'post_register' ) );
141 add_action( 'admin_init', array( $this, 'mo_firebase_auth_admin_forms_handler' ) );
142 if ( 1 === (int) get_option( 'mo_enable_firebase_auth' ) ) {
143 if ( strpos( ( isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '' ), '/wp-json' ) === false ) {
144 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
145 remove_filter( 'authenticate', 'wp_authenticate_email_password', 20, 3 );
146 add_filter( 'authenticate', array( $this, 'mo_firebase_auth' ), 0, 3 );
147 }
148 }
149 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message' ) );
150 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message' ) );
151 add_action( 'admin_footer', array( $this, 'mo_firebase_auth_feedback_request' ) );
152 add_action( 'admin_notices', array( $this, 'mo_firebase_unverified_email_admin_notice' ) );
153 add_action( 'wp_ajax_mo_firebase_dismiss_unverified_email_notice', array( $this, 'mo_firebase_dismiss_unverified_email_notice' ) );
154 update_option( 'mo_fb_host_name', 'https://login.xecurify.com' );
155 }
156
157 /**
158 * Shows an admin notice on the Plugins page and this plugin's settings page
159 * explaining that only Firebase-verified emails can log in by default.
160 * Reappears on every page load as long as the "allow unverified email login"
161 * setting stays unchecked - unless the admin has dismissed it, which is permanent.
162 */
163 public function mo_firebase_unverified_email_admin_notice() {
164 if ( get_option( 'mo_firebase_allow_unverified_email_login' )
165 || get_option( 'mo_firebase_unverified_login_notice_dismissed' )
166 || ! current_user_can( 'manage_options' ) ) {
167 return;
168 }
169
170 $screen = get_current_screen();
171 if ( ! $screen || ! in_array( $screen->id, array( 'plugins', 'toplevel_page_mo_firebase_authentication' ), true ) ) {
172 return;
173 }
174
175 $settings_url = admin_url( 'admin.php?page=mo_firebase_authentication&tab=loginsettings' );
176 $message = sprintf(
177 /* translators: %s: link to the Firebase Authentication login settings page. */
178 __( 'Firebase Authentication: For security reasons, only users with a Firebase-verified email address are allowed to log in. If you want to allow login for unverified email addresses, %s.', 'firebase-authentication' ),
179 '<a href="' . esc_url( $settings_url ) . '">' . esc_html__( 'click here to enable it', 'firebase-authentication' ) . '</a>'
180 );
181 $allowed_tags = array(
182 'a' => array( 'href' => array() ),
183 );
184 ?>
185 <div class="notice notice-warning is-dismissible mo-firebase-unverified-email-notice">
186 <p><?php echo wp_kses( $message, $allowed_tags ); ?></p>
187 </div>
188 <script>
189 jQuery( function ( $ ) {
190 $( document ).on( 'click', '.mo-firebase-unverified-email-notice .notice-dismiss', function () {
191 $.post( ajaxurl, {
192 action: 'mo_firebase_dismiss_unverified_email_notice',
193 nonce: '<?php echo esc_js( wp_create_nonce( 'mo_firebase_dismiss_unverified_email_notice' ) ); ?>'
194 } );
195 } );
196 } );
197 </script>
198 <?php
199 }
200
201 /**
202 * AJAX handler that permanently dismisses the unverified-email admin notice.
203 */
204 public function mo_firebase_dismiss_unverified_email_notice() {
205 if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'mo_firebase_dismiss_unverified_email_notice', 'nonce', false ) ) {
206 wp_send_json_error();
207 }
208 update_option( 'mo_firebase_unverified_login_notice_dismissed', 1 );
209 wp_send_json_success();
210 }
211
212 /**
213 * Save details after customer registration
214 */
215 public function post_register() {
216 if ( isset( $_POST['verify_user'] ) && isset( $_REQUEST['page'] ) && sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) === 'mo_firebase_authentication' && wp_verify_nonce( isset( $_REQUEST['mo_firebase_auth_config_field'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_auth_config_field'] ) ) : '', 'mo_firebase_auth_config_form' ) ) {
217
218 if ( current_user_can( 'administrator' ) ) {
219 update_option( 'mo_firebase_auth_disable_wordpress_login', isset( $_POST['disable_wordpress_login'] ) ? (int) filter_var( wp_unslash( $_POST['disable_wordpress_login'] ), FILTER_SANITIZE_NUMBER_INT ) : 0 );
220
221 update_option( 'mo_firebase_auth_enable_admin_wp_login', isset( $_POST['mo_firebase_auth_enable_admin_wp_login'] ) ? (int) filter_var( wp_unslash( $_POST['mo_firebase_auth_enable_admin_wp_login'] ), FILTER_SANITIZE_NUMBER_INT ) : 0 );
222
223 $project_id = isset( $_POST['projectid'] ) ? sanitize_text_field( wp_unslash( $_POST['projectid'] ) ) : '';
224 update_option( 'mo_firebase_auth_project_id', $project_id );
225
226 $api_key = isset( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : '';
227 update_option( 'mo_firebase_auth_api_key', $api_key );
228
229 $this->mo_firebase_auth_store_certificates();
230 update_option( 'mo_firebase_auth_message', 'Configurations saved successfully. Please <a href="' . admin_url( 'admin.php?page=mo_firebase_authentication&tab=config#test_authentication' ) . '">Test Authentication</a> before trying to Login.' );
231 $this->mo_firebase_auth_show_success_message();
232 }
233 }
234 }
235 /**
236 * Store certificates.
237 */
238 public function mo_firebase_auth_store_certificates() {
239 $response = wp_remote_get( 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com' );
240 if ( is_array( $response ) ) {
241 $header = $response['headers']; // array of http header lines.
242 $body = $response['body']; // use the content.
243
244 $split_result = explode( ':', $body );
245 $count = count( $split_result );
246 $kid1 = substr( $split_result[0], 5, 40 );
247 $s = explode( ',', $split_result[1] );
248 $c1 = substr( $s[0], 2, 1158 );
249 $c1 = str_replace( '\n', '', $c1 );
250 update_option( 'mo_firebase_auth_kid1', $kid1 );
251 update_option( 'mo_firebase_auth_cert1', $c1 );
252 if ( 3 === $count ) {
253 $kid2 = substr( $s[1], 4, 40 );
254 $c2 = explode( '}', $split_result[2] );
255 $c2[0] = substr( $c2[0], 2, 1158 );
256 $c2[0] = str_replace( '\n', '', $c2[0] );
257 update_option( 'mo_firebase_auth_kid2', $kid2 );
258 update_option( 'mo_firebase_auth_cert2', $c2[0] );
259 } elseif ( $count > 3 ) {
260 $kid2 = substr( $s[1], 4, 40 );
261 $s2 = explode( ',', $split_result[2] );
262 $c2 = substr( $s2[0], 2, 1158 );
263 $kid3 = substr( $s2[1], 4, 40 );
264 $c3 = explode( '}', $split_result[3] );
265 $c3[0] = substr( $c3[0], 2, 1158 );
266 $c2 = str_replace( '\n', '', $c2 );
267 update_option( 'mo_firebase_auth_kid2', $kid2 );
268 update_option( 'mo_firebase_auth_cert2', $c2 );
269 $c3[0] = str_replace( '\n', '', $c3[0] );
270 update_option( 'mo_firebase_auth_kid3', $kid3 );
271 update_option( 'mo_firebase_auth_cert3', $c3[0] );
272 }
273 } else {
274 if ( is_wp_error( $response ) ) {
275 $error_message = $response->get_error_message();
276 echo 'Something went wrong: ' . esc_attr( $error_message );
277 exit();
278 }
279 }
280 }
281 /**
282 * Handler function
283 *
284 * @param array $errors .
285 * @param string $redirect_to .
286 */
287 public function mo_fb_clear_wp_login_errors( $errors, $redirect_to ) {
288 return new WP_Error();
289 }
290
291 /**
292 * Firebase Authentication Login Handler
293 *
294 * @param WP_User/WP_Error $default_user .
295 * @param string $username .
296 * @param string $password .
297 */
298 public function mo_firebase_auth( $default_user, $username, $password ) {
299
300 if ( 'POST' !== ( isset( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : '' ) ) {
301 add_filter( 'wp_login_errors', array( $this, 'mo_fb_clear_wp_login_errors' ), 0, 2 );
302 return $default_user;
303 }
304
305 if ( empty( $username ) || empty( $password ) ) {
306
307 $error = new WP_Error();
308 // create new error object and add errors to it.
309
310 if ( empty( $username ) ) { // No email.
311 $error->add(
312 'empty_username',
313 wp_kses(
314 '<strong>' . esc_html__( 'ERROR', 'firebase-authentication' ) . '</strong>: ' . esc_html__( 'Email field is empty.', 'firebase-authentication' ),
315 array( 'strong' => array() )
316 )
317 );
318 } elseif ( empty( $password ) ) { // No password.
319 $error->add(
320 'empty_password',
321 wp_kses(
322 '<strong>' . esc_html__( 'ERROR', 'firebase-authentication' ) . '</strong>: ' . esc_html__( 'Password field is empty.', 'firebase-authentication' ),
323 array( 'strong' => array() )
324 )
325 );
326 }
327 return $error;
328 }
329
330 $mo_firebase_config_obj = new Mo_Firebase_Config();
331 $fb_user = $mo_firebase_config_obj->mo_firebase_authenticate_call( $username, $password );
332 $fb_user = json_decode( $fb_user, true );
333
334 if ( isset( $fb_user['idToken'] ) ) {
335 $response = $mo_firebase_config_obj->mo_fb_login_user( $fb_user['idToken'] );
336 } else {
337
338 $error_message = $fb_user['error']['message'];
339
340 if ( 'INVALID_EMAIL' === $error_message || 'EMAIL_NOT_FOUND' === $error_message || 'INVALID_LOGIN_CREDENTIALS' === $error_message ) {
341 if ( '0' === get_option( 'mo_firebase_auth_disable_wordpress_login' ) ) {
342 $user = get_user_by( 'login', $username );
343 if ( ! $user ) {
344 $user = get_user_by( 'email', $username );
345 }
346 if ( $user && wp_check_password( $password, $user->data->user_pass, $user->ID ) ) {
347 return $user;
348 }
349 } elseif ( get_option( 'mo_firebase_auth_enable_admin_wp_login' ) ) {
350 $user = get_user_by( 'login', $username );
351 if ( ! $user ) {
352 $user = get_user_by( 'email', $username );
353 }
354 if ( $user && $this->is_administrator_user( $user ) ) {
355
356 if ( wp_check_password( $password, $user->data->user_pass, $user->ID ) ) {
357 return $user;
358 }
359 }
360 }
361 } else {
362 $error = new WP_Error();
363 if ( 'INVALID_PASSWORD' === $error_message ) {
364 $error_message = 'The password is invalid or the user does not have a password.';
365 }
366 $error_message = wp_kses(
367 '<strong>' . esc_html__( 'ERROR', 'firebase-authentication' ) . '</strong>: ' . esc_html( $error_message ),
368 array( 'strong' => array() )
369 );
370 $error->add( 'firebase_error', $error_message );
371 return $error;
372 }
373 }
374 return $default_user;
375 }
376
377 /**
378 * Admin dashboard messages
379 */
380 public function mo_firebase_auth_success_message() {
381 $message = "<div class='error'><p>" . get_option( 'mo_firebase_auth_message' ) . '</p></div>';
382 $allowed_tags = array(
383 'div' => array(
384 'class' => array(),
385 ),
386 'a' => array(
387 'href' => array(),
388 ),
389 );
390 echo wp_kses( $message, $allowed_tags );
391 }
392
393 /**
394 * Admin dashboard messages
395 */
396 public function mo_firebase_auth_error_message() {
397 $message = "<div class='updated'><p>" . get_option( 'mo_firebase_auth_message' ) . '</p></div>';
398 $allowed_tags = array(
399 'div' => array(
400 'class' => array(),
401 ),
402 'a' => array(
403 'href' => array(),
404 ),
405 );
406 echo wp_kses( $message, $allowed_tags );
407 }
408
409 /**
410 * Check for admin user
411 *
412 * @param WP_User $user .
413 */
414 public function is_administrator_user( $user ) {
415 $user_role = ( $user->roles );
416 if ( ! is_null( $user_role ) && in_array( 'administrator', $user_role, true ) ) {
417 return true;
418 } else {
419 return false;
420 }
421 }
422
423 /**
424 * Admin dashboard messages
425 */
426 private function mo_firebase_auth_show_success_message() {
427 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message' ) );
428 add_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message' ) );
429 }
430 /**
431 * Admin dashboard messages
432 */
433 private function mo_firebase_auth_show_error_message() {
434 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message' ) );
435 add_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message' ) );
436 }
437 /**
438 * Admin dashboard feedback form on deactivation
439 */
440 public function mo_firebase_auth_feedback_request() {
441 mo_firebase_auth_display_feedback_form();
442 }
443
444 /**
445 * Function to check the validations
446 *
447 * @param string $value .
448 */
449 private function mo_firebase_authentication_check_empty_or_null( $value ) {
450 if ( ! isset( $value ) || empty( $value ) ) {
451 return true;
452 }
453 return false;
454 }
455 /**
456 * Function for backend of admin forms such as contact us, feedback, login, etc.
457 */
458 public function mo_firebase_auth_admin_forms_handler() {
459
460 if ( isset( $_POST['option'] ) ) {
461
462 if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_change_email' && isset( $_REQUEST['mo_firebase_authentication_change_email_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_authentication_change_email_form_nonce'] ) ), 'mo_firebase_authentication_change_email_form' ) ) {
463 // Adding back button.
464 update_option( 'mo_firebase_authentication_verify_customer', '' );
465 update_option( 'mo_firebase_authentication_registration_status', '' );
466 update_option( 'mo_firebase_authentication_new_registration', 'true' );
467 }
468
469 if ( 'mo_firebase_authentication_sign_in_option' === sanitize_text_field( wp_unslash( $_POST['option'] ) ) && isset( $_REQUEST['mo_firebase_auth_sign_in_option_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_auth_sign_in_option_field'] ) ), 'mo_firebase_auth_sign_in_option_form' ) ) {
470 if ( current_user_can( 'administrator' ) ) {
471 update_option( 'mo_firebase_allow_unverified_email_login', isset( $_POST['mo_firebase_allow_unverified_email_login'] ) ? 1 : 0 );
472 }
473 }
474
475 if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'change_miniorange' && isset( $_REQUEST['change_miniorange_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['change_miniorange_form_nonce'] ) ), 'change_miniorange_form' ) ) {
476 require_once MO_FIREBASE_AUTHENTICATION_DIR . 'includes' . DIRECTORY_SEPARATOR . 'class-mo-firebase-authentication-deactivator.php';
477 MO_Firebase_Authentication_Deactivator::deactivate();
478 return;
479 }
480
481 if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_register_customer' && isset( $_REQUEST['mo_fb_register_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_fb_register_form_nonce'] ) ), 'mo_fb_register_form' ) ) { // register the admin to miniOrange
482 // validation and sanitization.
483 $email = '';
484 $phone = '';
485 $password = isset( $_POST['password'] ) ? stripslashes( $_POST['password'] ) : ''; //phpcs:ignore -- Ignoring sanitization for password input in case of special characters.
486 $confirm_password = isset( $_POST['confirmPassword'] ) ? stripslashes( $_POST['confirmPassword'] ) : ''; //phpcs:ignore -- Ignoring sanitization for password input in case of special characters.
487 $fname = '';
488 $lname = '';
489 $company = '';
490 if ( ! ( isset( $_POST['email'] ) && isset( $_POST['password'] ) && isset( $_POST['confirmPassword'] ) ) ) {
491 update_option( 'mo_firebase_auth_message', 'All the fields are required. Please enter valid entries.' );
492 $this->mo_firebase_auth_show_error_message();
493 return;
494 } elseif ( strlen( $password ) < 8 || strlen( $confirm_password ) < 8 ) {
495 update_option( 'mo_firebase_auth_message', 'Choose a password with minimum length 8.' );
496 $this->mo_firebase_auth_show_error_message();
497 return;
498 } else {
499 $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
500 $phone = isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : '';
501 $fname = isset( $_POST['fname'] ) ? sanitize_text_field( wp_unslash( $_POST['fname'] ) ) : '';
502 $lname = isset( $_POST['lname'] ) ? sanitize_text_field( wp_unslash( $_POST['lname'] ) ) : '';
503 $company = isset( $_POST['company'] ) ? sanitize_text_field( wp_unslash( $_POST['company'] ) ) : '';
504 }
505
506 update_option( 'mo_firebase_authentication_admin_email', $email );
507 update_option( 'mo_firebase_authentication_admin_phone', $phone );
508 update_option( 'mo_firebase_authentication_admin_fname', $fname );
509 update_option( 'mo_firebase_authentication_admin_lname', $lname );
510 update_option( 'mo_firebase_authentication_admin_company', $company );
511
512 if ( 0 === strcmp( $password, $confirm_password ) ) {
513 update_option( 'password', $password );
514 $customer = new MO_Firebase_Customer();
515 $email = get_option( 'mo_firebase_authentication_admin_email' );
516 $content = json_decode( $customer->check_customer(), true );
517
518 if ( 0 === strcasecmp( $content['status'], 'CUSTOMER_NOT_FOUND' ) ) {
519 $response = json_decode( $customer->create_customer(), true );
520 if ( strcasecmp( $response['status'], 'SUCCESS' ) !== 0 ) {
521 update_option( 'mo_firebase_auth_message', 'Failed to create customer. Try again.' );
522 $this->mo_firebase_auth_show_error_message();
523 } else {
524 update_option( 'mo_firebase_auth_message', 'Your registration is successful. Please login.' );
525 $this->mo_firebase_auth_show_success_message();
526 }
527 } elseif ( 0 === strcasecmp( $content['status'], 'SUCCESS' ) ) {
528 update_option( 'mo_firebase_auth_message', 'Account already exist. Please Login.' );
529 $this->mo_firebase_auth_show_error_message();
530 } else {
531 update_option( 'mo_firebase_auth_message', $content['status'] );
532 $this->mo_firebase_auth_show_success_message();
533 }
534 } else {
535 update_option( 'mo_firebase_auth_message', 'Passwords do not match.' );
536 delete_option( 'mo_firebase_authentication_verify_customer' );
537 $this->mo_firebase_auth_show_error_message();
538 }
539 } if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_goto_login' && isset( $_REQUEST['mo_firebase_authentication_goto_login_form_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_authentication_goto_login_form_field'] ) ), 'mo_firebase_authentication_goto_login_form' ) ) {
540 delete_option( 'mo_firebase_authentication_new_registration' );
541 update_option( 'mo_firebase_authentication_verify_customer', 'true' );
542
543 } if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_enable_firebase_auth' && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_enable_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_enable_field'] ) ) : '' ), 'mo_firebase_auth_enable_form' ) ) {
544 update_option( 'mo_enable_firebase_auth', isset( $_POST['mo_enable_firebase_auth'] ) ? (int) filter_var( wp_unslash( $_POST['mo_enable_firebase_auth'] ), FILTER_SANITIZE_NUMBER_INT ) : 0 );
545
546 } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_auth_contact_us' && isset( $_REQUEST['mo_firebase_auth_contact_us_field'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_contact_us_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_contact_us_field'] ) ) : '' ), 'mo_firebase_auth_contact_us_form' ) ) {
547 $email = isset( $_POST['mo_firebase_auth_contact_us_email'] ) ? sanitize_email( wp_unslash( $_POST['mo_firebase_auth_contact_us_email'] ) ) : '';
548 $phone = isset( $_POST['mo_firebase_auth_contact_us_phone'] ) ? '+ ' . preg_replace( '/[^0-9]/', '', sanitize_text_field( wp_unslash( $_POST['mo_firebase_auth_contact_us_phone'] ) ) ) : '';
549 $query = isset( $_POST['mo_firebase_auth_contact_us_query'] ) ? sanitize_text_field( wp_unslash( $_POST['mo_firebase_auth_contact_us_query'] ) ) : '';
550 if ( $this->mo_firebase_authentication_check_empty_or_null( $email ) || $this->mo_firebase_authentication_check_empty_or_null( $query ) ) {
551 echo '<br><b style=color:red>Please fill up Email and Query fields to submit your query.</b>';
552 } else {
553 $contact_us = new MO_Firebase_contact_us();
554 $submited = $contact_us->mo_firebase_auth_contact_us( $email, $phone, $query );
555 if ( false === $submited ) {
556 update_option( 'mo_firebase_auth_message', 'Your query could not be submitted. Please try again.' );
557 $this->mo_firebase_auth_show_error_message();
558 } else {
559 update_option( 'mo_firebase_auth_message', 'Thanks for getting in touch! We shall get back to you shortly.' );
560 $this->mo_firebase_auth_show_success_message();
561 }
562 }
563 } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_verify_customer' && isset( $_REQUEST['mo_fb_login_form_nonce'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_fb_login_form_nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_fb_login_form_nonce'] ) ) : '' ), 'mo_fb_login_form' ) ) {// register the admin to miniOrange
564 // validation and sanitization.
565 $email = '';
566 $password = '';
567 if ( ! ( isset( $_POST['email'] ) && isset( $_POST['password'] ) ) ) {
568 update_option( 'mo_firebase_auth_message', 'All the fields are required. Please enter valid entries.' );
569 $this->mo_firebase_auth_show_error_message();
570 return;
571 } else {
572 $email = sanitize_email( wp_unslash( $_POST['email'] ) );
573 $password = stripslashes( wp_unslash( $_POST['password'] ) ); //phpcs:ignore -- Ignoring sanitization for password input in case of special characters.
574 }
575
576 update_option( 'mo_firebase_authentication_admin_email', $email );
577 update_option( 'password', $password );
578 $customer = new MO_Firebase_Customer();
579 $content = $customer->mo_firebase_auth_get_customer_key();
580 $customer_key = json_decode( $content, true );
581 if ( json_last_error() === JSON_ERROR_NONE ) {
582 update_option( 'mo_firebase_authentication_admin_customer_key', $customer_key['id'] );
583 update_option( 'mo_firebase_authentication_admin_api_key', $customer_key['apiKey'] );
584 update_option( 'mo_firebase_authentication_customer_token', $customer_key['token'] );
585 if ( isset( $customer_key['phone'] ) ) {
586 update_option( 'mo_firebase_authentication_admin_phone', $customer_key['phone'] );
587 }
588 delete_option( 'password' );
589 update_option( 'mo_firebase_auth_message', 'Customer retrieved successfully' );
590 delete_option( 'mo_firebase_authentication_verify_customer' );
591 $this->mo_firebase_auth_show_success_message();
592 } else {
593 update_option( 'mo_firebase_auth_message', 'Invalid username or password. Please try again.' );
594 $this->mo_firebase_auth_show_error_message();
595 }
596 } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_auth_skip_feedback' && isset( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'] ) ) : '' ), 'mo_firebase_auth_skip_feedback_form' ) ) {
597 deactivate_plugins( __FILE__ );
598 update_option( 'mo_firebase_auth_message', 'Plugin deactivated successfully' );
599 $this->mo_firebase_auth_show_success_message();
600
601 } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_auth_feedback' && isset( $_REQUEST['mo_firebase_auth_feedback_field'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_feedback_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_feedback_field'] ) ) : '' ), 'mo_firebase_auth_feedback_form' ) ) {
602 $user = wp_get_current_user();
603 $message = 'Plugin Deactivated:';
604 $deactivate_reason = array_key_exists( 'deactivate_reason_radio', $_POST ) ? sanitize_text_field( wp_unslash( $_POST['deactivate_reason_radio'] ) ) : false;
605 $deactivate_reason_message = array_key_exists( 'query_feedback', $_POST ) ? sanitize_text_field( wp_unslash( $_POST['query_feedback'] ) ) : false;
606 if ( $deactivate_reason ) {
607 $message .= $deactivate_reason;
608 if ( isset( $deactivate_reason_message ) ) {
609 $message .= ':' . $deactivate_reason_message;
610 }
611
612 $email = $user->user_email;
613 $contact_us = new MO_Firebase_contact_us();
614 $response = $contact_us->mo_firebase_auth_send_email_alert( $email, $message, 'Feedback: WordPress Firebase Authentication' );
615 if ( ! is_null( $response ) ) {
616 $submited = json_decode( $response, true );
617 }
618 deactivate_plugins( __FILE__ );
619 update_option( 'mo_firebase_auth_message', 'Thank you for the feedback.' );
620 $this->mo_firebase_auth_show_success_message();
621
622 } else {
623 update_option( 'mo_firebase_auth_message', 'Please Select one of the reasons ,if your reason is not mentioned please select Other Reasons' );
624 $this->mo_firebase_auth_show_error_message();
625 }
626 } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_fb_demo_request_form' && isset( $_REQUEST['mo_fb_demo_request_field'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_fb_demo_request_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_fb_demo_request_field'] ) ) : '' ), 'mo_fb_demo_request_form' ) ) {
627
628 if ( current_user_can( 'administrator' ) ) {
629 $email = isset( $_POST['mo_auto_create_demosite_email'] ) ? sanitize_email( wp_unslash( $_POST['mo_auto_create_demosite_email'] ) ) : '';
630 $firestore_check = isset( $_POST['mo_auto_create_demosite_firestore_integrator_check'] ) ? sanitize_text_field( wp_unslash( $_POST['mo_auto_create_demosite_firestore_integrator_check'] ) ) : '';
631 $query = isset( $_POST['mo_auto_create_demosite_usecase'] ) ? sanitize_text_field( wp_unslash( $_POST['mo_auto_create_demosite_usecase'] ) ) : '';
632
633 if ( $this->mo_firebase_authentication_check_empty_or_null( $email ) || $this->mo_firebase_authentication_check_empty_or_null( $query ) ) {
634 update_option( 'message', 'Please fill up Usecase, Email field to submit your query.' );
635 $$this->mo_firebase_auth_show_error_message();
636 } else {
637 global $wp_version;
638 $mo_firebase_sandbox_usecase_with_addons = 'Usecase: ' . PHP_EOL .
639 $query .
640 PHP_EOL .
641 ' ' .
642 'Firestore Integrator: ' . PHP_EOL . $firestore_check;
643 $wp_version_trim = substr( $wp_version, 0, 3 );
644 $mo_oauth_sandbox_href = 'https://sandbox.miniorange.com/?email=' . rawurlencode( $email ) . '&mo_plugin=mo_firebase_authentication&wordpress_version=' . rawurlencode( $wp_version_trim ) . '&usecase=' . rawurlencode( $mo_firebase_sandbox_usecase_with_addons ) . '&referer=' . rawurlencode( get_site_url() );
645 echo '<script type="text/javascript">
646 window.open("' . esc_url_raw( $mo_oauth_sandbox_href ) . '", "_blank");
647 </script>';
648 }
649 }
650 }
651 }
652 }
653
654 }
655
656 $mo_firebase_authentication_obj = new Miniorange_Firebase_Authentication();
657