+ handling incorrect sesion data returned from the vendor API
This commit is contained in:
parent
d859dbad0a
commit
c7bc5ddc0c
|
@ -9,7 +9,12 @@ function get_auth_string() {
|
||||||
|
|
||||||
local user="$(session_get_username ${cookies[sh_session]})"
|
local user="$(session_get_username ${cookies[sh_session]})"
|
||||||
|
|
||||||
echo "Authorization: Bearer $(cat secret/authTokens.dat | grep -P "^$user:" | sed -s "s/$user://")"
|
local token="$(cat secret/authTokens.dat | grep -P "^$user:" | sed -s "s/$user://")"
|
||||||
|
if [[ "$token" == 'null' ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Authorization: Bearer $token"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_refresh_token() {
|
function get_refresh_token() {
|
||||||
|
@ -40,10 +45,13 @@ function add_account_refreshtoken() {
|
||||||
if ! session_verify "${cookies[sh_session]}"; then
|
if ! session_verify "${cookies[sh_session]}"; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
username="$(session_get_username ${cookies[sh_session]})"
|
||||||
|
|
||||||
if check_if_user_exists refreshToken; then
|
if ! check_if_user_exists refreshToken; then
|
||||||
echo "$(session_get_username ${cookies[sh_session]}):$1" >> secret/refreshTokens.dat
|
sed -E -i '/^'"$username"':/d' secret/refreshTokens.dat
|
||||||
fi
|
fi
|
||||||
|
echo "$username:$1" >> secret/refreshTokens.dat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,11 +61,13 @@ function add_account_authtoken() {
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
username="$(session_get_username ${cookies[sh_session]})"
|
||||||
token="$(sed 's/Bearer //g' <<< "$@")"
|
token="$(sed 's/Bearer //g' <<< "$@")"
|
||||||
|
|
||||||
if check_if_user_exists authToken; then
|
if ! check_if_user_exists authToken; then
|
||||||
echo "$(session_get_username ${cookies[sh_session]}):$token" >> secret/authTokens.dat
|
sed -E -i '/^'"$username"':/d' secret/authTokens.dat
|
||||||
fi
|
fi
|
||||||
|
echo "$username:$token" >> secret/authTokens.dat
|
||||||
}
|
}
|
||||||
|
|
||||||
# update_account_authtoken(username)
|
# update_account_authtoken(username)
|
||||||
|
|
|
@ -223,6 +223,17 @@ const request = (resource: string, data: any) =>
|
||||||
".package-list",
|
".package-list",
|
||||||
".description",
|
".description",
|
||||||
]);
|
]);
|
||||||
|
case -4:
|
||||||
|
// the API broke our token
|
||||||
|
showElements([".tel-box", ".logout-button", ".reset-notice"]);
|
||||||
|
hideElements([
|
||||||
|
".login-box",
|
||||||
|
".register-box",
|
||||||
|
".mail-box",
|
||||||
|
".package-list",
|
||||||
|
".description",
|
||||||
|
".sms-box",
|
||||||
|
]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
openError(res.description || res.msg || `Session error: ${res.status}`);
|
openError(res.description || res.msg || `Session error: ${res.status}`);
|
||||||
|
@ -519,6 +530,24 @@ window.addEventListener("load", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const tel = document.querySelector(".tel-form")!;
|
||||||
|
tel.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = event.target as HTMLFormElement;
|
||||||
|
if (!phone) {
|
||||||
|
phone = (form.querySelector('input[name="phone"]')! as HTMLInputElement).value;
|
||||||
|
}
|
||||||
|
const res = await request("smscode_send", {
|
||||||
|
phone,
|
||||||
|
});
|
||||||
|
if (res.status == 200) {
|
||||||
|
hideElements([".tel-box"]);
|
||||||
|
showElements([".sms-box"]);
|
||||||
|
} else {
|
||||||
|
openError(res.description || res.msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const sms = document.querySelector(".sms-form")!;
|
const sms = document.querySelector(".sms-form")!;
|
||||||
sms.addEventListener("submit", async (event) => {
|
sms.addEventListener("submit", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -531,7 +560,7 @@ window.addEventListener("load", () => {
|
||||||
phone,
|
phone,
|
||||||
});
|
});
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
hideElements([".sms-box", ".description"]);
|
hideElements([".sms-box", ".reset-notice"]);
|
||||||
phone = null;
|
phone = null;
|
||||||
localStorage.removeItem("phone");
|
localStorage.removeItem("phone");
|
||||||
await refreshPackages();
|
await refreshPackages();
|
||||||
|
@ -539,6 +568,7 @@ window.addEventListener("load", () => {
|
||||||
} else {
|
} else {
|
||||||
openError(res.description || res.msg);
|
openError(res.description || res.msg);
|
||||||
}
|
}
|
||||||
|
(form.querySelector('input[name="code"]')! as HTMLInputElement).value = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
[...Array.from(document.querySelectorAll(".modal-background"))].forEach((element) => {
|
[...Array.from(document.querySelectorAll(".modal-background"))].forEach((element) => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ $family-sans-serif: BlinkMacSystemFont, -apple-system, sans-serif;
|
||||||
@import "../node_modules/bulma/sass/grid/columns.sass";
|
@import "../node_modules/bulma/sass/grid/columns.sass";
|
||||||
@import "../node_modules/bulma/sass/elements/button.sass";
|
@import "../node_modules/bulma/sass/elements/button.sass";
|
||||||
@import "../node_modules/bulma/sass/elements/container.sass";
|
@import "../node_modules/bulma/sass/elements/container.sass";
|
||||||
|
@import "../node_modules/bulma/sass/elements/notification.sass";
|
||||||
@import "../node_modules/bulma/sass/elements/table.sass";
|
@import "../node_modules/bulma/sass/elements/table.sass";
|
||||||
@import "../node_modules/bulma/sass/elements/title.sass";
|
@import "../node_modules/bulma/sass/elements/title.sass";
|
||||||
@import "../node_modules/bulma/sass/elements/other.sass";
|
@import "../node_modules/bulma/sass/elements/other.sass";
|
||||||
|
@ -28,7 +29,9 @@ $family-sans-serif: BlinkMacSystemFont, -apple-system, sans-serif;
|
||||||
.error-box,
|
.error-box,
|
||||||
.areyousure-box,
|
.areyousure-box,
|
||||||
.package-list,
|
.package-list,
|
||||||
.details-box {
|
.details-box,
|
||||||
|
.reset-notice,
|
||||||
|
.tel-box {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,15 @@ fi
|
||||||
data=''
|
data=''
|
||||||
|
|
||||||
while [[ "$data" == '' ]]; do
|
while [[ "$data" == '' ]]; do
|
||||||
data=$(curl -s -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/parcel?updatedAfter=1970-01-01T00:00:00.000Z")
|
auth="$(get_auth_string)"
|
||||||
|
if [[ $? == 1 ]]; then
|
||||||
|
broken_session=true # whatever, this works
|
||||||
|
fi
|
||||||
|
data=$(curl -s -H "$auth" "https://api-inmobile-pl.easypack24.net/v1/parcel?updatedAfter=1970-01-01T00:00:00.000Z")
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$data" | jq -c "[.[] | {shipmentNumber: .shipmentNumber, status: .status, openCode: .openCode, senderName: .senderName, pickupPoint: {name: .pickupPoint.name, status: .pickupPoint.status, location: .pickupPoint.location, description: .pickupPoint.locationDescription, address: .pickupPoint.addressDetails}}]"
|
if [[ "$broken_session" == true ]]; then
|
||||||
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args "-4" "The session went bork"
|
||||||
|
else
|
||||||
|
echo "$data" | jq -c "[.[] | {shipmentNumber: .shipmentNumber, status: .status, openCode: .openCode, senderName: .senderName, pickupPoint: {name: .pickupPoint.name, status: .pickupPoint.status, location: .pickupPoint.location, description: .pickupPoint.locationDescription, address: .pickupPoint.addressDetails}}]"
|
||||||
|
fi
|
||||||
|
|
|
@ -16,8 +16,8 @@ if [[ "${post_data[phone]}" != "" && "${post_data[code]}" != "" ]]; then
|
||||||
if [[ $(echo $tokens | jq .status) == "404" ]]; then
|
if [[ $(echo $tokens | jq .status) == "404" ]]; then
|
||||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "wrongData"
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "wrongData"
|
||||||
else
|
else
|
||||||
add_account_refreshtoken $(echo $tokens | jq -r .refreshToken)
|
add_account_refreshtoken "$(echo "$tokens" | jq -r .refreshToken)"
|
||||||
add_account_authtoken $(echo $tokens | jq -r .authToken)
|
add_account_authtoken "$(echo "$tokens" | jq -r .authToken)"
|
||||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
16
webroot/api/smscode_send.shs
Normal file
16
webroot/api/smscode_send.shs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# stolen from mailcode.shs - probably should be merged sometime
|
||||||
|
if ! session_verify "${cookies[sh_session]}"; then
|
||||||
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "You're not logged in!"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
source "${cfg[namespace]}/code/common.sh"
|
||||||
|
|
||||||
|
if [[ "${post_data[phone]}" != '' ]]; then
|
||||||
|
x=''
|
||||||
|
while [[ "$x" == '' ]]; do
|
||||||
|
x=$(curl -s "https://api-inmobile-pl.easypack24.net/v1/sendSMSCode/${post_data[phone]}")
|
||||||
|
done
|
||||||
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "sent request"
|
||||||
|
fi
|
|
@ -26,6 +26,12 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="notification is-danger reset-notice">
|
||||||
|
It appears that the vendor API sent OCW a bad token value. This means
|
||||||
|
that to authenticate to the service, you'll need to
|
||||||
|
<strong>re-validate your phone number</strong>.<br /><br />
|
||||||
|
Sorry for the inconvenience.
|
||||||
|
</div>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<div class="title is-1">Welcome to OCW!</div>
|
<div class="title is-1">Welcome to OCW!</div>
|
||||||
<p class="paragraph">
|
<p class="paragraph">
|
||||||
|
@ -232,6 +238,24 @@
|
||||||
<input type="submit" class="button" value="Submit" />
|
<input type="submit" class="button" value="Submit" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tel-box column">
|
||||||
|
<label class="label is-large">Phone re-validation</label>
|
||||||
|
<form method="POST" class="tel-form">
|
||||||
|
<div class="field tel-phone-field">
|
||||||
|
<label for="phone" class="label">Phone number</label>
|
||||||
|
<div class="control">
|
||||||
|
<input
|
||||||
|
type="tel"
|
||||||
|
name="phone"
|
||||||
|
class="input"
|
||||||
|
placeholder="222922597"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p class="help">The one your packages are assigned to</p>
|
||||||
|
</div>
|
||||||
|
<input type="submit" class="button" value="Submit" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="areyousure-box modal">
|
<div class="areyousure-box modal">
|
||||||
<div class="modal-background"></div>
|
<div class="modal-background"></div>
|
||||||
|
|
Loading…
Reference in a new issue