From 4a85fa82c3334cfd92064d25f82d07a4c0e0d0da Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 29 Jul 2020 21:32:51 +0200 Subject: [PATCH] Fixed single page login for a certain poor Simon with a weird browser --- Customizations/AllKnownLayouts.ts | 1 - Customizations/TagRendering.ts | 2 -- Logic/OsmConnection.ts | 43 +++++++++++++++++++++++-------- UI/Base/SubtleButton.ts | 8 +++--- UI/MoreScreen.ts | 2 +- UI/SimpleAddUI.ts | 2 +- index.ts | 12 ++++----- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/Customizations/AllKnownLayouts.ts b/Customizations/AllKnownLayouts.ts index 251679f..249e884 100644 --- a/Customizations/AllKnownLayouts.ts +++ b/Customizations/AllKnownLayouts.ts @@ -37,7 +37,6 @@ export class AllKnownLayouts { const knownKeys = [] for (const layout of layouts) { for (const layer of layout.layers) { - console.log("Adding ", Translations.W(layer.name).InnerRender()); const key = layer.overpassFilter.asOverpass().join(""); if (knownKeys.indexOf(key) >= 0) { continue; diff --git a/Customizations/TagRendering.ts b/Customizations/TagRendering.ts index c1fe661..a111a46 100644 --- a/Customizations/TagRendering.ts +++ b/Customizations/TagRendering.ts @@ -365,8 +365,6 @@ class TagRendering extends UIElement implements TagDependantUIElement { .split("$"); const type = prepost[1]; - console.log("PrePost:", prepost); - let isValid = TagRenderingOptions.inputValidation[type]; if (isValid === undefined) { isValid = (str) => true; diff --git a/Logic/OsmConnection.ts b/Logic/OsmConnection.ts index a0e2b8d..920770b 100644 --- a/Logic/OsmConnection.ts +++ b/Logic/OsmConnection.ts @@ -17,33 +17,54 @@ export class UserDetails { export class OsmConnection { - private auth = new osmAuth({ - oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem', - oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI', - auto: true // show a login form if the user is not authenticated and - // you try to do a call - }); + public auth; public userDetails: UIEventSource; private _dryRun: boolean; - constructor(dryRun: boolean) { + constructor(dryRun: boolean, oauth_token: UIEventSource) { + + this.auth = new osmAuth({ + oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem', + oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI', + oauth_token: oauth_token.data, + singlepage: true, + landing: "./index.html", + auto: true // show a login form if the user is not authenticated and + // you try to do a call + + }); + + this.userDetails = new UIEventSource(new UserDetails()); this.userDetails.data.osmConnection = this; this.userDetails.data.dryRun = dryRun; this._dryRun = dryRun; - + + if(oauth_token.data !== undefined){ + console.log(oauth_token.data) + const self = this; + this.auth.bootstrapToken(oauth_token.data, + (x) => { + console.log("Called back: ", x) + self.AttemptLogin(); + }, this.auth); + + oauth_token.setData(undefined); + + } if (this.auth.authenticated()) { this.AttemptLogin(); // Also updates the user badge - }else{ + } else { console.log("Not authenticated"); } - - if(dryRun){ + + if (dryRun) { console.log("DRYRUN ENABLED"); } + } public LogOut() { diff --git a/UI/Base/SubtleButton.ts b/UI/Base/SubtleButton.ts index 757fd3a..0234d6a 100644 --- a/UI/Base/SubtleButton.ts +++ b/UI/Base/SubtleButton.ts @@ -7,21 +7,21 @@ import {link} from "fs"; export class SubtleButton extends UIElement{ private imageUrl: string; private message: UIElement; - private linkTo: string = undefined; + private linkTo: { url: string, newTab?: boolean } = undefined; - constructor(imageUrl: string, message: string | UIElement, linkTo : string = undefined) { + constructor(imageUrl: string, message: string | UIElement, linkTo: { url: string, newTab?: boolean } = undefined) { super(undefined); this.linkTo = linkTo; this.message = Translations.W(message); this.imageUrl = imageUrl; - + } InnerRender(): string { if(this.linkTo != undefined){ return new Combine([ - ``, + ``, this.imageUrl !== undefined ? `` : "", this.message, '' diff --git a/UI/MoreScreen.ts b/UI/MoreScreen.ts index 58764fa..5d49f2e 100644 --- a/UI/MoreScreen.ts +++ b/UI/MoreScreen.ts @@ -44,7 +44,7 @@ export class MoreScreen extends UIElement { "", "
", Translations.W(layout.description), - ]), linkText); + ]), {url: linkText, newTab: false}); els.push(link) } diff --git a/UI/SimpleAddUI.ts b/UI/SimpleAddUI.ts index a8cbff0..61ede4e 100644 --- a/UI/SimpleAddUI.ts +++ b/UI/SimpleAddUI.ts @@ -36,7 +36,7 @@ export class SimpleAddUI extends UIElement { private confirmButton: UIElement = undefined; private cancelButton: UIElement; private goToInboxButton: UIElement = new SubtleButton("/assets/envelope.svg", - Translations.t.general.goToInbox, "https://www.openstreetmap.org/messages/inbox"); + Translations.t.general.goToInbox, {url:"https://www.openstreetmap.org/messages/inbox", newTab: false}); constructor(zoomlevel: UIEventSource<{ zoom: number }>, lastClickLocation: UIEventSource<{ lat: number, lon: number }>, diff --git a/index.ts b/index.ts index 36d5404..a209c90 100644 --- a/index.ts +++ b/index.ts @@ -128,15 +128,15 @@ const locationControl = new UIEventSource<{ lat: number, lon: number, zoom: numb locationControl.addCallback((latlonz) => { zoom.setData(latlonz.zoom.toString()); - lat.setData(latlonz.lat.toString().substr(0,6)); - lon.setData(latlonz.lon.toString().substr(0,6)); + lat.setData(latlonz.lat.toString().substr(0, 6)); + lon.setData(latlonz.lon.toString().substr(0, 6)); }) // ----------------- Prepare the important objects ----------------- - -const osmConnection = new OsmConnection( - QueryParameters.GetQueryParameter("test", "false").data === "true" +const osmConnection: OsmConnection = new OsmConnection( + QueryParameters.GetQueryParameter("test", "false").data === "true", + QueryParameters.GetQueryParameter("oauth_token", undefined) ); @@ -222,7 +222,7 @@ for (const layer of layoutToUse.layers) { tags[k] = tag.value; } } - preset.icon = layer.style(tags).icon.iconUrl; + preset.icon = layer.style(tags)?.icon?.iconUrl; } const addButton = {