| | 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 | |
|---|