PluginProbe
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.4
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.4
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 All 48 releases
← All changes | lib/controllers/auth_controller.php +96 -162 trunk5.2.4 View file →
@@ -10,144 +10,116 @@
10 10 class OsAuthController extends OsController {
11 11
12 12 function __construct() {
13 13 parent::__construct();
14 - $this->action_access['public'] = array_merge(
15 - $this->action_access['public'],
16 - [
17 - 'logout_customer',
18 - 'login_customer',
19 - 'login_customer_using_social_data',
20 - 'login_customer_using_google_token',
21 - 'login_customer_using_facebook_token',
22 - 'request_otp',
23 - 'verify_otp',
24 - 'resend_otp',
25 - ]
26 - );
14 + $this->action_access['public'] = array_merge( $this->action_access['public'], [
15 + 'logout_customer',
16 + 'login_customer',
17 + 'login_customer_using_social_data',
18 + 'login_customer_using_google_token',
19 + 'login_customer_using_facebook_token',
20 + 'request_otp',
21 + 'verify_otp',
22 + 'resend_otp'
23 + ] );
27 24 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'auth/';
28 25 }
29 26
30 - public function verify_otp() {
27 + public function verify_otp(){
31 28 $this->check_nonce( 'otp_verify_otp_nonce', $this->params['otp']['verify_nonce'] );
32 29 $otp_verification_params = $this->params_for_otp_verification();
33 - $otp_code = $otp_verification_params['otp_code'];
34 - $contact_type = $otp_verification_params['contact_type'];
35 - $contact_value = $otp_verification_params['contact_value'];
36 - $delivery_method = $otp_verification_params['delivery_method'];
30 + $otp_code = $otp_verification_params['otp_code'];
31 + $contact_type = $otp_verification_params['contact_type'];
32 + $contact_value = $otp_verification_params['contact_value'];
33 + $delivery_method = $otp_verification_params['delivery_method'];
37 34
38 - $result = OsOTPHelper::verifyOTP( $otp_code, $contact_value, $contact_type, $delivery_method );
35 + $result = OsOTPHelper::verifyOTP($otp_code, $contact_value, $contact_type, $delivery_method);
39 36
40 - $message = __( 'Invalid Code', 'latepoint' );
41 - $status = LATEPOINT_STATUS_ERROR;
37 + $message = __('Invalid Code', 'latepoint');
38 + $status = LATEPOINT_STATUS_ERROR;
42 39
43 - if ( is_wp_error( $result ) ) {
40 + if ( is_wp_error($result) ) {
44 41 $message = $result->get_error_message();
45 - } elseif ( $result['status'] == LATEPOINT_STATUS_ERROR ) {
42 + }elseif($result['status'] == LATEPOINT_STATUS_ERROR){
46 43 $message = $result['message'];
47 - } elseif ( $result['status'] == LATEPOINT_STATUS_SUCCESS ) {
44 + }elseif($result['status'] == LATEPOINT_STATUS_SUCCESS) {
48 45 // Success
49 - $status = LATEPOINT_STATUS_SUCCESS;
50 - $message = OsOTPHelper::create_verification_token( $contact_value, $contact_type );
46 + $status = LATEPOINT_STATUS_SUCCESS;
47 + $message = OsOTPHelper::create_verification_token($contact_value, $contact_type);
51 48 // if auth is enabled - make sure customer is logged in
52 - if ( OsAuthHelper::is_customer_auth_enabled() && ! OsAuthHelper::is_customer_logged_in() ) {
53 - $customer = OsCustomerHelper::get_by_contact( $contact_value, $contact_type );
54 - if ( $customer && ! $customer->is_new_record() ) {
55 - OsAuthHelper::authorize_customer( $customer->id );
49 + if(OsAuthHelper::is_customer_auth_enabled() && !OsAuthHelper::is_customer_logged_in()){
50 + $customer = OsCustomerHelper::get_by_contact($contact_value, $contact_type);
51 + if($customer && !$customer->is_new_record()){
52 + OsAuthHelper::authorize_customer($customer->id);
56 53 }
57 54 }
58 55 }
59 - $this->send_json(
60 - array(
61 - 'status' => $status,
62 - 'message' => $message,
63 - )
64 - );
56 + $this->send_json( array( 'status' => $status, 'message' => $message ) );
65 57 }
66 58
67 - public function resend_otp() {
59 + public function resend_otp(){
68 60 $this->check_nonce( 'otp_resend_otp_nonce', $this->params['otp']['resend_nonce'] );
69 61 $otp_verification_params = $this->params_for_otp_verification();
70 - $contact_type = $otp_verification_params['contact_type'];
71 - $contact_value = $otp_verification_params['contact_value'];
72 - $delivery_method = $otp_verification_params['delivery_method'];
62 + $contact_type = $otp_verification_params['contact_type'];
63 + $contact_value = $otp_verification_params['contact_value'];
64 + $delivery_method = $otp_verification_params['delivery_method'];
73 65
74 - $result = OsOTPHelper::generateAndSendOTP( $contact_value, $contact_type, $delivery_method );
66 + $result = OsOTPHelper::generateAndSendOTP($contact_value, $contact_type, $delivery_method);
75 67
76 - $message = __( 'Error sending OTP', 'latepoint' );
77 - $status = LATEPOINT_STATUS_ERROR;
68 + $message = __('Error sending OTP', 'latepoint');
69 + $status = LATEPOINT_STATUS_ERROR;
78 70
79 - if ( is_wp_error( $result ) ) {
71 + if ( is_wp_error($result) ) {
80 72 $message = $result->get_error_message();
81 - } elseif ( $result['status'] == LATEPOINT_STATUS_ERROR ) {
73 + }elseif($result['status'] == LATEPOINT_STATUS_ERROR){
82 74 $message = $result['message'];
83 - } elseif ( $result['status'] == LATEPOINT_STATUS_SUCCESS ) {
75 + }elseif($result['status'] == LATEPOINT_STATUS_SUCCESS){
84 76 // Success
85 - $status = LATEPOINT_STATUS_SUCCESS;
86 - $message = OsOTPHelper::otp_input_box_html( $contact_type, $contact_value, $delivery_method );
77 + $status = LATEPOINT_STATUS_SUCCESS;
78 + $message = OsOTPHelper::otp_input_box_html($contact_type, $contact_value, $delivery_method);
87 79 }
88 - $this->send_json(
89 - array(
90 - 'status' => $status,
91 - 'message' => $message,
92 - )
93 - );
80 + $this->send_json( array( 'status' => $status, 'message' => $message ) );
94 81 }
95 82
96 - public function request_otp() {
83 + public function request_otp(){
97 84 $this->check_nonce( 'auth_nonce', $this->params['auth']['nonce'] );
98 85
99 - $auth_params = $this->params_for_otp_request();
100 - $contact_type = $auth_params['contact_type'];
101 - $contact_value = $auth_params[ $contact_type ];
86 + $auth_params = $this->params_for_otp_request();
87 + $contact_type = $auth_params['contact_type'];
88 + $contact_value = $auth_params[$contact_type];
102 89 $delivery_method = $auth_params['delivery_method'];
103 90
104 - if ( OsAuthHelper::is_classic_auth_flow() ) {
91 + if(OsAuthHelper::is_classic_auth_flow()){
105 92 // in classic flow - you can't send a OTP request to a non existent account
106 93 $customer = new OsCustomerModel();
107 - if ( $contact_type == 'email' ) {
108 - $existing_customer = $customer->where( [ 'email' => $contact_value ] )->set_limit( 1 )->get_results_as_models();
109 - if ( ! $existing_customer ) {
110 - $this->send_json(
111 - array(
112 - 'status' => LATEPOINT_STATUS_ERROR,
113 - 'message' => __( 'We don\'t recognize this email. Double-check it or create an account.', 'latepoint' ),
114 - )
115 - );
94 + if($contact_type == 'email'){
95 + $existing_customer = $customer->where(['email' => $contact_value])->set_limit(1)->get_results_as_models();
96 + if(!$existing_customer){
97 + $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __('We don\'t recognize this email. Double-check it or create an account.', 'latepoint') ) );
116 98 }
117 - } elseif ( $contact_type == 'phone' ) {
118 - $existing_customer = $customer->where( [ 'phone' => $contact_value ] )->set_limit( 1 )->get_results_as_models();
119 - if ( ! $existing_customer ) {
120 - $this->send_json(
121 - array(
122 - 'status' => LATEPOINT_STATUS_ERROR,
123 - 'message' => __( 'We don\'t recognize this phone number. Double-check it or create an account.', 'latepoint' ),
124 - )
125 - );
99 + }elseif($contact_type == 'phone'){
100 + $existing_customer = $customer->where(['phone' => $contact_value])->set_limit(1)->get_results_as_models();
101 + if(!$existing_customer){
102 + $this->send_json( array( 'status' => LATEPOINT_STATUS_ERROR, 'message' => __('We don\'t recognize this phone number. Double-check it or create an account.', 'latepoint') ) );
126 103 }
127 104 }
128 105 }
129 106
130 - $result = OsOTPHelper::generateAndSendOTP( $contact_value, $contact_type, $delivery_method );
107 + $result = OsOTPHelper::generateAndSendOTP($contact_value, $contact_type, $delivery_method);
131 108
132 - $message = __( 'Error sending OTP', 'latepoint' );
133 - $status = LATEPOINT_STATUS_ERROR;
109 + $message = __('Error sending OTP', 'latepoint');
110 + $status = LATEPOINT_STATUS_ERROR;
134 111
135 - if ( is_wp_error( $result ) ) {
112 + if ( is_wp_error($result) ) {
136 113 $message = $result->get_error_message();
137 - } elseif ( $result['status'] == LATEPOINT_STATUS_ERROR ) {
114 + }elseif($result['status'] == LATEPOINT_STATUS_ERROR){
138 115 $message = $result['message'];
139 - } elseif ( $result['status'] == LATEPOINT_STATUS_SUCCESS ) {
116 + }elseif($result['status'] == LATEPOINT_STATUS_SUCCESS){
140 117 // Success
141 - $status = LATEPOINT_STATUS_SUCCESS;
142 - $message = OsOTPHelper::otp_input_box_html( $contact_type, $contact_value, $delivery_method );
118 + $status = LATEPOINT_STATUS_SUCCESS;
119 + $message = OsOTPHelper::otp_input_box_html($contact_type, $contact_value, $delivery_method);
143 120 }
144 - $this->send_json(
145 - array(
146 - 'status' => $status,
147 - 'message' => $message,
148 - )
149 - );
121 + $this->send_json( array( 'status' => $status, 'message' => $message ) );
150 122 }
151 123
152 124
153 125 private function params_for_otp_verification(): array {
@@ -155,26 +127,23 @@
155 127 if ( empty( $params ) ) {
156 128 return [];
157 129 }
158 130
159 - $otp_params = OsParamsHelper::permit_params(
160 - $params,
161 - [
162 - 'contact_value',
163 - 'contact_type',
164 - 'delivery_method',
165 - 'otp_code',
166 - ]
167 - );
131 + $otp_params = OsParamsHelper::permit_params( $params, [
132 + 'contact_value',
133 + 'contact_type',
134 + 'delivery_method',
135 + 'otp_code'
136 + ] );
168 137
169 - $otp_params['otp_code'] = sanitize_text_field( $otp_params['otp_code'] );
138 + $otp_params['otp_code'] = sanitize_text_field( $otp_params['otp_code'] );
170 139 $otp_params['delivery_method'] = sanitize_text_field( $otp_params['delivery_method'] );
171 140
172 - if ( $otp_params['contact_type'] == 'phone' ) {
141 + if($otp_params['contact_type'] == 'phone'){
173 142 $otp_params['contact_value'] = sanitize_text_field( $otp_params['contact_value'] );
174 143 }
175 144
176 - if ( $otp_params['contact_type'] == 'email' ) {
145 + if($otp_params['contact_type'] == 'email'){
177 146 $otp_params['contact_value'] = sanitize_email( $otp_params['contact_value'] );
178 147 }
179 148
180 149 /**
@@ -196,18 +165,15 @@
196 165 if ( empty( $params ) ) {
197 166 return [];
198 167 }
199 168
200 - $auth_params = OsParamsHelper::permit_params(
201 - $params,
202 - [
203 - 'email',
204 - 'phone',
205 - 'contact_type',
206 - 'delivery_method',
207 - 'otp_code',
208 - ]
209 - );
169 + $auth_params = OsParamsHelper::permit_params( $params, [
170 + 'email',
171 + 'phone',
172 + 'contact_type',
173 + 'delivery_method',
174 + 'otp_code'
175 + ] );
210 176
211 177 if ( ! empty( $auth_params['email'] ) ) {
212 178 $auth_params['email'] = sanitize_email( $auth_params['email'] );
213 179 }
@@ -234,54 +200,37 @@
234 200
235 201
236 202 // Logs out customer and shows blank contact step
237 203 public function logout_customer() {
238 - // Verify nonce.
239 - $this->check_nonce( 'auth_nonce', $this->params['auth']['nonce'] );
240 -
241 204 OsAuthHelper::logout_customer();
242 205
243 206 if ( $this->get_return_format() == 'json' ) {
244 - $this->send_json(
245 - array(
246 - 'status' => LATEPOINT_STATUS_SUCCESS,
247 - 'message' => __( 'You have been logged out of your account.', 'latepoint' ),
248 - )
249 - );
207 + $this->send_json( array( 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => __( 'You have been logged out of your account.', 'latepoint' ) ) );
250 208 }
251 209 }
252 210
253 211 // Login customer and show contact step with prefilled info
254 212 public function login_customer() {
255 - // Verify nonce.
256 - $this->check_nonce( 'auth_nonce', $this->params['auth']['nonce'] );
257 -
258 - $contact_type = $this->params['auth']['contact_type'];
259 - $contact_value = ( $contact_type == 'email' ) ? $this->params['auth']['email'] : $this->params['auth']['phone'];
260 - $customer = OsAuthHelper::login_customer( $contact_value, $this->params['auth']['password'], $this->params['auth']['contact_type'] );
213 + $contact_type = $this->params['auth']['contact_type'];
214 + $contact_value = ($contact_type == 'email') ? $this->params['auth']['email'] : $this->params['auth']['phone'];
215 + $customer = OsAuthHelper::login_customer( $contact_value, $this->params['auth']['password'], $this->params['auth']['contact_type'] );
261 216 if ( $customer ) {
262 217 $status = LATEPOINT_STATUS_SUCCESS;
263 218 $customer_id = $customer->id;
264 219 $response_html = __( 'Welcome back', 'latepoint' );
265 220 } else {
266 - $status = LATEPOINT_STATUS_ERROR;
267 - if ( $contact_type == 'email' ) {
221 + $status = LATEPOINT_STATUS_ERROR;
222 + if($contact_type == 'email'){
268 223 $response_html = __( 'Sorry, that email or password didn\'t work.', 'latepoint' );
269 - } elseif ( $contact_type == 'phone' ) {
224 + }elseif($contact_type == 'phone'){
270 225 $response_html = __( 'Sorry, that phone number or password didn\'t work.', 'latepoint' );
271 - } else {
226 + }else{
272 227 $response_html = __( 'Sorry, that didn\'t work.', 'latepoint' );
273 228 }
274 - $customer_id = '';
229 + $customer_id = '';
275 230 }
276 231 if ( $this->get_return_format() == 'json' ) {
277 - $this->send_json(
278 - array(
279 - 'status' => $status,
280 - 'message' => $response_html,
281 - 'customer_id' => $customer_id,
282 - )
283 - );
232 + $this->send_json( array( 'status' => $status, 'message' => $response_html, 'customer_id' => $customer_id ) );
284 233 }
285 234 }
286 235
287 236 public function login_customer_using_social_data( $network, $social_user ) {
@@ -342,46 +291,31 @@
342 291 $status = LATEPOINT_STATUS_ERROR;
343 292 $response_html = $social_user['error'];
344 293 }
345 294 if ( $this->get_return_format() == 'json' ) {
346 - $this->send_json(
347 - array(
348 - 'status' => $status,
349 - 'message' => $response_html,
350 - 'customer_id' => $customer_id,
351 - )
352 - );
295 + $this->send_json( array( 'status' => $status, 'message' => $response_html, 'customer_id' => $customer_id ) );
353 296 }
297 +
354 298 }
355 299
356 300
357 301 public function login_customer_using_google_token() {
358 - // Condition for pro compatibility. Remove later.
359 - if ( isset( $this->params['nonce'] ) ) {
360 - // Verify nonce.
361 - $this->check_nonce( 'social_login_nonce', $this->params['nonce'] );
362 - }
363 -
364 302 $social_user = [];
365 303 $token = sanitize_text_field( $this->params['token'] );
366 304 $social_user = apply_filters( 'latepoint_get_social_user_by_token', $social_user, 'google', $token );
367 - if ( ! empty( $social_user ) ) {
305 + if ( !empty($social_user) ) {
368 306 $this->login_customer_using_social_data( 'google', $social_user );
369 307 }
370 308 }
371 309
372 310 public function login_customer_using_facebook_token() {
373 - // Condition for pro compatibility. Remove later.
374 - if ( isset( $this->params['nonce'] ) ) {
375 - // Verify nonce.
376 - $this->check_nonce( 'social_login_nonce', $this->params['nonce'] );
377 - }
378 -
379 311 $social_user = [];
380 312 $token = sanitize_text_field( $this->params['token'] );
381 313 $social_user = apply_filters( 'latepoint_get_social_user_by_token', $social_user, 'facebook', $token );
382 - if ( ! empty( $social_user ) ) {
314 + if ( !empty($social_user) ) {
383 315 $this->login_customer_using_social_data( 'facebook', $social_user );
384 316 }
385 317 }
318 +
319 +
386 320 }
387 -endif;
321 +endif;