[horde] update preferences cache

Aleksey Chudov aleksey at bb.lv
Thu Nov 27 21:19:39 UTC 2008


Hello!

My users authenticates with user names without domain part.
So they can't send messages because default "from address" is without 
domain name.
I can't just add default domain to user name because some users have 
different "from address" and user name.
I found article http://wiki.horde.org/CustomizingPreferences
I take _horde_hook_postauthenticate for lookup and setting "from 
address" for each user.
I'm not php programmer, so if someone can check for mistakes it will be 
grate.
And another question. How to update preferences cache without logout?
May be there is better solution?

------------------------------------------------------------------------------------ 


<?php

require_once 'MDB2.php';
require_once 'Horde/Identity.php';

if (!function_exists('_get_from_address')) {
   function _get_from_address($userID)
   {
       $dsn = array(
           'phptype'  => $GLOBALS['conf']['auth']['params']['phptype'],
           'username' => $GLOBALS['conf']['auth']['params']['username'],
           'password' => $GLOBALS['conf']['auth']['params']['password'],
           'hostspec' => $GLOBALS['conf']['auth']['params']['hostspec'],
           'database' => $GLOBALS['conf']['auth']['params']['database'],
       );

       $_db = &MDB2::singleton($dsn);
       if(PEAR::isError($_db)) {
           die($_db->getMessage());
       }

       $name = "$userID";

       $query = "SELECT alias FROM virtual WHERE username = " . 
$_db->quote($name);
       $res = $_db->query($query);
       if(PEAR::isError($res)) {
           die($res->getMessage());
       }

       while($row = $res->fetchRow()) {
               $mail = $row[0];
       }
       return $mail;
   }
}

if (!function_exists('_horde_hook_postauthenticate')) {
   function _horde_hook_postauthenticate($userID, $credential, $realm)
   {
       $name = "$userID";

       if (is_null($name)) {
           $name = Auth::getAuth();
       }

       if (!empty($name)) {
           $users_identities = &Identity::singleton('none',"$name");
           $users_identities->init();
           $users_identity_default_from_addr = 
$users_identities->getValue('from_addr');

           if (empty($users_identity_default_from_addr)) {

               $mail = _get_from_address($name);

               if (!empty($mail)) {
                   // store default identity changes
                   $users_identities->setValue('from_addr',"$mail");
                   $users_identities->save();
               }
           } else {
               $mail = "$users_identity_default_from_addr";
           }
           // If no email address is found, then the login name will be 
used
           return (empty($mail) ? '' : $mail);
       }
       return '';
   }
}

------------------------------------------------------------------------------------ 








More information about the horde mailing list