Changeset 680

Show
Ignore:
Timestamp:
10/30/06 23:06:52 (2 years ago)
Author:
misja
Message:

Added the option to automatically have a user created based on LDAP credentials.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/auth/ldap/lib.php

    r602 r680  
    2929     * // Search attibutes 
    3030     * $CFG->ldap_search_attr = array('dn', 'ou', 'mail'); 
    31      * 
     31     * // Create user, relies on the givenname, sn, and email attributes for now 
     32     * $CFG->ldap_user_create = true; 
    3233     */ 
    3334 
     
    105106                            // We have a bind, valid login 
    106107                            //$messages[] = "Succesfull LDAP login for ".$entry[0]['dn']; 
     108 
     109                            // If we need to create the user 
     110                            if ($CFG->ldap_user_create == true) { 
     111                                // Valid Elgg username? 
     112                                if (!preg_match("/^[A-Za-z0-9]{3,12}$/",$username)) { 
     113                                    $messages[] = __gettext("Error! Your username must contain letters and numbers only, cannot be blank, and must be between 3 and 12 characters in length."); 
     114                                } else { 
     115                                    // Does the user already exist? 
     116                                    $username = strtolower($username); 
     117                                    if (record_exists('users','username',$username)) { 
     118                                        $messages[] = sprintf(__gettext("The username %s is already taken by another user. You will need to pick a different one."), $username); 
     119                                    } else { 
     120                                        // Everythink OK, create user 
     121                                        $user = new StdClass; 
     122                                        $user->email = $entry[0]["mail"][0]; 
     123                                        $user->name  = $entry[0]["givenname"][0]; 
     124                                        $user->name  = $user->name . " " . $entry[0]["sn"][0]; 
     125                                        $user->password = md5($password); 
     126                                        $user->user_type = 'person'; 
     127                                        $user->owner = -1; 
     128 
     129                                        $user_id = insert_record('users',$user); 
     130 
     131                                        if (!empty($user_id)) { 
     132                                            $rssresult = run("weblogs:rss:publish", array($uid, false)); 
     133                                            $rssresult = run("files:rss:publish", array($uid, false)); 
     134                                            $rssresult = run("profile:rss:publish", array($uid, false)); 
     135 
     136                                        } else { 
     137                                            // User creation failed 
     138                                            $messages[] = sprintf(__gettext("User addition %d failed: Unknown reason, please contact you system administrator."), $username); 
     139                                        } 
     140                                    } 
     141                                } 
     142                            } 
     143 
    107144                            // Done with LDAP 
    108145                            ldap_close($ds); 
     
    125162 
    126163                        // No such user in LDAP, fallback to internal authentication 
     164                        // TODO make this a configurable option 
    127165                        require_once($CFG->dirroot . 'auth/internal/lib.php'); 
    128166                        return internal_authenticate_user_login($username, $password); 
     
    146184        } 
    147185    } 
     186 
     187    function ldap_create_user($user) 
     188    { 
     189    } 
    148190?>