/[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.18 - (hide annotations) (download) (as text)
Tue Apr 24 01:17:45 2007 UTC (2 years, 7 months ago) by weitzman
Branch: MAIN
Changes since 1.17: +6 -3 lines
File MIME type: text/x-php
#138649 Conflict with Profile module (and potentially others). patch by zibas
1 weitzman 1.1 <?php
2 weitzman 1.18 // $Id: webserver_auth.module,v 1.17 2007/04/24 01:09:26 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.16 // two ways to get $name
8     if ($name != $_SERVER["REMOTE_USER"]) {
9     $name = $_SERVER["REDIRECT_REMOTE_USER"];
10     }
11    
12     if (isset($user) && $user->id && $user->name === $name) {
13     //do nothing because user is already logged into Drupal, and hasn't presented different credentials vis web server
14 weitzman 1.1 }
15     else {
16 weitzman 1.16 if ($name) {
17 weitzman 1.10 // user is logged into webserver.
18 weitzman 1.5 $account->name = $name;
19     //modules get to change the user bits before saving. use a global $account to do so.
20 weitzman 1.12 // only loaded modules will see this hook
21 weitzman 1.5 module_invoke_all("webserver_auth");
22 weitzman 1.12 // if we are in bootstrap, load user.module ourselves
23     if (!module_exist('user')) {
24     drupal_load('module', 'user');
25     }
26 weitzman 1.10
27 weitzman 1.5 // try to log into Drupal. if unsuccessful, register the user
28 weitzman 1.18 $test_user = user_external_load($account->name);
29     if (!$test_user->uid) {
30 weitzman 1.1 if (variable_get("user_register", 1) == 1) {
31 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));
32 weitzman 1.16 // TODO - the hook_user('register') will fire but only for loaded modules. could be a problem for sites using page cache and that hook+operation
33 weitzman 1.13 $user = user_save("", array_merge($user_default, (array)$account));
34 weitzman 1.5 watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
35 weitzman 1.1 }
36     }
37 weitzman 1.18 else{
38     $user = $test_user;
39     }
40 weitzman 1.1 }
41     else {
42     // do nothing. user isn't logged into web server
43     }
44     }
45     }
46    
47 weitzman 1.5 // using a global to change your bits. module_invoke_all miffs me.
48     function webserver_auth_webserver_auth() {
49     global $account;
50 weitzman 1.10
51 weitzman 1.17 $account->name = trim($account->name);
52 weitzman 1.3 // pretties up the username for NTLM authentication (i.e. Windows)
53 weitzman 1.6 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
54 weitzman 1.17 if (!(strpos($account->name, "\\") === false)) {
55     $account->name = substr($account->name, strrpos($account->name, "\\")+1);
56     }
57     if (!(strpos($account->name, "@") === false)) {
58     $account->name = substr($account->name, 0, strrpos($account->name, "@"));
59     }
60 weitzman 1.5 }
61 weitzman 1.10
62 weitzman 1.5 if ($domain = variable_get("webserver_auth_domain", "")) {
63     if ($account->name) {
64     $account->mail = $account->name. "@$domain";
65     }
66 weitzman 1.3 }
67     }
68    
69 weitzman 1.5 function webserver_auth_settings() {
70 weitzman 1.13 $form["webserver_auth_domain"] = array(
71     '#type' => 'textfield',
72     '#title' => t("Email Domain"),
73     '#default_value' => variable_get("webserver_auth_domain", ""),
74     '#size' => 30,
75     '#maxlength' => 55,
76     '#description' => t("Append this domain name to each new user in order generate his email address."),
77     );
78     return $form;
79 weitzman 1.5 }
80    
81 weitzman 1.3 function webserver_auth_help($section) {
82     $output ="";
83    
84     switch ($section) {
85     case 'admin/help#webserver_auth':
86     break;
87 weitzman 1.8 case 'admin/modules#description':
88 weitzman 1.3 $output .= t("Use web server authentication instead of Drupal");
89     break;
90     }
91    
92     return $output;
93     }

  ViewVC Help
Powered by ViewVC 1.1.2