Subject: The mailing list for listmasters using Sympa
List archive
Re: [sympa-users] access to user attributes in tt2
- From: Etienne MELEARD <address@concealed>
- To: address@concealed
- Subject: Re: [sympa-users] access to user attributes in tt2
- Date: Wed, 12 Jan 2022 16:42:08 +0100
Hello,
You could use a TT2 plugin like follows.
Perl package under /your/sympa/root/lib/Sympa/Template/Plugin/MyLDAPQuery.pm :
#!/usr/bin/perl
package Sympa::Template::Plugin::MyLDAPQuery;
use base qw( Template::Plugin );
use Template::Plugin;
# Called as Sympa::Template::Plugin::MyLDAPQuery->load($context)
# by TT2 engine
sub load {
my ($class, $context) = @_;
return $class;
}
# Called as Sympa::Template::Plugin::MyLDAPQuery->new($context, @params)
# when using [% USE MyLDAPQuery(param1, param2, ...) %] in TT2 template
sub new {
my ($class, $context, @params) = @_;
my $stash = $context->stash();
my $self = {};
# Initialisation here
bless $self, $class;
return $self;
}
# Hande affiliations query
sub getAffiliations {
my ($self, $user) = @_;
# LDAP search here
my @affiliations = ...
return [ @affiliations ];
}
# Package must return trueish value
1;
TT2 syntax tu use in your template(s) :
[% TRY %]
[% USE MyLDAPQuery %]
<ul>
[% FOREACH affiliation IN MyLDAPQuery.getAffiliations("${session.email}") %]
<li>[% affiliation %]</li>
[% END %]
</ul>
[% CATCH %]
<p class="error">LDAP query failed : [% error.info %]</p>
[% END %]
Hello,
I would do a query like this one
ldapsearch -x -D "cn=My_CN_account" -b "my_dc" -H ldaps://myhost:myport -W "(mail=myuser@mydomain" eduPersonPrimaryAffiliation
Thanks
Envoyé : lundi 10 janvier 2022 18:09:04
À : address@concealed
Objet : Re: [sympa-users] access to user attributes in tt2
> thanks for your answer, it works!
>
> for my second question I have an ldap conf in my auth.conf( not in my sympa.conf...)
>
> Is there a possibility to automatically do an ldap query in a tt2 template?
>
>
> Thanks
Hello,
what kind of LDAP query to you have a mind?
Regards
Racke
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *De :* address@concealed <address@concealed> de la part de Stefan Hornburg (Racke) <address@concealed>
> *Envoyé :* lundi 10 janvier 2022 16:38:49
> *À :* address@concealed
> *Objet :* Re: [sympa-users] access to user attributes in tt2
> On 10/01/2022 15:52, Jerome Pouilloux wrote:
>> Hi,
>> first of all, happy new year to every one.
>> I'm trying to get attributes from user in a tt2 template to check the value.
>> To do that, I have filled the field `attributes_user` in the table `user_table`
>> in my tt2 I have tried to do
>> [% IF user %]
>> [% FOREACH vuser IN user.attributes %]
>> [% vuser %]
>> [% END %]
>> [% END %]
>> but the result is an hash who changes every time I refresh the page example:HASH(0xd4442a0), HASH(0x790f858).
>> What am I missing?
>
> user.attributes is a hash and not an array.
>
> http://www.template-toolkit.org/docs/manual/VMethods.html#section_keys <http://www.template-toolkit.org/docs/manual/VMethods.html#section_keys>
>
>> Furthermore, is there a possibility to check a value directly in the ldap configured in sympa.conf?
>>
>
> Please elaborate how you configure LDAP in sympa.conf.
>
> Regards
> Racke
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration.
>
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature
-
[sympa-users] access to user attributes in tt2,
Jerome Pouilloux, 01/10/2022
-
Re: [sympa-users] access to user attributes in tt2,
Stefan Hornburg (Racke), 01/10/2022
-
RE: [sympa-users] access to user attributes in tt2,
Jerome Pouilloux, 01/10/2022
-
Re: [sympa-users] access to user attributes in tt2,
Stefan Hornburg (Racke), 01/10/2022
-
RE: [sympa-users] access to user attributes in tt2,
Jerome Pouilloux, 01/11/2022
- Re: [sympa-users] access to user attributes in tt2, Etienne MELEARD, 01/12/2022
-
RE: [sympa-users] access to user attributes in tt2,
Jerome Pouilloux, 01/11/2022
-
Re: [sympa-users] access to user attributes in tt2,
Stefan Hornburg (Racke), 01/10/2022
-
RE: [sympa-users] access to user attributes in tt2,
Jerome Pouilloux, 01/10/2022
-
Re: [sympa-users] access to user attributes in tt2,
Stefan Hornburg (Racke), 01/10/2022
Archive powered by MHonArc 2.6.19+.