Commit b227bea8 authored by Jan Koester's avatar Jan Koester
Browse files

editor: nach der Anmeldung auf die angeforderte Seite

401-Umleitungen in api.js geben die aktuelle Seite als ?next= an
login.html; nach dem Login geht es dorthin (nur lokale Pfade), bzw. auf
dieselbe URL, wenn der Server login.html an Stelle von index.html liefert.
Ersetzt die Sonderbehandlung nur fuer ?document=.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 711e5003
Loading
Loading
Loading
Loading
+10 −4
Changes for editor/html/js/api.js: 10 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,12 @@
var EditorApi = (function() {
    'use strict';

    // Not authenticated: to the login page, which returns here afterwards (?next=)
    function toLogin() {
        window.location.href = 'login.html?next=' +
            encodeURIComponent(location.pathname + location.search + location.hash);
    }

    function request(method, url, data) {
        return new Promise(function(resolve, reject) {
            var xhr = new XMLHttpRequest();
@@ -18,7 +24,7 @@ var EditorApi = (function() {
                if (xhr.readyState !== 4) return;
                if (xhr.status === 401) {
                    // Not authenticated — redirect to login
                    window.location.href = 'login.html';
                    toLogin();
                    return;
                }
                if (xhr.status >= 200 && xhr.status < 300) {
@@ -54,7 +60,7 @@ var EditorApi = (function() {
            if (contentType) xhr.setRequestHeader('Content-Type', contentType);
            xhr.onreadystatechange = function() {
                if (xhr.readyState !== 4) return;
                if (xhr.status === 401) { window.location.href = 'login.html'; return; }
                if (xhr.status === 401) { toLogin(); return; }
                if (xhr.status >= 200 && xhr.status < 300) {
                    try { resolve(JSON.parse(xhr.responseText)); } catch(e) { resolve(xhr.responseText); }
                } else {
@@ -76,7 +82,7 @@ var EditorApi = (function() {
            xhr.onreadystatechange = function() {
                if (xhr.readyState !== 4) return;
                if (xhr.status === 401) {
                    window.location.href = 'login.html';
                    toLogin();
                    return;
                }
                if (xhr.status >= 200 && xhr.status < 300) {
@@ -328,7 +334,7 @@ var EditorApi = (function() {
                signal: controller.signal
            }).then(function(response) {
                if (response.status === 401) {
                    window.location.href = 'login.html';
                    toLogin();
                    throw { error: 'Not authenticated' };
                }
                if (!response.ok) {
+8 −6
Changes for editor/html/login.html: 8 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -209,12 +209,14 @@
                if (xhr.status === 200) {
                    // Navigate to the mount root (the <base href>), not the
                    // domain root, so we stay inside the /editor prefix.
                    // Keep a deep link (?document=<id>): the server serves this page in
                    // place of index.html for unauthenticated requests to /?document=...
                    var next = document.baseURI.split('?')[0].split('#')[0], docId = '';
                    try { docId = new URLSearchParams(location.search).get('document') || ''; } catch(ex) {}
                    if (/^[A-Za-z0-9_-]{1,128}$/.test(docId)) next += '?document=' + encodeURIComponent(docId);
                    window.location.href = next;
                    // Back to the requested page: ?next=<local path> (set by the 401
                    // redirect in api.js), or -- when the server served this page in
                    // place of index.html, e.g. for /?document=<id> -- the same URL.
                    var base = document.baseURI.split('?')[0].split('#')[0], next = '';
                    try { next = new URLSearchParams(location.search).get('next') || ''; } catch(ex) {}
                    if (!/^\/(?![\/\\])[^\x00-\x1f\\]*$/.test(next) || /login\.html/.test(next.split('?')[0])) next = '';
                    if (!next && !/login\.html$/.test(location.pathname)) next = location.pathname + location.search + location.hash;
                    window.location.href = next || base;
                } else {
                    try {
                        var resp = JSON.parse(xhr.responseText);