/[drupal]/contributions/modules/webserver_auth/webserver_auth.module
ViewVC logotype

Contents of /contributions/modules/webserver_auth/webserver_auth.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.14 - (hide annotations) (download) (as text)
Fri Mar 3 05:08:46 2006 UTC (3 years, 8 months ago) by weitzman
Branch: MAIN
Changes since 1.13: +2 -2 lines
File MIME type: text/x-php
sorry - parse bug
1 weitzman 1.1 <?php
2 weitzman 1.14 // $Id: webserver_auth.module,v 1.13 2006/03/03 05:02:28 weitzman Exp $
3 weitzman 1.1
4 weitzman 1.5 function webserver_auth_init() {
5     global $user, $account;
6 weitzman 1.10
7 weitzman 1.1 if ($user->uid) {
8 weitzman 1.5 //do nothing because user is already logged into Drupal
9 weitzman 1.1 }
10     else {
11 weitzman 1.4 if ($name = $_SERVER["REMOTE_USER"]) {
12 weitzman 1.10 // user is logged into webserver.
13 weitzman 1.5 $account->name = $name;
14     //modules get to change the user bits before saving. use a global $account to do so.
15 weitzman 1.12 // only loaded modules will see this hook
16 weitzman 1.5 module_invoke_all("webserver_auth");
17 weitzman 1.12 // if we are in bootstrap, load user.module ourselves
18     if (!module_exist('user')) {
19     drupal_load('module', 'user');
20     }
21 weitzman 1.10
22 weitzman 1.5 // try to log into Drupal. if unsuccessful, register the user
23 weitzman 1.7 $user = user_external_load($account->name);
24 weitzman 1.1 if (!$user->uid) {
25     if (variable_get("user_register", 1) == 1) {
26 weitzman 1.14 $user_default = array("name" => $account->name, "pass" => "cyan", "init" => db_escape_string($name), "authname_webserver_auth" => $account->name, "status" => 1, "roles" => array(DRUPAL_AUTHENTICATED_RID));
27 weitzman 1.12 // TODO - the hook_user('register') will fire but only for loaded modules. cold be a problem for sites using page cache and that hook+operation
28 weitzman 1.13 $user = user_save("", array_merge($user_default, (array)$account));
29 weitzman 1.5 watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
30 weitzman 1.1 }
31     }
32     }
33     else {
34     // do nothing. user isn't logged into web server
35     }
36     }
37     }
38    
39 weitzman 1.5 // using a global to change your bits. module_invoke_all miffs me.
40     function webserver_auth_webserver_auth() {
41     global $account;
42 weitzman 1.10
43 weitzman 1.3 // pretties up the username for NTLM authentication (i.e. Windows)
44 weitzman 1.6 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
45     $account->name = substr(trim($account->name), strrpos(trim($account->name), "\\")+1);
46 weitzman 1.5 }
47 weitzman 1.10
48 weitzman 1.5 if ($domain = variable_get("webserver_auth_domain", "")) {
49     if ($account->name) {
50     $account->mail = $account->name. "@$domain";
51     }
52 weitzman 1.3 }
53     }
54    
55 weitzman 1.5 function webserver_auth_settings() {
56 weitzman 1.13 $form["webserver_auth_domain"] = array(
57     '#type' => 'textfield',
58     '#title' => t("Email Domain"),
59     '#default_value' => variable_get("webserver_auth_domain", ""),
60     '#size' => 30,
61     '#maxlength' => 55,
62     '#description' => t("Append this domain name to each new user in order generate his email address."),
63     );
64     return $form;
65 weitzman 1.5 }
66    
67 weitzman 1.3 function webserver_auth_help($section) {
68     $output ="";
69    
70     switch ($section) {
71     case 'admin/help#webserver_auth':
72     break;
73 weitzman 1.8 case 'admin/modules#description':
74 weitzman 1.3 $output .= t("Use web server authentication instead of Drupal");
75     break;
76     }
77    
78     return $output;
79     }
80    
81    
82 uwe 1.9 ?>

  ViewVC Help
Powered by ViewVC 1.1.2