login flow now works ;) also small refactor
parent
9496fe3cdc
commit
756a75d0aa
|
@ -26,16 +26,14 @@ const openLockerConfirm = (lat: string, lon: string, openCode: string, id: strin
|
|||
id,
|
||||
}).then((res) => {
|
||||
if (res.status != 200) {
|
||||
openError(res.description || res.error);
|
||||
openError(res.description || res.msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const openLocker = (lat: string, lon: string, openCode: string, id: string) => {
|
||||
(document.querySelector(".areyousure-box") as HTMLElement).style.display = "block";
|
||||
document
|
||||
.querySelector(".areyousure-button")!
|
||||
.addEventListener("click", () => openLockerConfirm(lat, lon, openCode, id));
|
||||
(document.querySelector(".areyousure-button") as HTMLElement)!.onclick = () => { openLockerConfirm(lat, lon, openCode, id) };
|
||||
};
|
||||
|
||||
const refreshPackages = () =>
|
||||
|
@ -78,9 +76,26 @@ window.addEventListener("load", () => {
|
|||
request("login", {
|
||||
login: form.login.value,
|
||||
password: form.password.value,
|
||||
}).then((res) => {
|
||||
if(res.status == 200) {
|
||||
refreshPackages().then(() => {
|
||||
[".login-box", ".register-box"].forEach((elementName) => {
|
||||
(document.querySelector(elementName)! as HTMLDivElement).style.display = "none";
|
||||
});
|
||||
(document.querySelector(".package-list")! as HTMLDivElement).style.display = "block";
|
||||
});
|
||||
} else {
|
||||
openError(res.msg || "Error during login. Try again in a while?")
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const logout = document.querySelector(".logout-button")!;
|
||||
logout.addEventListener("click", (event) => {
|
||||
request("logout",{}).then(() => {
|
||||
document.location = document.location})
|
||||
})
|
||||
|
||||
const register = document.querySelector(".register-form")!;
|
||||
register.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
|
@ -97,7 +112,7 @@ window.addEventListener("load", () => {
|
|||
);
|
||||
(document.querySelector(".sms-box")! as HTMLDivElement).style.display = "block";
|
||||
} else {
|
||||
openError(res.description || res.error);
|
||||
openError(res.description || res.msg);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -114,7 +129,7 @@ window.addEventListener("load", () => {
|
|||
await refreshPackages();
|
||||
(document.querySelector(".package-list")! as HTMLDivElement).style.display = "block";
|
||||
} else {
|
||||
openError(res.description || res.error);
|
||||
openError(res.description || res.msg);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -124,6 +139,12 @@ window.addEventListener("load", () => {
|
|||
errorBoxWindow.style.display = "none";
|
||||
});
|
||||
|
||||
const areYouNotSureButton = <HTMLAnchorElement>document.querySelector(".areyousure-button-deny")!;
|
||||
areYouNotSureButton.addEventListener("click", () => {
|
||||
(document.querySelector(".areyousure-box") as HTMLElement).style.display = "none";
|
||||
});
|
||||
|
||||
|
||||
request("session", {}).then((res) => {
|
||||
if (res.status == 200) {
|
||||
// logged in
|
||||
|
|
|
@ -8,13 +8,13 @@ source "${cfg[namespace]}/code/common.sh"
|
|||
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]}'"}}')
|
||||
|
||||
if [[ $(echo $data | jq .status) == "403" ]]; then
|
||||
echo $data | jq "{status: .status, error: .error}"
|
||||
echo $data | jq "{status: .status, msg: .error}"
|
||||
else
|
||||
uuid=$(echo $data | jq -r ".sessionUuid")
|
||||
data=$(curl -X POST -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid")
|
||||
if [[ $(echo $data | jq ".compartment") != "" ]]; then
|
||||
echo $data
|
||||
else
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args -1 "emptyPage"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "emptyPage"
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -4,8 +4,10 @@ if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
|
|||
login ${post_data[login]} ${post_data[password]}
|
||||
status=$?
|
||||
if [[ $status == 0 ]]; then
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args 200 "success"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
|
||||
elif [[ $status == 1 && $reason != '' ]]; then
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args -1 "$reason"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "$reason"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "Send me some credentials, dammit!"
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
logout
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "logged?? you?? out???? not sure, but probably"
|
|
@ -4,9 +4,9 @@ if [[ ${post_data[login]} != '' && ${post_data[password]} != '' && ${post_data[p
|
|||
register ${post_data[login]} ${post_data[password]}
|
||||
status=$?
|
||||
if [[ $status == 0 ]]; then
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args 200 "success"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
|
||||
curl -s "https://api-inmobile-pl.easypack24.net/v1/sendSMSCode/${post_data[phone]}" > /dev/null
|
||||
elif [[ $status == 1 && $reason != '' ]]; then
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args -1 "$reason"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "$reason"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
if ! session_verify ${cookies[sh_session]}; then
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args -1 "You're not logged in!"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "You're not logged in!"
|
||||
else
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args 200 ""
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "OK"
|
||||
fi
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@ if [[ ${post_data[phone]} != "" && ${post_data[code]} != "" ]]; then
|
|||
tokens=$(curl -s -X POST -H "Content-type: application/json" --data '{"phoneOS":"Android"}' "https://api-inmobile-pl.easypack24.net/v1/confirmSMSCode/${post_data[phone]}/${post_data[code]}")
|
||||
|
||||
if [[ $(echo $tokens | jq .status) == "404" ]]; then
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args -1 "wrongData"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "wrongData"
|
||||
else
|
||||
add_account_refreshtoken $(echo $tokens | jq -r .refreshToken)
|
||||
add_account_authtoken $(echo $tokens | jq -r .authToken)
|
||||
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args 200 "success"
|
||||
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>OCW</title>
|
||||
<title>Otwarty Czapkomat Webowy</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -74,6 +74,7 @@
|
|||
<div class="message-body">
|
||||
<div class="control">
|
||||
<a class="areyousure-button button is-danger">Open locker</a>
|
||||
<a class="areyousure-button-deny button">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -87,6 +88,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="package-list table-container">
|
||||
<div class="logout-button button">Log out</div>
|
||||
<table class="table is-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in New Issue