PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.2
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.2
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Templates / Login.php

Login.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.2, at includes/Templates/Login.php

104 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Login template
4 * NOTE: This is the modal login template, ie: JWT expired, not the web login
5 *
6 * @package WooCommercePOS
7 */
8
9 namespace WCPOS\WooCommercePOS\Templates;
10
11 use WCPOS\WooCommercePOS\Services\Auth;
12 use WP_User;
13
14 /**
15 * Login template
16 */
17 class Login {
18 /**
19 * Constructor.
20 */
21 public function __construct() {
22 remove_action( 'login_init', 'send_frame_options_header', 10 );
23 }
24
25 /**
26 * Get the login template.
27 *
28 * @return void
29 */
30 public function get_template(): void {
31 $login_attempt = isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce_pos_login' );
32
33 // Login attempt detected.
34 $error_string = '';
35 if ( $login_attempt ) {
36 $creds = array();
37 $creds['user_login'] = isset( $_POST['log'] ) ? sanitize_text_field( wp_unslash( $_POST['log'] ) ) : '';
38 $creds['user_password'] = isset( $_POST['pwd'] ) ? wp_unslash( $_POST['pwd'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Passwords must not be sanitized as it can strip valid characters.
39 // $creds['remember'] = isset( $_POST['rememberme'] );
40
41 $user = wp_signon( $creds, false );
42
43 if ( is_wp_error( $user ) ) {
44 foreach ( $user->errors as $error ) {
45 $error_string .= '<p class="error">' . $error[0] . '</p>';
46 }
47 } else {
48 wp_set_current_user( $user->ID );
49 $this->login_success( $user );
50 exit;
51 }
52 }
53
54 do_action( 'woocommerce_pos_login_init' );
55
56 do_action( 'woocommerce_pos_login_form_login' );
57
58 include woocommerce_pos_locate_template( 'login.php' );
59 exit;
60 }
61
62 /**
63 * Login success
64 *
65 * @param WP_User $user The authenticated user.
66 *
67 * @return void
68 */
69 private function login_success( WP_User $user ) {
70 $auth_service = Auth::instance();
71 $user_data = $auth_service->get_user_data( $user );
72 $stores = array_map(
73 function ( $store ) {
74 return $store->get_data();
75 },
76 wcpos_get_stores()
77 );
78 $user_data['stores'] = $stores;
79 $credentials = wp_json_encode( $user_data );
80
81 echo '<script>
82 (function() {
83 var credentials = ' . wp_json_encode( $user_data ) . "
84
85 // Check if postMessage function exists for window.top
86 if (typeof window.top.postMessage === 'function') {
87 window.top.postMessage({
88 action: 'wcpos-wp-credentials',
89 payload: credentials
90 }, '*');
91 }
92
93 // Check if ReactNativeWebView object and postMessage function exists
94 if (typeof window.ReactNativeWebView !== 'undefined' && typeof window.ReactNativeWebView.postMessage === 'function') {
95 window.ReactNativeWebView.postMessage(JSON.stringify({
96 action: 'wcpos-wp-credentials',
97 payload: credentials
98 }));
99 }
100 })();
101 </script>" . "\n";
102 }
103 }
104