PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.4
ShopBuilder – WooCommerce Builder For Elementor v1.1.4
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Frontend / Ajax / AjaxLogin.php

AjaxLogin.php in ShopBuilder – WooCommerce Builder For Elementor 1.1.4, at app/Controllers/Frontend/Ajax/AjaxLogin.php

100 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add to Cart Ajax Class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers\Frontend\Ajax;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Traits\SingletonTrait;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Add to Cart Ajax Class.
20 */
21 class AjaxLogin {
22 /**
23 * Singleton.
24 */
25 use SingletonTrait;
26
27 /**
28 * Class Constructor.
29 *
30 * @return void
31 */
32 private function __construct() {
33 add_action( 'wp_ajax_nopriv_rtsb_ajax_login', [ $this, 'response' ] );
34 }
35
36 /**
37 * Ajax Response.
38 *
39 * @return void
40 */
41 public function response() {
42 $checkout_url = wc_get_checkout_url();
43 $has_error = false;
44 if ( ! Fns::verify_nonce() ) {
45 $response = array(
46 'loggedin' => false,
47 'redirectto' => $checkout_url,
48 'message_type' => 'error',
49 'message' => esc_html__('Maybe You are not a real user.', 'shopbuilder')
50 );
51 $has_error = true;
52 }
53 if ( is_user_logged_in()) {
54 $response = array(
55 'loggedin' => true,
56 'redirectto' => $checkout_url,
57 'message_type' => 'info',
58 'message' => esc_html__('Already Logged In.', 'shopbuilder')
59 );
60 $has_error = true;
61 }
62
63 if( empty( $_POST['username'] ) || empty( $_POST['password'] ) ){
64 $response = array(
65 'loggedin' => false,
66 'redirectto' => $checkout_url,
67 'message_type' => 'error',
68 'message' => esc_html__('Incorrect User Or password.', 'shopbuilder' )
69 );
70 $has_error = true;
71 }
72 if( ! $has_error ) {
73 $info['user_login'] = sanitize_text_field( $_POST['username'] ?? '' );
74 $info['user_password'] = sanitize_text_field( $_POST['password'] ?? '' );
75 $info['remember'] = ! empty( $_POST['rememberme'] ) ? sanitize_text_field( $_POST['rememberme'] ) : false;
76
77 $user_signon = wp_signon( $info, false );
78 if ( is_wp_error( $user_signon ) ) {
79 $response = array(
80 'loggedin' => false,
81 'redirectto' => $checkout_url,
82 'message_type' => 'error',
83 'message' => esc_html__( 'Login Faild.', 'shopbuilder' )
84 );
85 } else {
86 $response = array(
87 'loggedin' => true,
88 'redirectto' => $checkout_url,
89 'message_type' => 'success',
90 'message' => esc_html__( 'Login successful.', 'shopbuilder' )
91 );
92 }
93 }
94
95 wc_add_notice( $response['message'], $response['message_type'] );
96 wp_send_json($response);
97 die();
98 }
99 }
100