Register a new/old Apple device within the Fork API
public appleRegisterDevice ( string $deviceToken ) : boolean | ||
$deviceToken | string | The device token to register. |
return | boolean |
/** * Add a device to a user. * * @return void * @param string $token The token of the device. * @param string $email The emailaddress for the user to link the device to. */ public static function appleAdddevice($token, $email) { // authorized? if (API::authorize()) { // redefine $token = str_replace(' ', '', (string) $token); // validate if ($token == '') { API::output(API::BAD_REQUEST, array('message' => 'No token-parameter provided.')); } if ($email == '') { API::output(API::BAD_REQUEST, array('message' => 'No email-parameter provided.')); } // we should tell the ForkAPI that we registered a device $publicKey = BackendModel::getModuleSetting('core', 'fork_api_public_key', ''); $privateKey = FrontendModel::getModuleSetting('core', 'fork_api_private_key', ''); // validate keys if ($publicKey == '' || $privateKey == '') { API::output(API::BAD_REQUEST, array('message' => 'Invalid key for the Fork API, configer them in the backend.')); } try { // load user $user = new BackendUser(null, $email); // get current tokens $tokens = (array) $user->getSetting('apple_device_token'); // not already in array? if (!in_array($token, $tokens)) { $tokens[] = $token; } // require the class require_once PATH_LIBRARY . '/external/fork_api.php'; // create instance $forkAPI = new ForkAPI($publicKey, $privateKey); // make the call $forkAPI->appleRegisterDevice($token); // store if (!empty($tokens)) { $user->setSetting('apple_device_token', $tokens); } } catch (Exception $e) { API::output(API::FORBIDDEN, array('message' => 'Can\'t authenticate you.')); } } }
/** * Add an Apple device to a user. * * @param string $token The token of the device. * @param string $email The emailaddress for the user to link the device to. */ public static function appleAddDevice($token, $email) { trigger_error('The api is deprecated and will be removed in version 5', E_USER_DEPRECATED); if (BaseAPI::isAuthorized()) { $token = str_replace(' ', '', (string) $token); // validate if ($token == '') { BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No token-parameter provided.')); } if ($email == '') { BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No email-parameter provided.')); } // we should tell the ForkAPI that we registered a device $publicKey = Model::get('fork.settings')->get('Core', 'fork_api_public_key', ''); $privateKey = Model::get('fork.settings')->get('Core', 'fork_api_private_key', ''); // validate keys if ($publicKey == '' || $privateKey == '') { BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'Invalid key for the Fork API, configure them in the backend.')); } try { // load user $user = new User(null, $email); // get current tokens $tokens = (array) $user->getSetting('apple_device_token'); // not already in array? if (!in_array($token, $tokens)) { $tokens[] = $token; } // require the class require_once PATH_LIBRARY . '/external/fork_api.php'; // create instance $forkAPI = new \ForkAPI($publicKey, $privateKey); // make the call $forkAPI->appleRegisterDevice($token); // store if (!empty($tokens)) { $user->setSetting('apple_device_token', $tokens); } } catch (Exception $e) { BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.')); } } }