| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('BVAccountCallback')) : |
| 5 |
class BVAccountCallback extends BVCallbackBase { |
| 6 |
public $account; |
| 7 |
public $settings; |
| 8 |
|
| 9 |
const ACCOUNT_WING_VERSION = 1.2; |
| 10 |
|
| 11 |
public function __construct($callback_handler) { |
| 12 |
$this->account = $callback_handler->account; |
| 13 |
$this->settings = $callback_handler->settings; |
| 14 |
} |
| 15 |
|
| 16 |
function updateInfo($args) { |
| 17 |
$result = array(); |
| 18 |
|
| 19 |
if (array_key_exists('update_info', $args)) { |
| 20 |
$this->account->updateInfo($args['update_info']); |
| 21 |
$result['update_info'] = array( |
| 22 |
"status" => WPRAccount::exists($this->settings, $args['update_info']['pubkey']) |
| 23 |
); |
| 24 |
} |
| 25 |
|
| 26 |
if (array_key_exists('update_api_key', $args)) { |
| 27 |
WPRAccount::updateApiPublicKey($this->settings, $args['update_api_key']['pubkey']); |
| 28 |
$result['update_api_key'] = array( |
| 29 |
"status" => $this->settings->getOption(WPRAccount::$api_public_key) |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
if (array_key_exists('update_options', $args)) |
| 34 |
$result['update_options'] = $this->settings->updateOptions($args['update_options']); |
| 35 |
|
| 36 |
if (array_key_exists('delete_options', $args)) |
| 37 |
$result['delete_options'] = $this->settings->deleteOptions($args['delete_options']); |
| 38 |
|
| 39 |
$result['status'] = true; |
| 40 |
|
| 41 |
return $result; |
| 42 |
} |
| 43 |
|
| 44 |
function process($request) { |
| 45 |
$params = $request->params; |
| 46 |
$account = $this->account; |
| 47 |
$settings = $this->settings; |
| 48 |
switch ($request->method) { |
| 49 |
case "addacc": |
| 50 |
WPRAccount::addAccount($settings, $params['public'], $params['secret']); |
| 51 |
$resp = array("status" => WPRAccount::exists($settings, $params['public'])); |
| 52 |
break; |
| 53 |
case "rmacc": |
| 54 |
$resp = array("status" => WPRAccount::remove($settings, $params['public'])); |
| 55 |
break; |
| 56 |
case "updt": |
| 57 |
$account->updateInfo($params); |
| 58 |
$resp = array("status" => WPRAccount::exists($settings, $params['pubkey'])); |
| 59 |
break; |
| 60 |
case "updtapikey": |
| 61 |
WPRAccount::updateApiPublicKey($settings, $params['pubkey']); |
| 62 |
$resp = array("status" => $settings->getOption(WPRAccount::$api_public_key)); |
| 63 |
break; |
| 64 |
case "rmbvscrt": |
| 65 |
$resp = array("status" => WPRRecover::deleteDefaultSecret($settings)); |
| 66 |
break; |
| 67 |
case "rmbvkeys": |
| 68 |
$resp = array("status" => $settings->deleteOption('bvKeys')); |
| 69 |
break; |
| 70 |
case "rmdefpub": |
| 71 |
$resp = array("status" => $settings->deleteOption('bvDefaultPublic')); |
| 72 |
break; |
| 73 |
case "rmoldbvacc": |
| 74 |
$resp = array("status" => $settings->deleteOption('bvAccounts')); |
| 75 |
break; |
| 76 |
case "fetch": |
| 77 |
$accounts = WPRAccount::allAccounts($settings); |
| 78 |
if (!isset($params['full'])) { |
| 79 |
foreach ($accounts as &$account) { |
| 80 |
if (isset($account['secret'])) { |
| 81 |
unset($account['secret']); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
$resp = array("status" => $accounts); |
| 86 |
break; |
| 87 |
case "updtinfo": |
| 88 |
$resp = $this->updateInfo($params); |
| 89 |
break; |
| 90 |
default: |
| 91 |
$resp = false; |
| 92 |
} |
| 93 |
return $resp; |
| 94 |
} |
| 95 |
} |
| 96 |
endif; |