On Tue, Nov 10, 2020 at 8:12 AM Vieri <[email protected]> wrote:
> > > On Tuesday, November 10, 2020, 11:38:23 AM GMT+1, Vieri > <[email protected]> wrote: > > >>> Is there a way to get the authenticated username in any of these > custom pages? > >>> Something like ${GUAC_USERNAME} in a custom .html file? > >> > >> Yes, by invoking authenticationService.getCurrentUsername(): > >> > >> > https://github.com/apache/guacamole-client/blob/43f8cc0400266288a70448ad7ddc12b10734c83f/guacamole/src/main/webapp/app/auth/service/authenticationService.js#L317-L335 > >> > >> To do that from within a template that you've patched, you would need > to create an AngularJS directive that handles invoking that function and > rendering the result. > > > > So it's not as simple as writing this in my custom HTML file, is it? > > > > <div ng-app="" > ng-init="test='test';name=authenticationService.getCurrentUsername()"> > > <p>Test: <input type="text" ng-model="test"></p> > > <p>Echo Test: {{ test }}</p> > > <p>Name: <input type="text" ng-model="name"></p> > > <p>Echo Name: {{ name }}</p> > > </div> > > > > The 'test' variable works, the 'name' variable however doesn't. I'm a > rookie in this domain so any suggestions/tips are greatly appreciated. > > What I mean by "doesn't work" is that the 'name' variable is empty, but I > did authenticate via LDAP extension. > > I believe this is because "authenticationService" is not in scope when you try to call it in here in this HTML snippet. That's why Mike mentioned that writing a proper AngularJS directive is the way to go - it will allow you to use the AngularJS injector to pull the required services into scope so that you can use them like this. It may not be the fastest way to accomplish what you're trying to do, but it is the correct way. -Nick
