-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
264 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace WCPOS\WooCommercePOS\Templates; | ||
|
||
use WCPOS\WooCommercePOS\Services\Auth; | ||
|
||
class Login { | ||
/** | ||
* | ||
*/ | ||
protected $auth_service; | ||
|
||
|
||
public function __construct() { | ||
$this->auth_service = new Auth(); | ||
$this->send_headers(); | ||
} | ||
|
||
/** | ||
* Send headers | ||
* | ||
* @return void | ||
*/ | ||
private function send_headers() { | ||
header( 'Content-Security-Policy: frame-ancestors http://localhost:* https://localhost:*' ); | ||
} | ||
|
||
|
||
public function get_template(): void { | ||
$login_attempt = isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce_pos_login' ); | ||
|
||
// Login attempt detected | ||
$error_string = ''; | ||
if ( $login_attempt ) { | ||
$creds = array(); | ||
$creds['user_login'] = $_POST['log']; | ||
$creds['user_password'] = $_POST['pwd']; | ||
// $creds['remember'] = isset( $_POST['rememberme'] ); | ||
|
||
$user = wp_signon( $creds, false ); | ||
|
||
if ( is_wp_error( $user ) ) { | ||
foreach ( $user->errors as $error ) { | ||
$error_string .= '<p class="error">' . $error[0] . '</p>'; | ||
} | ||
} else { | ||
$this->login_success(); | ||
exit; | ||
} | ||
} | ||
|
||
// | ||
do_action( 'login_init' ); | ||
|
||
// | ||
do_action( 'login_form_login' ); | ||
|
||
include woocommerce_pos_locate_template( 'login.php' ); | ||
exit; | ||
} | ||
|
||
/** | ||
* Login success | ||
* | ||
* @return void | ||
*/ | ||
private function login_success() { | ||
$user = wp_get_current_user(); | ||
$user_data = $this->auth_service->get_user_data( $user ); | ||
$credentials = wp_json_encode( $user_data ); | ||
|
||
echo '<script> | ||
(function() { | ||
// Parse the order JSON from PHP | ||
var credentials = ' . $credentials . " | ||
// Check if postMessage function exists for window.top | ||
if (typeof window.top.postMessage === 'function') { | ||
window.top.postMessage({ | ||
action: 'wcpos-wp-credentials', | ||
payload: credentials | ||
}, '*'); | ||
} | ||
// Check if ReactNativeWebView object and postMessage function exists | ||
if (typeof window.ReactNativeWebView !== 'undefined' && typeof window.ReactNativeWebView.postMessage === 'function') { | ||
window.ReactNativeWebView.postMessage(JSON.stringify({ | ||
action: 'wcpos-wp-credentials', | ||
payload: credentials | ||
})); | ||
} | ||
})(); | ||
</script>" . "\n"; | ||
} | ||
|
||
} |
Oops, something went wrong.