class-zvc-admin-setup-wizard.php
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
class VCZAPI_Admin_Setup_Wizard {
public static $instance = null;
/**
* @return VCZAPI_Admin_Setup_Wizard|null
*/
public static function get_instance() {
return is_null( self::$instance ) ? self::$instance = new self() : self::$instance;
}
public function __construct() {
add_action( 'wp_ajax_vczapi_save_oauth_credentials', [ $this, 'save_oauth_credentials' ] );
add_action( 'wp_ajax_vczapi_save_app_sdk_credentials', [ $this, 'save_app_sdk_credentials' ] );
}
/**
* @return void
*/
public function save_oauth_credentials() {
$nonce = filter_input( INPUT_POST, 's2sOauth_wizard_nonce' );
if ( ! wp_verify_nonce( $nonce, 'verify_s2sOauth_wizard_nonce' ) ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$account_id = sanitize_text_field( filter_input( INPUT_POST, 'vczapi_wizard_oauth_account_id' ) );
$client_id = sanitize_text_field( filter_input( INPUT_POST, 'vczapi_wizard_oauth_client_id' ) );
$client_secret = sanitize_text_field( filter_input( INPUT_POST, 'vczapi_wizard_oauth_client_secret' ) );
$delete_jwt_keys = sanitize_text_field( filter_input( INPUT_POST, 'vczapi_wizard_delete_jwt_keys' ) );
//added for Oauth S2S
update_option( 'vczapi_oauth_account_id', $account_id );
update_option( 'vczapi_oauth_client_id', $client_id );
update_option( 'vczapi_oauth_client_secret', $client_secret );
$result = \vczapi\S2SOAuth::get_instance()->generateAndSaveAccessToken( $account_id, $client_id, $client_secret );
if ( ! is_wp_error( $result ) ) {
//this can't be a cached request
$decoded_users = json_decode( zoom_conference()->listUsers() );
if ( ! is_null( $decoded_users ) ) {
if ( $delete_jwt_keys == 'on' ) {
delete_option( 'zoom_api_key' );
delete_option( 'zoom_api_secret' );
}
wp_send_json_success( [ 'message' => 'Credentials verified and saved, please continue to next step' ] );
} else {
wp_send_json_error( [ 'code' => 'Random', 'message' => 'Could not make API Call - please try saving again' ] );
}
} else {
wp_send_json_error( [ 'code' => $result->get_error_code(), 'message' => $result->get_error_message() . ' Please double check your credentials' ] );
}
}
/**
* @return void
*/
public function save_app_sdk_credentials() {
$nonce = filter_input( INPUT_POST, 's2sOauth_wizard_nonce' );
if ( ! wp_verify_nonce( $nonce, 'verify_s2sOauth_wizard_nonce' ) ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$vczapi_sdk_key = filter_input( INPUT_POST, 'vczapi_wizard_sdk_key' );
$vczapi_sdk_secret_key = filter_input( INPUT_POST, 'vczapi_wizard_sdk_secret_key' );
update_option( 'vczapi_sdk_key', $vczapi_sdk_key );
update_option( 'vczapi_sdk_secret_key', $vczapi_sdk_secret_key );
if ( empty( $vczapi_sdk_key ) ) {
wp_send_json_error( [ 'message' => 'SDK Key is missing, please double check your credentials' ] );
} elseif ( empty( $vczapi_sdk_secret_key ) ) {
wp_send_json_error( [ 'message' => 'SDK Secret Key is missing, please double check your credentials' ] );
}
wp_send_json_success( [ 'message' => 'App SDK Keys succesfully saved, please check that join via browser is working on your site.' ] );
}
}
VCZAPI_Admin_Setup_Wizard::get_instance();