| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: webserver_auth.module,v 1.22 2008/07/17 20:37:37 weitzman Exp $ |
| 3 |
|
|
|
/** |
|
|
* Implementation of hook_menu(). |
|
|
*/ |
|
| 4 |
function webserver_auth_menu() { |
function webserver_auth_menu() { |
| 5 |
$items = array(); |
$items = array(); |
| 6 |
$items['admin/settings/webserver_auth'] = array( |
$items['admin/settings/webserver_auth'] = array( |
| 13 |
return $items; |
return $items; |
| 14 |
} |
} |
| 15 |
|
|
|
/** |
|
|
* Implementation of hook_init(). |
|
|
*/ |
|
| 16 |
function webserver_auth_init() { |
function webserver_auth_init() { |
| 17 |
global $user; |
global $user; |
| 18 |
|
|
| 57 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 58 |
*/ |
*/ |
| 59 |
function webserver_auth_user($op, &$edit, &$account, $category = NULL) { |
function webserver_auth_user($op, &$edit, &$account, $category = NULL) { |
| 60 |
if ($op == 'insert' && $category = 'account') { |
if ($op == 'submit' && $category = 'account') { |
| 61 |
$account->name = trim($account->name); |
// Only fiddle with new accounts. |
| 62 |
// Pretty up the username for NTLM authentication (i.e. Windows) |
if (empty($account->uid)) { |
| 63 |
if (variable_get('webserver_auth_strip_prefix', TRUE)) { |
$account->name = trim($account->name); |
| 64 |
// Get 'bar' from 'foo1\foo2\bar' |
// Pretty up the username for NTLM authentication (i.e. Windows) |
| 65 |
$account->name = array_pop(explode("\\", $account->name)); |
if (variable_get('webserver_auth_strip_prefix', TRUE)) { |
| 66 |
} |
// Get 'bar' from 'foo1\foo2\bar' |
| 67 |
if (variable_get('webserver_auth_strip_domain', TRUE)) { |
$account->name = array_pop(explode("\\", $account->name)); |
| 68 |
// Get 'foo' from 'foo@bar' |
} |
| 69 |
$account->name = array_shift(explode('@', $account->name)); |
if (variable_get('webserver_auth_strip_domain', TRUE)) { |
| 70 |
} |
// Get 'foo' from 'foo@bar' |
| 71 |
db_query("UPDATE {users} SET name = '%s' WHERE uid = %d", $account->name, $account->uid); |
$account->name = array_shift(explode('@', $account->name)); |
| 72 |
// Generate an e-mail address automagically |
} |
| 73 |
if ($domain = variable_get('webserver_auth_email_domain', '')) { |
|
| 74 |
if ($account->name) { |
// Generate an e-mail address automagically |
| 75 |
db_query("UPDATE {users} SET mail = '%s@%s' WHERE uid = %d", $account->name, $domain, $account->uid); |
if ($domain = variable_get('webserver_auth_email_domain', '')) { |
| 76 |
|
if ($account->name) { |
| 77 |
|
$account->mail = $account->name. '@'. $domain; |
| 78 |
|
} |
| 79 |
|
} |
| 80 |
|
// run some custom code to modify the user object at creation time |
| 81 |
|
if ($code = variable_get('webserver_auth_insert', '')) { |
| 82 |
|
eval('?>'. $code); |
| 83 |
} |
} |
|
} |
|
|
// run some custom code to modify the user object at creation time |
|
|
if ($code = variable_get('webserver_auth_insert', '')) { |
|
|
eval('?>'. $code); |
|
| 84 |
} |
} |
| 85 |
} |
} |
| 86 |
elseif ($op == 'logout') { |
elseif ($op == 'logout') { |
| 90 |
} |
} |
| 91 |
} |
} |
| 92 |
|
|
|
/** |
|
|
* Implementation of hook_settings(). |
|
|
*/ |
|
| 93 |
function webserver_auth_settings() { |
function webserver_auth_settings() { |
| 94 |
$form['webserver_auth_email_domain'] = array( |
$form['webserver_auth_email_domain'] = array( |
| 95 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 120 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 121 |
'#title' => 'User account modification', |
'#title' => 'User account modification', |
| 122 |
'#default_value' => variable_get('webserver_auth_insert', ''), |
'#default_value' => variable_get('webserver_auth_insert', ''), |
| 123 |
'#description' => t("Modify user accounts at the time of creation. Use PHP code (enclosed in <code><?php</code> and <code>?></code>). The variable <code>\$account</code> is available as in <a href=\"http://api.drupal.org/api/function/hook_user/6\">hook_user('insert',...)</a>. Changes to the user object must be explicitly saved to the database to be made permanent."), |
'#description' => t("Modify user accounts at the time of creation. Use PHP code (enclosed in <code><?php</code> and <code>?></code>). The variable <code>\$account</code> is available as in <a href=\"http://api.drupal.org/api/function/hook_user/6\">hook_user('submit',...)</a>. Changes to the \$account object will be automatically saved."), |
| 124 |
), |
), |
| 125 |
); |
); |
| 126 |
return system_settings_form($form); |
return system_settings_form($form); |