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

Diff of /contributions/modules/webserver_auth/webserver_auth.module

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

revision 1.13.2.1, Fri Mar 3 05:02:28 2006 UTC revision 1.13.2.2, Fri Mar 3 05:06:18 2006 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: webserver_auth.module,v 1.13 2006/03/03 05:02:28 weitzman Exp $
3    
4    function webserver_auth_init() {
5      global $user, $account;
6    
7      if ($user->uid) {
8        //do nothing because user is already logged into Drupal
9      }
10      else {
11        if ($name = $_SERVER["REMOTE_USER"]) {
12          // user is logged into webserver.
13          $account->name = $name;
14          //modules get to change the user bits before saving. use a global $account to do so.
15          // only loaded modules will see this hook
16          module_invoke_all("webserver_auth");
17          // if we are in bootstrap, load user.module ourselves
18          if (!module_exist('user')) {
19           drupal_load('module', 'user');
20          }
21    
22          // try to log into Drupal. if unsuccessful, register the user
23          $user = user_external_load($account->name);
24          if (!$user->uid) {
25            if (variable_get("user_register", 1) == 1) {
26              $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              // 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              $user = user_save("", array_merge($user_default, (array)$account));
29              watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
30            }
31          }
32        }
33        else {
34          // do nothing. user isn't logged into web server
35        }
36      }
37    }
38    
39    // using a global to change your bits. module_invoke_all miffs me.
40    function webserver_auth_webserver_auth() {
41      global $account;
42    
43      // pretties up the username for NTLM authentication (i.e. Windows)
44      if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
45        $account->name = substr(trim($account->name), strrpos(trim($account->name), "\\")+1);
46      }
47    
48      if ($domain = variable_get("webserver_auth_domain", "")) {
49        if ($account->name) {
50          $account->mail = $account->name. "@$domain";
51        }
52      }
53    }
54    
55    function webserver_auth_settings() {
56      $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    }
66    
67    function webserver_auth_help($section) {
68      $output ="";
69    
70      switch ($section) {
71        case 'admin/help#webserver_auth':
72          break;
73        case 'admin/modules#description':
74          $output .= t("Use web server authentication instead of Drupal");
75          break;
76      }
77    
78      return $output;
79    }
80    
81    
82    ?>

Legend:
Removed from v.1.13.2.1  
changed lines
  Added in v.1.13.2.2

  ViewVC Help
Powered by ViewVC 1.1.2