Skip to content

Commit

Permalink
Issue #10: fix invalid token error for each source (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool committed Dec 23, 2021
1 parent 65e323f commit a1da463
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions sources/attach.inc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ function filefield_source_attach_process($element, &$form_state, $form) {
);
$element['filefield_attach']['#description'] = $description;
}

$ajax_path = 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'];
$token = backdrop_hmac_base64($ajax_path, backdrop_get_private_key() . backdrop_get_hash_salt());
$element['filefield_attach']['attach'] = array(
'#name' => implode('_', $element['#array_parents']) . '_attach',
'#type' => 'submit',
Expand All @@ -181,7 +182,7 @@ function filefield_source_attach_process($element, &$form_state, $form) {
'#submit' => array('filefield_sources_field_submit'),
'#limit_validation_errors' => array($element['#parents']),
'#ajax' => array(
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
'path' => $ajax_path. '/' . $token,
'wrapper' => $element['upload_button']['#ajax']['wrapper'],
'method' => 'replace',
'effect' => 'fade',
Expand Down
4 changes: 3 additions & 1 deletion sources/clipboard.inc
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ function filefield_source_clipboard_process($element, &$form_state, $form) {
'#type' => 'hidden',
'#attributes' => array('class' => array('filefield-source-clipboard-contents')),
);
$ajax_path = 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'];
$token = backdrop_hmac_base64($ajax_path, backdrop_get_private_key() . backdrop_get_hash_salt());
$element['filefield_clipboard']['upload'] = array(
'#type' => 'submit',
'#value' => t('Upload'),
'#ajax' => array(
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
'path' => $ajax_path. '/' . $token,
'wrapper' => $element['upload_button']['#ajax']['wrapper'],
'effect' => 'fade',
'progress' => array(
Expand Down
4 changes: 3 additions & 1 deletion sources/imce.inc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function filefield_source_imce_process($element, &$form_state, $form) {
'#markup' => '<span id="' . $display_id . '" class="filefield-sources-imce-display">' . t('No file selected') . '</span> (<a class="filefield-sources-imce-browse" href="#" onclick="' . $imce_function . '">' . t('browse') . '</a>)',
);

$ajax_path = 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'];
$token = backdrop_hmac_base64($ajax_path, backdrop_get_private_key() . backdrop_get_hash_salt());
$element['filefield_imce']['select'] = array(
'#name' => implode('_', $element['#array_parents']) . '_imce_select',
'#type' => 'submit',
Expand All @@ -138,7 +140,7 @@ function filefield_source_imce_process($element, &$form_state, $form) {
'#id' => $select_id,
'#attributes' => array('style' => 'display: none;'),
'#ajax' => array(
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
'path' => $ajax_path. '/' . $token,
'wrapper' => $element['upload_button']['#ajax']['wrapper'],
'method' => 'replace',
'effect' => 'fade',
Expand Down
5 changes: 3 additions & 2 deletions sources/remote.inc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ function filefield_source_remote_process($element, &$form_state, $form) {
'#description' => filefield_sources_element_validation_help($element['#upload_validators']),
'#maxlength' => NULL,
);

$ajax_path = 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'];
$token = backdrop_hmac_base64($ajax_path, backdrop_get_private_key() . backdrop_get_hash_salt());
$element['filefield_remote']['transfer'] = array(
'#name' => implode('_', $element['#array_parents']) . '_transfer',
'#type' => 'submit',
Expand All @@ -98,7 +99,7 @@ function filefield_source_remote_process($element, &$form_state, $form) {
'#submit' => array('filefield_sources_field_submit'),
'#limit_validation_errors' => array($element['#parents']),
'#ajax' => array(
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
'path' => $ajax_path. '/' . $token,
'wrapper' => $element['upload_button']['#ajax']['wrapper'],
'effect' => 'fade',
'progress' => array(
Expand Down

0 comments on commit a1da463

Please sign in to comment.