PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.11
Timetics – Appointment Booking Calendar & Scheduling v1.0.11
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.11, at core/integrations/auth.php

85 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 }
50
51 do_action('timetics_integration_auth', $query_var, $code );
52
53 wp_redirect( admin_url( 'admin.php?page=timetics#/my-profile') );
54 exit;
55 }
56
57 /**
58 * Authentication for google
59 *
60 * @param string $code
61 *
62 * @return void
63 */
64 public function google_auth( $code = '' ) {
65 $client = timetics_get_google_client();
66
67 $client->add_scope( Calendar::scope() );
68 $data = $client->fetch_access_token_with_auth_code( $code );
69 $data['code'] = $code;
70
71 timetics_update_google_auth( get_current_user_id(), $data );
72 }
73
74 /**
75 * Authentication for zoom
76 *
77 * @param string $code
78 *
79 * @return void
80 */
81 public function zoom_auth( $code = '' ) {
82 // Override this function to authenticate zoom
83 }
84 }
85