forked from MapComplete/MapComplete
		
	Fix #271: url parameters (and thus location, selected feature, ...) are preserved when logging in
This commit is contained in:
		
							parent
							
								
									cd4a2608a2
								
							
						
					
					
						commit
						c367bef4c1
					
				
					 1 changed files with 37 additions and 33 deletions
				
			
		|  | @ -30,49 +30,22 @@ export class OsmConnection { | ||||||
|     public changesetHandler: ChangesetHandler; |     public changesetHandler: ChangesetHandler; | ||||||
| 
 | 
 | ||||||
|     private _onLoggedIn: ((userDetails: UserDetails) => void)[] = []; |     private _onLoggedIn: ((userDetails: UserDetails) => void)[] = []; | ||||||
|  |     private readonly _iframeMode: Boolean | boolean; | ||||||
|  |     private readonly _singlePage: boolean; | ||||||
| 
 | 
 | ||||||
|     constructor(dryRun: boolean, oauth_token: UIEventSource<string>, |     constructor(dryRun: boolean, oauth_token: UIEventSource<string>, | ||||||
|                 // Used to keep multiple changesets open and to write to the correct changeset
 |                 // Used to keep multiple changesets open and to write to the correct changeset
 | ||||||
|                 layoutName: string, |                 layoutName: string, | ||||||
|                 singlePage: boolean = true) { |                 singlePage: boolean = true) { | ||||||
| 
 |         this._singlePage = singlePage; | ||||||
|         let pwaStandAloneMode = false; |         this._iframeMode = window !== window.top; | ||||||
|         try { |  | ||||||
|             if (window.matchMedia('(display-mode: standalone)').matches || window.matchMedia('(display-mode: fullscreen)').matches) { |  | ||||||
|                 pwaStandAloneMode = true; |  | ||||||
|             } |  | ||||||
|         } catch (e) { |  | ||||||
|             console.warn("Detecting standalone mode failed", e, ". Assuming in browser and not worrying furhter") |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const iframeMode = window !== window.top; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|         if (iframeMode || pwaStandAloneMode || !singlePage) { |  | ||||||
|             // In standalone mode, we DON'T use single page login, as 'redirecting' opens a new window anyway...
 |  | ||||||
|             // Same for an iframe...
 |  | ||||||
|             this.auth = new osmAuth({ |  | ||||||
|                 oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem', |  | ||||||
|                 oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI', |  | ||||||
|                 singlepage: false, |  | ||||||
|                 auto: true, |  | ||||||
|             }); |  | ||||||
|         } else { |  | ||||||
| 
 |  | ||||||
|             this.auth = new osmAuth({ |  | ||||||
|                 oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem', |  | ||||||
|                 oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI', |  | ||||||
|                 singlepage: true, |  | ||||||
|                 landing: window.location.href, |  | ||||||
|                 auto: true, |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
|         this.userDetails = new UIEventSource<UserDetails>(new UserDetails(), "userDetails"); |         this.userDetails = new UIEventSource<UserDetails>(new UserDetails(), "userDetails"); | ||||||
|         this.userDetails.data.dryRun = dryRun; |         this.userDetails.data.dryRun = dryRun; | ||||||
|         this._dryRun = dryRun; |         this._dryRun = dryRun; | ||||||
|          |          | ||||||
|  |         this.updateAuthObject(); | ||||||
|  | 
 | ||||||
|         this.preferencesHandler = new OsmPreferences(this.auth, this); |         this.preferencesHandler = new OsmPreferences(this.auth, this); | ||||||
| 
 | 
 | ||||||
|         this.changesetHandler = new ChangesetHandler(layoutName, dryRun, this, this.auth); |         this.changesetHandler = new ChangesetHandler(layoutName, dryRun, this, this.auth); | ||||||
|  | @ -95,6 +68,36 @@ export class OsmConnection { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     private updateAuthObject(){ | ||||||
|  |         let pwaStandAloneMode = false; | ||||||
|  |         try { | ||||||
|  |             if (window.matchMedia('(display-mode: standalone)').matches || window.matchMedia('(display-mode: fullscreen)').matches) { | ||||||
|  |                 pwaStandAloneMode = true; | ||||||
|  |             } | ||||||
|  |         } catch (e) { | ||||||
|  |             console.warn("Detecting standalone mode failed", e, ". Assuming in browser and not worrying furhter") | ||||||
|  |         } | ||||||
|  |         if (this._iframeMode || pwaStandAloneMode || !this._singlePage) { | ||||||
|  |             // In standalone mode, we DON'T use single page login, as 'redirecting' opens a new window anyway...
 | ||||||
|  |             // Same for an iframe...
 | ||||||
|  |             this.auth = new osmAuth({ | ||||||
|  |                 oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem', | ||||||
|  |                 oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI', | ||||||
|  |                 singlepage: false, | ||||||
|  |                 auto: true, | ||||||
|  |             }); | ||||||
|  |         } else { | ||||||
|  | 
 | ||||||
|  |             this.auth = new osmAuth({ | ||||||
|  |                 oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem', | ||||||
|  |                 oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI', | ||||||
|  |                 singlepage: true, | ||||||
|  |                 landing: window.location.href, | ||||||
|  |                 auto: true, | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|     public UploadChangeset( |     public UploadChangeset( | ||||||
|         layout: LayoutConfig, |         layout: LayoutConfig, | ||||||
|  | @ -129,6 +132,7 @@ export class OsmConnection { | ||||||
|     public AttemptLogin() { |     public AttemptLogin() { | ||||||
|         const self = this; |         const self = this; | ||||||
|         console.log("Trying to log in..."); |         console.log("Trying to log in..."); | ||||||
|  |         this.updateAuthObject(); | ||||||
|         this.auth.xhr({ |         this.auth.xhr({ | ||||||
|             method: 'GET', |             method: 'GET', | ||||||
|             path: '/api/0.6/user/details' |             path: '/api/0.6/user/details' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue