### Eclipse Workspace Patch 1.0
#P moodle18
Index: auth/ldap/auth.php
===================================================================
RCS file: /cvsroot/moodle/moodle/auth/ldap/auth.php,v
retrieving revision 1.6.2.7
diff -u -r1.6.2.7 auth.php
--- auth/ldap/auth.php	29 Mar 2007 19:47:21 -0000	1.6.2.7
+++ auth/ldap/auth.php	25 Apr 2007 07:34:22 -0000
@@ -210,12 +210,12 @@
      * @param string $username (with system magic quotes)
      */
     function user_exists($username) {
-
         $textlib = textlib_get_instance();
         $extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->ldapencoding);
 
         //returns true if given username exist on ldap
         $users = $this->ldap_get_userlist("({$this->config->user_attribute}=".$this->filter_addslashes($extusername).")");
+
         return count($users);
     }
 
@@ -273,7 +273,7 @@
                 $newuser['userpassword']  = $extpassword;
                 break;
             default:
-               print_error('auth_ldap_unsupportedusertype','auth',$this->config->user_type);
+               print_error('auth_ldap_unsupportedusertype','auth','', $this->config->user_type);
         }
         $uadd = $this->ldap_add($ldapconnection, $this->config->user_attribute.'="'.$this->ldap_addslashes($userobject->username).','.$this->config->create_context.'"', $newuser);
         ldap_close($ldapconnection);
@@ -281,6 +281,92 @@
 
     }
 
+    function can_signup() {
+        return (!empty($this->config->auth_user_create) and !empty($this->config->create_context));
+    }
+
+    /**
+     * Sign up a new user ready for confirmation.
+     * Password is passed in plaintext.
+     *
+     * @param object $user new user object (with system magic quotes)
+     * @param boolean $notify print notice with link and terminate
+     */
+    function user_signup($user, $notify=true) {
+        if ($this->user_exists($user->username)) {
+            error('LDAP username already exists');
+        }
+
+        $plainslashedpassword = $user->password;
+        unset($user->password);
+
+        if (!$this->user_create($user, $plainslashedpassword)) {
+            error('Error creating user in LDAP.');
+        }
+
+        if (! ($user->id = insert_record('user', $user)) ) {
+            print_error('auth_emailnoinsert','auth');
+        }
+
+        $this->update_user_record($user->username);
+        update_internal_user_password($user, $plainslashedpassword);
+
+        if (! send_confirmation_email($user)) {
+            print_error('auth_emailnoemail','auth');
+        }
+
+        if ($notify) {
+            global $CFG;
+            $emailconfirm = get_string('emailconfirm');
+            print_header($emailconfirm, $emailconfirm, $emailconfirm);
+            notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
+        } else {
+            return true;
+        }
+    }
+
+    /**
+     * Returns true if plugin allows confirming of new users.
+     *
+     * @return bool
+     */
+    function can_confirm() {
+        return $this->can_signup();
+    }
+
+    /**
+     * Confirm the new user as registered.
+     *
+     * @param string $username (with system magic quotes)
+     * @param string $confirmsecret (with system magic quotes)
+     */
+    function user_confirm($username, $confirmsecret) {
+        $user = get_complete_user_data('username', $username);
+
+        if (!empty($user)) {
+            if ($user->confirmed) {
+                return AUTH_CONFIRM_ALREADY;
+
+            } else if ($user->auth != 'ldap') {
+                return AUTH_CONFIRM_ERROR;
+
+            } else if ($user->secret == stripslashes($confirmsecret)) {   // They have provided the secret key to get in
+                if (!$this->user_activate($username)) {
+                    return AUTH_CONFIRM_FAIL;
+                }
+                if (!set_field("user", "confirmed", 1, "id", $user->id)) {
+                    return AUTH_CONFIRM_FAIL;
+                }
+                if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
+                    return AUTH_CONFIRM_FAIL;
+                }
+                return AUTH_CONFIRM_OK;
+            }
+        } else {
+            return AUTH_CONFIRM_ERROR;
+        }
+    }
+
     /**
      * return number of days to user password expires
      *
Index: lang/en_utf8/auth.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/auth.php,v
retrieving revision 1.18.2.7
diff -u -r1.18.2.7 auth.php
--- lang/en_utf8/auth.php	20 Apr 2007 07:49:58 -0000	1.18.2.7
+++ lang/en_utf8/auth.php	25 Apr 2007 07:34:22 -0000
@@ -204,7 +204,7 @@
 $string['auth_ldap_creators_key'] = 'Creators';
 $string['auth_ldap_noconnect'] = 'LDAP-module cannot connect to server: $a';
 $string['auth_ldap_noconnect_all'] = 'LDAP-module cannot connect to any servers: $a';
-$string['auth_ldap_unsupportedusertype'] = 'auth: ldap user_create() does not support selected usertype:"$a" (..yet)';
+$string['auth_ldap_unsupportedusertype'] = 'auth: ldap user_create() does not support selected usertype:$a (..yet)';
 $string['auth_ldap_usertypeundefined'] = 'config.user_type not defined or function ldap_expirationtime2unix does not support selected type!';
 $string['auth_ldap_usertypeundefined2'] = 'config.user_type not defined or function ldap_unixi2expirationtime does not support selected type!';
 $string['auth_ldap_noextension'] = 'Warning: The PHP LDAP module does not seem to be present. Please ensure it is installed and enabled.';
