You need to create a new ACL file:
root@er-x:~# cat /usr/share/rpcd/acl.d/allow-session-access.json
{
"allow-session-access": {
"description": "Allow access to login session information",
"read": {
"ubus": {
"session": [ "get" ]
}
}
}
}
Then, in the ui views you can do:
"require rpc";
var callSessionGet = rpc.declare({
object: "session",
method: "get",
reject: true,
expect: {
values: {}
}
});
callSessionGet().then(function(res) {
alert("Logged in username is: " + res.username);
});
Alternatively you can determine the name on the server side, e.g. in .htm, templates:
<p>
The current username is:
<strong><%= luci.dispatcher.context.authuser %></strong>
</p>
You could also add it to the global client side LuCI environment:
diff --git a/modules/luci-base/luasrc/view/header.htm b/modules/luci-base/luasrc/view/header.htm
index cffe9482ca..3f563d0af1 100644
--- a/modules/luci-base/luasrc/view/header.htm
+++ b/modules/luci-base/luasrc/view/header.htm
@@ -25,6 +25,7 @@
documentroot = luci.http.getenv("DOCUMENT_ROOT"),
requestpath = luci.dispatcher.context.requestpath,
dispatchpath = luci.dispatcher.context.path,
+ username = luci.dispatcher.context.authuser,
pollinterval = luci.config.main.pollinterval or 5,
ubuspath = luci.config.main.ubuspath or '/ubus/',
sessionid = luci.dispatcher.context.authsession,
... and query it in views using L.env.username
:
alert("The currently logged in user is: " + L.env.username);