Backend\Core\Engine\Api::appleAddDevice PHP Method

appleAddDevice() public static method

Add an Apple device to a user.
public static appleAddDevice ( string $token, string $email )
$token string The token of the device.
$email string 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.'));
            }
        }
    }