luci-base: dispatcher: add login indication on 403 errors
authorJo-Philipp Wich <jo@mein.io>
Fri, 16 Nov 2018 18:33:39 +0000 (19:33 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 16 Nov 2018 20:11:34 +0000 (21:11 +0100)
Send a custom LuCI X-Header to indicate that a login is required to access
the requested resource. This is mainly intended for xhr.js to be able to
intercept such responses and popup an authentication dialog.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/luasrc/dispatcher.lua

index 1e610e748919edd1601e5026ea12f62755b3bfe9..c4066a25920c26ff2c9d7113405096866238bcff 100644 (file)
@@ -417,6 +417,7 @@ function dispatch(request)
                                context.path = {}
 
                                http.status(403, "Forbidden")
+                               http.header("X-LuCI-Login-Required", "yes")
                                tmpl.render(track.sysauth_template or "sysauth", {
                                        duser = default_user,
                                        fuser = user
@@ -433,6 +434,7 @@ function dispatch(request)
 
                if not sid or not sdat then
                        http.status(403, "Forbidden")
+                       http.header("X-LuCI-Login-Required", "yes")
                        return
                end