[horde] USERNAME Hook - help required.

Jan Schneider jan at horde.org
Fri Aug 16 09:52:03 UTC 2013


Zitat von ANANT S ATHAVALE <asa at isac.gov.in>:

> ----- Message from Jan Schneider <jan at horde.org> ---------
>    Date: Fri, 16 Aug 2013 10:57:44 +0200
>    From: Jan Schneider <jan at horde.org>
> Subject: Re: [horde] USERNAME Hook - help required.
>      To: horde at lists.horde.org
>
>
>> Zitat von ANANT S ATHAVALE <asa at isac.gov.in>:
>>
>>> ----- Message from Jan Schneider <jan at horde.org> ---------
>>>  Date: Fri, 16 Aug 2013 09:44:46 +0200
>>>  From: Jan Schneider <jan at horde.org>
>>> Subject: Re: [horde] USERNAME Hook - help required.
>>>    To: horde at lists.horde.org
>>>
>>>
>>>> Zitat von ANANT S ATHAVALE <asa at isac.gov.in>:
>>>>
>>>>> Dear List,
>>>>>
>>>>> My authentication is based on LDAP which is case insensitive.  I  
>>>>> want username to be always lower case and also if there any  
>>>>> blank space (either at starting or trailing to be trimmed)
>>>>>
>>>>> I have written the hook as below.  Please suggest, if it is wrong:
>>>>>
>>>>> public function authusername($userId, $toHorde)
>>>>> {
>>>>>     return $toHorde
>>>>>         ? trim(Horde_String::lower($userId) . '@isac.gov.in')
>>>>>         : trim($userId) . '@isac.gov.in';
>>>>> }
>>>>>
>>>>> I want basically that the preferences to be stored with  
>>>>> username at isac.gov.in, where username should be always in lower  
>>>>> case and it should not have any space characters.
>>>>>
>>>>> Please suggest.
>>>>
>>>> It also adds the domain part, not sure if this is intended.
>>>
>>> This is intended as in my Horde 3 setup, all users preferences are  
>>> already stored in the form 'username at domain'.
>>>
>>>>
>>>> More important though is the reverse direction, which you have  
>>>> wrong. The trim() is no longer necessary because you already  
>>>> trimmed in the other direction. And you have to *remove* the  
>>>> domain part, not add them another time.
>>>
>>> OK.
>>>
>>> Will the following hook be OK?
>>>
>>>   public function authusername($userId, $toHorde)
>>>   {
>>>       return $toHorde
>>>           ? trim(Horde_String::lower($userId)) . '@isac.gov.in'
>>>           : $userId;
>>>   }
>>
>> Not quite, you still need to strip the domain part from the name in  
>> the 2nd case. See the examples in hooks.php.dist how to do this.
>> -- 
>> Jan Schneider
>> The Horde Project
>> http://www.horde.org/
>>
>> -- 
>> Horde mailing list
>> Frequently Asked Questions: http://horde.org/faq/
>> To unsubscribe, mail: horde-unsubscribe at lists.horde.org
>
>
> ----- End message from Jan Schneider <jan at horde.org> -----
> Thanks a lot.  I have re-written based on examples in hooks.php.dist  
> and I hope the following should be correct.
>
>     public function authusername($userId, $toHorde)
>     {
>         $vdomain = 'isac.gov.in';
>         if ($toHorde) {
>            return trim(Horde_String::lower($userId)) . '@' . $vdomain;
>         }
>
>         return (substr($userId, -strlen($vdomain)) == $vdomain)
>             ? substr($userId, 0, -strlen($vdomain) - 1)
>             : $userId;
>     }
>
> Only doubt is with trimming.  I am trimming in (toHorde), but not  
> untrimming in else case.
>
> Why I need to trim is, I have seen some preferences are getting  
> stored as asa @isac.gov.in, instead of asa at isac.gov.in, when a user  
> logs in with a blank space at the end of user id 'asa'.

This is done in the first case. The second case is for converting  
internal Horde user names back to the format displayed in the UI.  
Since you already trimmed the user names when converting *to* Horde,  
they are already trimmed when converting those back *from* Horde.
-- 
Jan Schneider
The Horde Project
http://www.horde.org/



More information about the horde mailing list