add "get all from profile" feature
This commit is contained in:
@@ -21,6 +21,29 @@ function correlationId() {
|
||||
return crypto.randomUUID() + "_" + crypto.randomUUID()
|
||||
}
|
||||
|
||||
async function getKundenkontoV2(){
|
||||
let tok = await getAuthToken();
|
||||
let req = await fetch("https://www.bahn.de/web/api/kundenkonto/v2", {
|
||||
headers: [
|
||||
["Accept", "application/json"], ["authorization", "Bearer " + tok], //["X-Correlation-ID", correlationId()]
|
||||
]
|
||||
});
|
||||
if(req.ok){
|
||||
const data = await req.json();
|
||||
return {
|
||||
"addr__appellation": data.anrede,
|
||||
"addr__firstName": data.vorname,
|
||||
"addr__surName": data.nachname,
|
||||
"bday": data.geburtsdatum,
|
||||
"addr__email": data.email,
|
||||
"addr__placename": data.hauptadresse.ort,
|
||||
"addr__postcode": data.hauptadresse.plz,
|
||||
"addr__street": data.hauptadresse.strasse
|
||||
}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
async function getBahncardInfo() {
|
||||
let tok = await getAuthToken();
|
||||
let req = await fetch("https://www.bahn.de/web/api/kundenkonto/bahncard", {
|
||||
@@ -46,16 +69,25 @@ async function getBahncardInfo() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
browser.storage.sync.get("acquireBahncard").then(v => {
|
||||
browser.storage.sync.get(["acquireAll","acquireBahncard"]).then(v => {
|
||||
if (v.acquireAll!=false){
|
||||
Promise.all([getKundenkontoV2(), getBahncardInfo()]).then(data => {
|
||||
const saveData = {...data[0], "bcnum": data[1]};
|
||||
console.log("Saving", saveData);
|
||||
browser.storage.sync.set(saveData).then(()=>{
|
||||
alert("Saved all available data to settings.\nPlease enter your bank details on the bottom of the settings page.");
|
||||
window.close();
|
||||
})
|
||||
})
|
||||
}
|
||||
if (v.acquireBahncard != false) { // may also be undefined, so no identity check here
|
||||
getBahncardInfo().then(v => {
|
||||
if (!!v && v.length == 16) {
|
||||
const saveData = { "bcnum": v, "acquireBahncard": false }
|
||||
console.log("Saving", saveData);
|
||||
browser.storage.sync.set(saveData).then(success => {
|
||||
if (window !== window.top) {
|
||||
window.close();
|
||||
}
|
||||
browser.storage.sync.set(saveData).then(() => {
|
||||
alert("Saved your BahnCard number to settings.\nReload the settings page to continue.");
|
||||
window.close();
|
||||
});
|
||||
}
|
||||
}, f => console.log("Could not acquire BahnCard number.", f))
|
||||
|
Reference in New Issue
Block a user