Rest hack

Créé Le diff n'expire jamais
4 suppressions
338 lignes
2 ajouts
336 lignes
<?php
<?php


class Post_SMTP_Mobile_Rest_API {
class Post_SMTP_Mobile_Rest_API {
private $filter = '';
private $filter = '';




/**
/**
* Register routes
* Register routes
*
*
* @since 2.7.0
* @since 2.7.0
* @version 1.0.0
* @version 1.0.0
*/
*/
public function __construct() {
public function __construct() {


add_action( 'rest_api_init', array( $this, 'register_routes' ) );
add_action( 'rest_api_init', array( $this, 'register_routes' ) );


}
}


/**
/**
* Register routes
* Register routes
*
*
* @since 2.7.0
* @since 2.7.0
* @version 1.0.0
* @version 1.0.0
*/
*/
public function register_routes() {
public function register_routes() {


register_rest_route( 'post-smtp/v1', '/connect-app', array(
register_rest_route( 'post-smtp/v1', '/connect-app', array(
'methods' => WP_REST_Server::CREATABLE,
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'connect_app' ),
'callback' => array( $this, 'connect_app' ),
'permission_callback' => '__return_true',
'permission_callback' => '__return_true',
) );
) );
register_rest_route( 'post-smtp/v1', '/get-logs', array(
register_rest_route( 'post-smtp/v1', '/get-logs', array(
'methods' => WP_REST_Server::READABLE,
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_logs' ),
'callback' => array( $this, 'get_logs' ),
'permission_callback' => '__return_true',
'permission_callback' => '__return_true',
) );
) );
register_rest_route( 'post-smtp/v1', '/disconnect-site', array(
register_rest_route( 'post-smtp/v1', '/disconnect-site', array(
'methods' => WP_REST_Server::EDITABLE,
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'disconnect_site' ),
'callback' => array( $this, 'disconnect_site' ),
'permission_callback' => '__return_true',
'permission_callback' => '__return_true',
) );
) );
register_rest_route( 'post-smtp/v1', '/get-log', array(
register_rest_route( 'post-smtp/v1', '/get-log', array(
'methods' => WP_REST_Server::READABLE,
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_log' ),
'callback' => array( $this, 'get_log' ),
'permission_callback' => '__return_true',
'permission_callback' => '__return_true',
) );
) );
register_rest_route( 'post-smtp/v1', '/resend-email', array(
register_rest_route( 'post-smtp/v1', '/resend-email', array(
'methods' => WP_REST_Server::CREATABLE,
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'resend_email' ),
'callback' => array( $this, 'resend_email' ),
'permission_callback' => '__return_true',
'permission_callback' => '__return_true',
) );
) );


}
}
public function connect_app( WP_REST_Request $request ) {
public function connect_app( WP_REST_Request $request ) {
$nonce = get_transient( 'post_smtp_auth_nonce' );
$nonce = get_transient( 'post_smtp_auth_nonce' );
$auth_key = $request->get_header( 'auth_key' );
$auth_key = $request->get_header( 'auth_key' );
$fcm_token = $request->get_header( 'fcm_token' );
$fcm_token = $request->get_header( 'fcm_token' );
$device = $request->get_header( 'device' );
$device = $request->get_header( 'device' );
$server_url = $request->get_header( 'server_url' );
$server_url = $request->get_header( 'server_url' );
if( $auth_key == $nonce ) {
if( $auth_key === $nonce ) {
$data = array(
$data = array(
$fcm_token => array(
$fcm_token => array(
'auth_key' => $auth_key,
'auth_key' => $auth_key,
'fcm_token' => $fcm_token,
'fcm_token' => $fcm_token,
'device' => $device,
'device' => $device,
'enable_notification' => 1
'enable_notification' => 1
)
)
);
);
update_option( 'post_smtp_mobile_app_connection', $data );
update_option( 'post_smtp_mobile_app_connection', $data );
update_option( 'post_smtp_server_url', $server_url );
update_option( 'post_smtp_server_url', $server_url );
wp_send_json_success(
wp_send_json_success(
array(
array(
'fcm_token' => $fcm_token
'fcm_token' => $fcm_token
),
),
200
200
);
);
}
}
delete_transient( 'post_smtp_auth_nonce' );
wp_send_json_error(
wp_send_json_error(
array(
array(
'error' => 'Refresh QR Code page, and scan again.'
'error' => 'Regenerate QR Code, and scan again.'
),
),
200
200
);
);
}
}