PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.0
Timetics – Appointment Booking Calendar & Scheduling v1.0.0
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / integrations / auth.php

auth.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.0, at core/integrations/auth.php

86 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Authentication for integrations
4 *
5 * @package Timetics
6 */
7
8 namespace Timetics\Core\Integrations;
9
10 use Timetics\Core\Integrations\Google\Service\Calendar;
11 use Timetics\Utils\Singleton;
12
13 /**
14 * Auth Class
15 *
16 * @since 1.0.0
17 */
18 class Auth {
19 use Singleton;
20
21 /**
22 * Initialize
23 *
24 * @return void
25 */
26 public function init() {
27 add_action( 'template_redirect', [ $this, 'authenticate' ] );
28 }
29
30 /**
31 * Authenticate integration
32 *
33 * @return void
34 */
35 public function authenticate() {
36 $query_var = get_query_var( 'timetics-integration', false );
37 $user_id = get_current_user_id();
38
39 $code = isset( $_GET['code'] ) ? sanitize_text_field( $_GET['code'] ) : '';
40
41 if ( ! $query_var ) {
42 return;
43 }
44
45 switch ( $query_var ) {
46 case 'google-auth':
47 $this->google_auth( $code );
48 break;
49 case 'zoom-auth':
50 $this->zoom_auth();
51 break;
52 }
53
54 wp_redirect( admin_url( 'admin.php?page=timetics#/my-profile') );
55 exit;
56 }
57
58 /**
59 * Authentication for google
60 *
61 * @param string $code
62 *
63 * @return void
64 */
65 public function google_auth( $code = '' ) {
66 $client = timetics_get_google_client();
67
68 $client->add_scope( Calendar::scope() );
69 $data = $client->fetch_access_token_with_auth_code( $code );
70 $data['code'] = $code;
71
72 timetics_update_google_auth( get_current_user_id(), $data );
73 }
74
75 /**
76 * Authentication for zoom
77 *
78 * @param string $code
79 *
80 * @return void
81 */
82 public function zoom_auth( $code = '' ) {
83 // Override this function to authenticate zoom
84 }
85 }
86