login flow now works ;) also small refactor
This commit is contained in:
parent
9496fe3cdc
commit
756a75d0aa
|
@ -26,16 +26,14 @@ const openLockerConfirm = (lat: string, lon: string, openCode: string, id: strin
|
||||||
id,
|
id,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.status != 200) {
|
if (res.status != 200) {
|
||||||
openError(res.description || res.error);
|
openError(res.description || res.msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const openLocker = (lat: string, lon: string, openCode: string, id: string) => {
|
const openLocker = (lat: string, lon: string, openCode: string, id: string) => {
|
||||||
(document.querySelector(".areyousure-box") as HTMLElement).style.display = "block";
|
(document.querySelector(".areyousure-box") as HTMLElement).style.display = "block";
|
||||||
document
|
(document.querySelector(".areyousure-button") as HTMLElement)!.onclick = () => { openLockerConfirm(lat, lon, openCode, id) };
|
||||||
.querySelector(".areyousure-button")!
|
|
||||||
.addEventListener("click", () => openLockerConfirm(lat, lon, openCode, id));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshPackages = () =>
|
const refreshPackages = () =>
|
||||||
|
@ -78,9 +76,26 @@ window.addEventListener("load", () => {
|
||||||
request("login", {
|
request("login", {
|
||||||
login: form.login.value,
|
login: form.login.value,
|
||||||
password: form.password.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")!;
|
const register = document.querySelector(".register-form")!;
|
||||||
register.addEventListener("submit", async (event) => {
|
register.addEventListener("submit", async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -97,7 +112,7 @@ window.addEventListener("load", () => {
|
||||||
);
|
);
|
||||||
(document.querySelector(".sms-box")! as HTMLDivElement).style.display = "block";
|
(document.querySelector(".sms-box")! as HTMLDivElement).style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
openError(res.description || res.error);
|
openError(res.description || res.msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -114,7 +129,7 @@ window.addEventListener("load", () => {
|
||||||
await refreshPackages();
|
await refreshPackages();
|
||||||
(document.querySelector(".package-list")! as HTMLDivElement).style.display = "block";
|
(document.querySelector(".package-list")! as HTMLDivElement).style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
openError(res.description || res.error);
|
openError(res.description || res.msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -124,6 +139,12 @@ window.addEventListener("load", () => {
|
||||||
errorBoxWindow.style.display = "none";
|
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) => {
|
request("session", {}).then((res) => {
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
// logged in
|
// 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]}'"}}')
|
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
|
if [[ $(echo $data | jq .status) == "403" ]]; then
|
||||||
echo $data | jq "{status: .status, error: .error}"
|
echo $data | jq "{status: .status, msg: .error}"
|
||||||
else
|
else
|
||||||
uuid=$(echo $data | jq -r ".sessionUuid")
|
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")
|
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
|
if [[ $(echo $data | jq ".compartment") != "" ]]; then
|
||||||
echo $data
|
echo $data
|
||||||
else
|
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
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -4,8 +4,10 @@ if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
|
||||||
login ${post_data[login]} ${post_data[password]}
|
login ${post_data[login]} ${post_data[password]}
|
||||||
status=$?
|
status=$?
|
||||||
if [[ $status == 0 ]]; then
|
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
|
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
|
else
|
||||||
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "Send me some credentials, dammit!"
|
||||||
|
fi
|
||||||
|
|
3
webroot/api/logout.shs
Normal file
3
webroot/api/logout.shs
Normal file
|
@ -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]}
|
register ${post_data[login]} ${post_data[password]}
|
||||||
status=$?
|
status=$?
|
||||||
if [[ $status == 0 ]]; then
|
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
|
curl -s "https://api-inmobile-pl.easypack24.net/v1/sendSMSCode/${post_data[phone]}" > /dev/null
|
||||||
elif [[ $status == 1 && $reason != '' ]]; then
|
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
|
fi
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if ! session_verify ${cookies[sh_session]}; then
|
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
|
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
|
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]}")
|
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
|
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
|
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], error: $ARGS.positional[1]}' --args 200 "success"
|
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args 200 "success"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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" />
|
<link rel="stylesheet" href="assets/style.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -74,6 +74,7 @@
|
||||||
<div class="message-body">
|
<div class="message-body">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<a class="areyousure-button button is-danger">Open locker</a>
|
<a class="areyousure-button button is-danger">Open locker</a>
|
||||||
|
<a class="areyousure-button-deny button">Cancel</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -87,6 +88,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="package-list table-container">
|
<div class="package-list table-container">
|
||||||
|
<div class="logout-button button">Log out</div>
|
||||||
<table class="table is-striped">
|
<table class="table is-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in a new issue