PluginProbe ʕ •ᴥ•ʔ
Firebase Authentication / 1.5.9
Firebase Authentication v1.5.9
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 years ago includes 3 years ago languages 3 years ago public 3 years ago views 3 years ago README.txt 3 years ago class-contact-us.php 3 years ago class-mo-firebase-config.php 3 years ago firebase-authentication.php 3 years ago index.php 3 years ago uninstall.php 3 years ago
firebase-authentication.php
564 lines
1 <?php
2 /**
3 *
4 * @link https://miniorange.com
5 * @since 1.0.0
6 * @package Firebase_Authentication
7 *
8 * @wordpress-plugin
9 * Plugin Name: Firebase Authentication
10 * Plugin URI: firebase-authentication
11 * Description: This plugin allows login into Wordpress using Firebase as Identity provider.
12 * Version: 1.5.9
13 * Author: miniOrange
14 * Author URI: https://miniorange.com
15 * License: MIT/Expat
16 */
17
18
19 // If this file is called directly, abort.
20 if ( ! defined( 'WPINC' ) ) {
21 die;
22 }
23
24 /**
25 * Currently plugin version.
26 * Start at version 1.0.0 and use SemVer - https://semver.org
27 * Rename this for your plugin and update it as you release new versions.
28 */
29 define( 'MO_FIREBASE_AUTHENTICATION_VERSION', '1.5.9' );
30
31 /**
32 * The code that runs during plugin activation.
33 * This action is documented in includes/class-firebase-authentication-activator.php
34 */
35 function mo_firebase_activate_firebase_authentication() {
36 require_once plugin_dir_path( __FILE__ ) . 'includes/class-firebase-authentication-activator.php';
37 MO_Firebase_Authentication_Activator::activate();
38 }
39
40 /**
41 * The code that runs during plugin deactivation.
42 * This action is documented in includes/class-firebase-authentication-deactivator.php
43 */
44 function mo_firebase_deactivate_firebase_authentication() {
45 require_once plugin_dir_path( __FILE__ ) . 'includes/class-firebase-authentication-deactivator.php';
46 MO_Firebase_Authentication_Deactivator::deactivate();
47 }
48
49 register_activation_hook( __FILE__, 'mo_firebase_activate_firebase_authentication' );
50 register_deactivation_hook( __FILE__, 'mo_firebase_deactivate_firebase_authentication' );
51
52 /**
53 * The core plugin class that is used to define internationalization,
54 * admin-specific hooks, and public-facing site hooks.
55 */
56 require plugin_dir_path( __FILE__ ) . 'includes/class-firebase-authentication.php';
57 require_once 'class-mo-firebase-config.php';
58 require('views/feedback_form.php');
59 require('class-contact-us.php');
60 require('admin/class-firebase-authentication-customer.php');
61
62
63 /**
64 * Begins execution of the plugin.
65 *
66 * Since everything within the plugin is registered via hooks,
67 * then kicking off the plugin from this point in the file does
68 * not affect the page life cycle.
69 *
70 * @since 1.0.0
71 */
72 function mo_firebase_run_firebase_authentication() {
73
74 $plugin = new MO_Firebase_Authentication();
75 $plugin->run();
76
77 }
78 mo_firebase_run_firebase_authentication();
79
80 function mo_firebase_authentication_is_customer_registered() {
81 $email = get_option('mo_firebase_authentication_admin_email');
82 // $phone = get_option('mo_firebase_authentication_admin_phone');
83 $customerKey = get_option('mo_firebase_authentication_admin_customer_key');
84 // if( ! $email || ! $phone || ! $customerKey || ! is_numeric( trim( $customerKey ) ) ) {
85 if( ! $email || ! $customerKey || ! is_numeric( trim( $customerKey ) ) ) {
86
87 return 0;
88 } else {
89 return 1;
90 }
91 }
92 function mo_firebase_authentication_is_clv() {
93 $licenseKey = get_option('mo_firebase_authentication_lk');
94 $isverified = get_option('mo_firebase_authentication_lv');
95 if($isverified)
96 $isverified = mo_firebase_authentication_decrypt($isverified);
97
98 if(!empty($licenseKey) && $isverified=="true") {
99 return 1;
100 }
101 return 0;
102 }
103
104 function mo_firebase_authentication_encrypt($str){
105 $pass = get_option("mo_firebase_authentication_customer_token");
106 $pass = str_split(str_pad('', strlen($str), $pass, STR_PAD_RIGHT));
107 $stra = str_split($str);
108 foreach($stra as $k=>$v){
109 $tmp = ord($v)+ord($pass[$k]);
110 $stra[$k] = chr( $tmp > 255 ?($tmp-256):$tmp);
111 }
112 return base64_encode(join('', $stra));
113 }
114
115 function mo_firebase_authentication_decrypt($str){
116 $str = base64_decode($str);
117 $pass = get_option("mo_firebase_authentication_customer_token");
118 $pass = str_split(str_pad('', strlen($str), $pass, STR_PAD_RIGHT));
119 $stra = str_split($str);
120 foreach($stra as $k=>$v){
121 $tmp = ord($v)-ord($pass[$k]);
122 $stra[$k] = chr( $tmp < 0 ?($tmp+256):$tmp);
123 }
124 return join('', $stra);
125 }
126
127
128 class mo_firebase_authentication_login {
129 function __construct() {
130 add_action( 'init', array( $this, 'postResgiter' ) );
131 add_action( 'admin_init', array( $this, 'mo_firebase_auth_deactivate' ) );
132 if ( get_option( 'mo_enable_firebase_auth' ) == 1 ) {
133 if ( strpos( $_SERVER['REQUEST_URI'], '/wp-json' ) === false ) {
134 remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
135 remove_filter( 'authenticate', 'wp_authenticate_email_password', 20, 3 );
136 add_filter( 'authenticate', array( $this, 'mo_firebase_auth' ), 0, 3 );
137 }
138 }
139 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message') );
140 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message') );
141 add_action( 'admin_footer', array( $this, 'mo_firebase_auth_feedback_request' ) );
142 update_option( 'host_name', 'https://login.xecurify.com' );
143 }
144
145 function postResgiter() {
146 if ( isset( $_POST['verify_user'] ) && isset( $_REQUEST['page'] ) && sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) == 'mo_firebase_authentication' && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_auth_config_field'] ) ), 'mo_firebase_auth_config_form' ) ) {
147
148 if( current_user_can( 'administrator' ) ) {
149 update_option( 'mo_firebase_auth_disable_wordpress_login', isset( $_POST['disable_wordpress_login'] ) ? (int)filter_var( $_POST['disable_wordpress_login'], FILTER_SANITIZE_NUMBER_INT ) : 0 );
150
151 update_option('mo_firebase_auth_enable_admin_wp_login', isset($_POST['mo_firebase_auth_enable_admin_wp_login']) ? $_POST['mo_firebase_auth_enable_admin_wp_login'] : 0);
152
153 $project_id = isset( $_POST['projectid'] ) ? sanitize_text_field( $_POST['projectid'] ) : '';
154 update_option( 'mo_firebase_auth_project_id', $project_id );
155
156 $api_key = isset( $_POST['apikey'] ) ? sanitize_text_field( $_POST['apikey'] ) : '';
157 update_option( 'mo_firebase_auth_api_key', $api_key );
158
159 $this->mo_firebase_auth_store_certificates();
160 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.');
161 $this->mo_firebase_auth_show_success_message();
162 }
163 }
164 }
165
166 function mo_firebase_auth_store_certificates(){
167 $response = wp_remote_get( 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com' );
168 if ( is_array( $response ) ) {
169 $header = $response['headers']; // array of http header lines
170 $body = $response['body']; // use the content
171
172 $split_result = explode( ":", $body );
173 $count = count( $split_result );
174 $kid1 = substr( $split_result[0], 5, 40 );
175 $s = explode( ",", $split_result[1] );
176 $c1 = substr( $s[0], 2, 1158 );
177 $c1 = str_replace( '\n', '', $c1 );
178 update_option( 'mo_firebase_auth_kid1', $kid1 );
179 update_option( 'mo_firebase_auth_cert1', $c1 );
180 if( $count == 3 ) {
181 $kid2 = substr( $s[1], 4, 40 );
182 $c2 = explode( "}", $split_result[2] );
183 $c2[0] = substr( $c2[0], 2, 1158 );
184 $c2[0] = str_replace( '\n', '', $c2[0] );
185 update_option( 'mo_firebase_auth_kid2', $kid2 );
186 update_option( 'mo_firebase_auth_cert2', $c2[0] );
187 } elseif ( $count > 3) {
188 $kid2 = substr( $s[1], 4, 40 );
189 $s2 = explode( ",", $split_result[2] );
190 $c2 = substr( $s2[0], 2, 1158 );
191 $kid3 = substr( $s2[1], 4, 40 );
192 $c3 = explode( "}", $split_result[3] );
193 $c3[0] = substr( $c3[0], 2, 1158 );
194 $c2 = str_replace( '\n', '', $c2 );
195 update_option( 'mo_firebase_auth_kid2', $kid2 );
196 update_option( 'mo_firebase_auth_cert2', $c2 );
197 $c3[0] = str_replace( '\n', '', $c3[0] );
198 update_option( 'mo_firebase_auth_kid3', $kid3 );
199 update_option( 'mo_firebase_auth_cert3', $c3[0] );
200 }
201 } else {
202 if ( is_wp_error( $response ) ) {
203 $error_message = $response->get_error_message();
204 echo "Something went wrong: ".esc_attr($error_message);
205 exit();
206 }
207 }
208 }
209
210 function mo_fb_clear_wp_login_errors($errors, $redirect_to){
211 return new WP_Error();
212 }
213
214
215 function mo_firebase_auth( $default_user, $username, $password ) {
216
217 if( "POST" !== sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ) {
218 add_filter( 'wp_login_errors', array( $this, 'mo_fb_clear_wp_login_errors' ), 0, 2 );
219 return $default_user;
220 }
221
222 if ( empty( $username ) || empty ( $password ) ) {
223
224 $error = new WP_Error();
225 //create new error object and add errors to it.
226
227 if ( empty( $username ) ) { //No email
228 $error->add( 'empty_username', __( '<strong>ERROR</strong>: Email field is empty.' ) );
229 }
230
231 else if ( empty( $password ) ) { //No password
232 $error->add( 'empty_password', __( '<strong>ERROR</strong>: Password field is empty.' ) );
233 }
234 return $error;
235 }
236
237 $mo_firebase_config_obj = new Mo_Firebase_Config();
238 $fb_user = $mo_firebase_config_obj->mo_firebase_authenticate_call($username, $password);
239 $fb_user = json_decode($fb_user, true);
240
241 if(isset($fb_user['idToken'])){
242 $response = $mo_firebase_config_obj->mo_fb_login_user($fb_user['idToken']);
243 }
244 else{
245
246 $error_message = $fb_user['error']['message'];
247 if($error_message == 'INVALID_EMAIL' || $error_message == 'EMAIL_NOT_FOUND'){
248 if ( get_option( 'mo_firebase_auth_disable_wordpress_login' ) == false ) {
249 $user = get_user_by( "login", $username );
250 if ( !$user ) {
251 $user = get_user_by( "email", $username );
252 }
253 if ( $user && wp_check_password( $password, $user->data->user_pass, $user->ID ) ) {
254 return $user;
255 }
256 }
257 else if ( get_option( 'mo_firebase_auth_enable_admin_wp_login' ) ) {
258 $user = get_user_by( "login", $username );
259 if ( !$user ) {
260 $user = get_user_by( "email", $username );
261 }
262 if ( $user && $this->is_administrator_user( $user ) ) {
263
264 if ( wp_check_password( $password, $user->data->user_pass, $user->ID ) ) {
265 return $user;
266 }
267 }
268 }
269 }else{
270 $error = new WP_Error();
271 if($error_message == 'INVALID_PASSWORD'){
272 $error_message = 'The password is invalid or the user does not have a password.';
273 }
274 $error->add('firebase_error', __( '<strong>ERROR</strong>: '.$error_message ));
275 return $error;
276 }
277 }
278 return $default_user;
279 }
280
281 function mo_firebase_auth_success_message() {
282 $message = "<div class='error'><p>" . get_option('mo_firebase_auth_message') . "</p></div>";
283 $allowed_tags = array(
284 'div' => array(
285 'class' => array(),
286 ),
287 'a' => array(
288 'href' => array()
289 )
290 );
291 echo wp_kses($message, $allowed_tags);
292 }
293
294 function mo_firebase_auth_error_message() {
295 $message = "<div class='updated'><p>" . get_option('mo_firebase_auth_message') . "</p></div>";
296 $allowed_tags = array(
297 'div' => array(
298 'class' => array(),
299 ),
300 'a' => array(
301 'href' => array()
302 )
303 );
304 echo wp_kses($message, $allowed_tags);
305 }
306
307 function is_administrator_user( $user ) {
308 $userRole = ( $user->roles );
309 if ( ! is_null( $userRole ) && in_array( 'administrator' , $userRole ) ) {
310 return true;
311 }
312 else {
313 return false;
314 }
315 }
316
317 private function mo_firebase_auth_show_success_message() {
318 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message') );
319 add_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message') );
320 }
321
322 private function mo_firebase_auth_show_error_message() {
323 remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message') );
324 add_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message') );
325 }
326
327 function mo_firebase_auth_feedback_request() {
328 mo_firebase_auth_display_feedback_form();
329 }
330
331 private function mo_firebase_authentication_check_empty_or_null( $value ) {
332 if( ! isset( $value ) || empty( $value ) ) {
333 return true;
334 }
335 return false;
336 }
337
338 function mo_firebase_auth_deactivate(){
339
340 if ( isset( $_POST['option'] ) ) {
341
342 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' ) ) {
343 //Adding back button
344 update_option('mo_firebase_authentication_verify_customer', '');
345 update_option('mo_firebase_authentication_registration_status','');
346 update_option('mo_firebase_authentication_new_registration','true');
347 }
348
349 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' ) ) {
350 require_once plugin_dir_path( __FILE__ ) . 'includes/class-firebase-authentication-deactivator.php';
351 MO_Firebase_Authentication_Deactivator::deactivate();
352 return;
353 }
354
355 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
356 //validation and sanitization
357 $email = '';
358 $phone = '';
359 $password = '';
360 $confirmPassword = '';
361 $fname = '';
362 $lname = '';
363 $company = '';
364 if ( $this->mo_firebase_authentication_check_empty_or_null( $_POST['email'] ) || $this->mo_firebase_authentication_check_empty_or_null( $_POST['password'] ) || $this->mo_firebase_authentication_check_empty_or_null( $_POST['confirmPassword'] ) ) {
365 update_option( 'mo_firebase_auth_message', 'All the fields are required. Please enter valid entries.');
366 $this->mo_firebase_auth_show_error_message();
367 return;
368 } else if ( strlen( $_POST['password'] ) < 8 || strlen( $_POST['confirmPassword'] ) < 8) {
369 update_option( 'mo_firebase_auth_message', 'Choose a password with minimum length 8.');
370 $this->mo_firebase_auth_show_error_message();
371 return;
372 } else {
373 $email = sanitize_email( $_POST['email'] );
374 $phone = stripslashes( $_POST['phone'] );
375 $password = stripslashes( $_POST['password'] );
376 $confirmPassword = stripslashes( $_POST['confirmPassword'] );
377 $fname = stripslashes( $_POST['fname'] );
378 $lname = stripslashes( $_POST['lname' ] );
379 $company = stripslashes( $_POST['company'] );
380 }
381
382 update_option( 'mo_firebase_authentication_admin_email', $email );
383 update_option( 'mo_firebase_authentication_admin_phone', $phone );
384 update_option( 'mo_firebase_authentication_admin_fname', $fname );
385 update_option( 'mo_firebase_authentication_admin_lname', $lname );
386 update_option( 'mo_firebase_authentication_admin_company', $company );
387
388 if ( strcmp( $password, $confirmPassword) == 0 ) {
389 update_option( 'password', $password );
390 $customer = new MO_Firebase_Customer();
391 $email = get_option('mo_firebase_authentication_admin_email');
392 $content = json_decode( $customer->check_customer(), true );
393
394 if ( strcasecmp( $content['status'], 'CUSTOMER_NOT_FOUND') == 0 ) {
395 $response = json_decode( $customer->create_customer(), true );
396 if ( strcasecmp( $response['status'], 'SUCCESS' ) != 0 ) {
397 update_option( 'mo_firebase_auth_message', 'Failed to create customer. Try again.' );
398 $this->mo_firebase_auth_show_error_message();
399 }else{
400 update_option( 'mo_firebase_auth_message', 'Your registration is successful. Please login.' );
401 $this->mo_firebase_auth_show_success_message();
402 }
403
404 } elseif ( strcasecmp( $content['status'], 'SUCCESS' ) == 0 ) {
405 update_option( 'mo_firebase_auth_message', 'Account already exist. Please Login.' );
406 $this->mo_firebase_auth_show_error_message();
407 } else {
408 update_option( 'mo_firebase_auth_message', $content['status'] );
409 $this->mo_firebase_auth_show_success_message();
410 }
411
412
413 } else {
414 update_option( 'mo_firebase_auth_message', 'Passwords do not match.');
415 delete_option('mo_firebase_authentication_verify_customer');
416 $this->mo_firebase_auth_show_error_message();
417 }
418
419 } 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' )) {
420 delete_option( 'mo_firebase_authentication_new_registration' );
421 update_option( 'mo_firebase_authentication_verify_customer', 'true' );
422
423 } if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_enable_firebase_auth' && wp_verify_nonce( $_REQUEST['mo_firebase_auth_enable_field'], 'mo_firebase_auth_enable_form' ) ){
424 update_option( 'mo_enable_firebase_auth', isset( $_POST['mo_enable_firebase_auth'] ) ? (int)filter_var( $_POST['mo_enable_firebase_auth'], FILTER_SANITIZE_NUMBER_INT ) : 0 );
425
426 } else if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_firebase_auth_contact_us' && isset($_REQUEST['mo_firebase_auth_contact_us_field']) && wp_verify_nonce( $_REQUEST['mo_firebase_auth_contact_us_field'], 'mo_firebase_auth_contact_us_form' ) ) {
427 $email = isset( $_POST['mo_firebase_auth_contact_us_email'] ) ? sanitize_email( $_POST['mo_firebase_auth_contact_us_email'] ) : "";
428 $phone = isset( $_POST['mo_firebase_auth_contact_us_phone'] ) ? "+ ".preg_replace( '/[^0-9]/', '', $_POST['mo_firebase_auth_contact_us_phone'] ) : "";
429 //$phone = sanitize_textarea_field($_POST['mo_firebase_auth_contact_us_phone']);
430 $query = isset( $_POST['mo_firebase_auth_contact_us_query'] ) ? sanitize_textarea_field( $_POST['mo_firebase_auth_contact_us_query'] ) : "";
431 if ( $this->mo_firebase_authentication_check_empty_or_null( $email ) || $this->mo_firebase_authentication_check_empty_or_null( $query ) ) {
432 echo '<br><b style=color:red>Please fill up Email and Query fields to submit your query.</b>';
433 } else {
434 $contact_us = new MO_Firebase_contact_us();
435 $submited = $contact_us->mo_firebase_auth_contact_us( $email, $phone, $query );
436 if ( $submited == false ) {
437 update_option( 'mo_firebase_auth_message', 'Your query could not be submitted. Please try again.' );
438 $this->mo_firebase_auth_show_error_message();
439 } else {
440 update_option( 'mo_firebase_auth_message', 'Thanks for getting in touch! We shall get back to you shortly.' );
441 $this->mo_firebase_auth_show_success_message();
442 }
443 }
444
445 } else if( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == "mo_firebase_authentication_verify_customer" && isset($_REQUEST['mo_fb_login_form_nonce']) && wp_verify_nonce( $_REQUEST['mo_fb_login_form_nonce'], 'mo_fb_login_form')) {//register the admin to miniOrange
446 //validation and sanitization
447 $email = '';
448 $password = '';
449 if( $this->mo_firebase_authentication_check_empty_or_null( $_POST['email'] ) || $this->mo_firebase_authentication_check_empty_or_null( $_POST['password'] ) ) {
450 update_option( 'mo_firebase_auth_message', 'All the fields are required. Please enter valid entries.');
451 $this->mo_firebase_auth_show_error_message();
452 return;
453 } else{
454 $email = sanitize_email( $_POST['email'] );
455 $password = stripslashes( $_POST['password'] );
456 }
457
458 update_option( 'mo_firebase_authentication_admin_email', $email );
459 update_option( 'password', $password );
460 $customer = new MO_Firebase_Customer();
461 $content = $customer->mo_firebase_auth_get_customer_key();
462 $customerKey = json_decode( $content, true );
463 if( json_last_error() == JSON_ERROR_NONE ) {
464 update_option( 'mo_firebase_authentication_admin_customer_key', $customerKey['id'] );
465 update_option( 'mo_firebase_authentication_admin_api_key', $customerKey['apiKey'] );
466 update_option( 'mo_firebase_authentication_customer_token', $customerKey['token'] );
467 if( isset( $customerKey['phone'] ) )
468 update_option( 'mo_firebase_authentication_admin_phone', $customerKey['phone'] );
469 delete_option( 'password' );
470 update_option( 'mo_firebase_auth_message', 'Customer retrieved successfully');
471 delete_option( 'mo_firebase_authentication_verify_customer' );
472 $this->mo_firebase_auth_show_success_message();
473 } else {
474 update_option( 'mo_firebase_auth_message', 'Invalid username or password. Please try again.');
475 $this->mo_firebase_auth_show_error_message();
476 }
477
478 } else if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_firebase_auth_skip_feedback' && isset($_REQUEST['mo_firebase_auth_skip_feedback_form_nonce']) && wp_verify_nonce( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'], 'mo_firebase_auth_skip_feedback_form' ) ) {
479 deactivate_plugins( __FILE__ );
480 update_option( 'mo_firebase_auth_message', 'Plugin deactivated successfully' );
481 $this->mo_firebase_auth_show_success_message();
482
483 } else if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_firebase_auth_feedback' && isset($_REQUEST['mo_firebase_auth_feedback_field']) && wp_verify_nonce( $_REQUEST['mo_firebase_auth_feedback_field'], 'mo_firebase_auth_feedback_form' ) ) {
484 $user = wp_get_current_user();
485 $message = 'Plugin Deactivated:';
486 $deactivate_reason = array_key_exists( 'deactivate_reason_radio', $_POST ) ? $_POST['deactivate_reason_radio'] : false;
487 $deactivate_reason_message = array_key_exists( 'query_feedback', $_POST ) ? $_POST['query_feedback'] : false;
488 if ( $deactivate_reason ) {
489 $message .= $deactivate_reason;
490 if ( isset( $deactivate_reason_message ) ) {
491 $message .= ':' . $deactivate_reason_message;
492 }
493
494 $email = $user->user_email;
495 $contact_us = new MO_Firebase_contact_us();
496 $submited = json_decode( $contact_us->mo_firebase_auth_send_email_alert( $email, $message, "Feedback: WordPress Firebase Authentication" ), true );
497 deactivate_plugins( __FILE__ );
498 update_option( 'mo_firebase_auth_message', 'Thank you for the feedback.' );
499 $this->mo_firebase_auth_show_success_message();
500
501 } else {
502 update_option( 'mo_firebase_auth_message', 'Please Select one of the reasons ,if your reason is not mentioned please select Other Reasons' );
503 $this->mo_firebase_auth_show_error_message();
504 }
505 } else if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_fb_demo_request_form' && isset($_REQUEST['mo_fb_demo_request_field']) && wp_verify_nonce( $_REQUEST['mo_fb_demo_request_field'], 'mo_fb_demo_request_form' ) ) {
506
507 if( current_user_can( 'administrator' ) ){
508 $email = $_POST['mo_auto_create_demosite_email'];
509 $demo_plan = isset($_POST['mo_auto_create_demosite_demo_plan']) ? stripslashes( $_POST['mo_auto_create_demosite_demo_plan']): ' ';
510 $query = $_POST['mo_auto_create_demosite_usecase'];
511
512 if( $this->mo_firebase_authentication_check_empty_or_null( $email ) || $this->mo_firebase_authentication_check_empty_or_null( $demo_plan ) || $this->mo_firebase_authentication_check_empty_or_null( $query ) ){
513 update_option('message', 'Please fill up Usecase, Email field and Requested demo plan to submit your query.');
514 $$this->mo_firebase_auth_show_error_message();
515 }
516 else {
517 $url = 'https://demo.miniorange.com/wpoauthsso/';
518
519 $headers = array( 'Content-Type' => 'application/x-www-form-urlencoded', 'charset' => 'UTF - 8');
520 $args = array(
521 'method' =>'POST',
522 'body' => array(
523 'option' => 'mo_auto_create_demosite',
524 'mo_auto_create_demosite_email' => $email,
525 'mo_auto_create_demosite_usecase' => $query,
526 'mo_auto_create_demosite_demo_plan' => $demo_plan
527 ),
528 'timeout' => '20',
529 'redirection' => '5',
530 'httpversion' => '1.0',
531 'blocking' => true,
532 'headers' => $headers,
533 );
534
535 $response = wp_remote_post( $url, $args );
536 if ( is_wp_error( $response ) ) {
537 $error_message = $response->get_error_message();
538
539 echo "Something went wrong: ".esc_attr($error_message);
540 exit();
541 }
542 $output = wp_remote_retrieve_body($response);
543 $output = json_decode($output);
544 if(is_null($output)){
545 update_option('mo_firebase_auth_message', $output->message);
546 $this->mo_firebase_auth_show_success_message();
547 }
548 if($output->status == 'SUCCESS'){
549 update_option( 'mo_firebase_auth_message', $output->message);
550 $this->mo_firebase_auth_show_success_message();
551 }else{
552 update_option( 'mo_firebase_auth_message', $output->message );
553 $this->mo_firebase_auth_show_error_message();
554 }
555 }
556
557 }
558 }
559 }
560 }
561
562 }
563
564 $mo_firebase_authentication_obj = new mo_firebase_authentication_login();