From 2baf509f259f8f3d795aab2906f7be0279021d59 Mon Sep 17 00:00:00 2001 From: Dominika Liberda Date: Tue, 27 Apr 2021 23:06:33 +0200 Subject: [PATCH] * fixes authToken update problem --- code/common.sh | 4 +++- webroot/api/collect.shs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/code/common.sh b/code/common.sh index 19208b6..57daeb2 100644 --- a/code/common.sh +++ b/code/common.sh @@ -53,8 +53,10 @@ function add_account_authtoken() { exit 0 fi + token="$(sed 's/Bearer //g' <<< "$@")" + if check_if_user_exists authToken; then - echo "$(session_get_username ${cookies[sh_session]}):$1" >> secret/authTokens.dat + echo "$(session_get_username ${cookies[sh_session]}):$token" >> secret/authTokens.dat fi } diff --git a/webroot/api/collect.shs b/webroot/api/collect.shs index 5c05cbb..2774e9a 100644 --- a/webroot/api/collect.shs +++ b/webroot/api/collect.shs @@ -10,6 +10,8 @@ while [[ "$data" == '' ]]; do data=$(curl -s -X POST -H "$(get_auth_string)" -H "Content-type: application/json" "https://api-inmobile-pl.easypack24.net/v1/collect/validate" --data '{"geoPoint":{"accuracy":"1","latitude":"'"${post_data[lat]}"'","longitude":"'"${post_data[lon]}"'"},"parcel":{"openCode":"'"${post_data[openCode]}"'","shipmentNumber":"'"${post_data[id]}"'"}}') done +echo $data > tmpdata + if [[ $(echo $data | jq .status) == "403" ]]; then echo $data | jq "{status: .status, msg: .error}" else @@ -19,8 +21,9 @@ else data=$(curl -X POST -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid") done if [[ $(echo $data | jq ".compartment") != "" ]]; then - echo $data + jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 ":o $data" else jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "OCW received an invalid response from the API." fi + echo $data > tmp_data2 fi