On Tuesday, November 10, 2020, 3:42:35 PM GMT+1, Nick Couchman
<[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.
OK, but I'm trying to find out how to do this. I have no AngularJS experience.
# cat customDirective.js
angular.module('customModule').directive('customDirective', function () {
return {
template: // do something here to getCurrentUsername()
};
});
# cat guac-manifest.json
{
"guacamoleVersion" : "*",
"name" : "Custom URLs",
"namespace" : "customurls",
"js" : "customDirective.js",
"html" : [
"Note.html",
"CustomURLs.html"
]
}
My custom htmls can then include something like <div custom-directive></div>.
Maybe I could take a snippet of code from guacamole.js to work on?
Any suggestions?
Vieri
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]