| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\API\Controller; |
| 4 |
|
| 5 |
use BitCode\BitForm\Core\Database\FormModel; |
| 6 |
use WP_Error; |
| 7 |
use WP_REST_Controller; |
| 8 |
use WP_REST_Request; |
| 9 |
|
| 10 |
class EntryController extends WP_REST_Controller |
| 11 |
{ |
| 12 |
protected static $form; |
| 13 |
protected $formModel; |
| 14 |
protected $form_id; |
| 15 |
|
| 16 |
public function __construct() |
| 17 |
{ |
| 18 |
$this->formModel = new FormModel(); |
| 19 |
} |
| 20 |
|
| 21 |
public function googleAuth() |
| 22 |
{ |
| 23 |
$state = $_GET['state']; |
| 24 |
$code = urlencode($_GET['code']); |
| 25 |
// echo $code; |
| 26 |
if (wp_redirect($state . '&code=' . $code, 302)) { |
| 27 |
exit; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function oneDriveAuth() |
| 32 |
{ |
| 33 |
$state = $_GET['state']; |
| 34 |
$code = urlencode($_GET['code']); |
| 35 |
// echo $code; |
| 36 |
if (wp_redirect($state . '&code=' . $code, 302)) { |
| 37 |
exit; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public function authRedirect(WP_REST_Request $request) |
| 42 |
{ |
| 43 |
$state = $request->get_param('state'); |
| 44 |
$parsed_url = parse_url(get_site_url()); |
| 45 |
$site_url = $parsed_url['scheme'] . '://' . $parsed_url['host']; |
| 46 |
$site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port']; |
| 47 |
if (false === strpos($state, $site_url)) { |
| 48 |
return new WP_Error('404'); |
| 49 |
} |
| 50 |
$params = $request->get_params(); |
| 51 |
unset($params['rest_route'], $params['state']); |
| 52 |
if (wp_redirect($state . '&' . http_build_query($params), 302)) { |
| 53 |
exit; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|