Changeset 2157 in subversion


Ignore:
Timestamp:
Dec 16, 2008 10:28:07 AM (4 years ago)
Author:
thomasb
Message:

Simplify code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_ldap.php

    r2127 r2157  
    6969  function connect() 
    7070  { 
     71    global $RCMAIL; 
     72     
    7173    if (!function_exists('ldap_connect')) 
    7274      raise_error(array('type' => 'ldap', 'message' => "No ldap support in this installation of PHP"), true); 
     
    100102      $this->ready = true; 
    101103 
     104      // User specific access, generate the proper values to use. 
    102105      if ($this->prop["user_specific"]) { 
    103         // User specific access, generate the proper values to use. 
    104         global $CONFIG, $RCMAIL; 
     106        // No password set, use the session password 
    105107        if (empty($this->prop['bind_pass'])) { 
    106           // No password set, use the users. 
    107108          $this->prop['bind_pass'] = $RCMAIL->decrypt_passwd($_SESSION["password"]); 
    108         } // end if 
     109        } 
    109110 
    110111        // Get the pieces needed for variable replacement. 
    111         // See if the logged in username has an "@" in it. 
    112         if (is_bool(strstr($_SESSION["username"], "@"))) { 
    113           // It does not, use the global default. 
    114           $fu = $_SESSION["username"]."@".$CONFIG["username_domain"]; 
    115           $u = $_SESSION["username"]; 
    116           $d = $CONFIG["username_domain"]; 
    117         } // end if 
    118         else { 
    119           // It does. 
    120           $fu = $_SESSION["username"]; 
    121           // Get the pieces needed for username and domain. 
    122           list($u, $d) = explode("@", $_SESSION["username"]); 
    123         } # end else 
    124  
    125         // Replace the bind_dn variables. 
    126         $bind_dn = str_replace(array("%fu", "%u", "%d"), 
    127                                array($fu, $u, $d), 
    128                                $this->prop['bind_dn']); 
    129         $this->prop['bind_dn'] = $bind_dn; 
    130         // Replace the base_dn variables. 
    131         $base_dn = str_replace(array("%fu", "%u", "%d"), 
    132                                array($fu, $u, $d), 
    133                                $this->prop['base_dn']); 
    134         $this->prop['base_dn'] = $base_dn; 
    135  
    136         $this->ready = $this->bind($this->prop['bind_dn'], $this->prop['bind_pass']); 
    137       } // end if 
    138       elseif (!empty($this->prop['bind_dn']) && !empty($this->prop['bind_pass'])) 
     112        $fu = $RCMAIL->user->get_username(); 
     113        list($u, $d) = explode('@', $fu); 
     114         
     115        // Replace the bind_dn and base_dn variables. 
     116        $replaces = array('%fu' => $fu, '%u' => $u, '%d' => $d); 
     117        $this->prop['bind_dn'] = strtr($this->prop['bind_dn'], $replaces); 
     118        $this->prop['base_dn'] = strtr($this->prop['base_dn'], $replaces); 
     119      } 
     120       
     121      if (!empty($this->prop['bind_dn']) && !empty($this->prop['bind_pass'])) 
    139122        $this->ready = $this->bind($this->prop['bind_dn'], $this->prop['bind_pass']); 
    140123    } 
Note: See TracChangeset for help on using the changeset viewer.