/[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.16 - (show annotations) (download) (as text)
Sat Mar 25 06:01:54 2006 UTC (3 years, 8 months ago) by weitzman
Branch: MAIN
Changes since 1.15: +10 -8 lines
File MIME type: text/x-php
#2618 Update logged in user on new http auth
1 <?php
2 // $Id: webserver_auth.module,v 1.15 2006/03/25 05:53:56 weitzman Exp $
3
4 function webserver_auth_init() {
5 global $user, $account;
6
7 // 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 }
15 else {
16 if ($name) {
17 // user is logged into webserver.
18 $account->name = $name;
19 //modules get to change the user bits before saving. use a global $account to do so.
20 // only loaded modules will see this hook
21 module_invoke_all("webserver_auth");
22 // if we are in bootstrap, load user.module ourselves
23 if (!module_exist('user')) {
24 drupal_load('module', 'user');
25 }
26
27 // try to log into Drupal. if unsuccessful, register the user
28 $user = user_external_load($account->name);
29 if (!$user->uid) {
30 if (variable_get("user_register", 1) == 1) {
31 $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 // 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 $user = user_save("", array_merge($user_default, (array)$account));
34 watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
35 }
36 }
37 }
38 else {
39 // do nothing. user isn't logged into web server
40 }
41 }
42 }
43
44 // using a global to change your bits. module_invoke_all miffs me.
45 function webserver_auth_webserver_auth() {
46 global $account;
47
48 // pretties up the username for NTLM authentication (i.e. Windows)
49 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
50 $account->name = substr(trim($account->name), strrpos(trim($account->name), "\\")+1);
51 }
52
53 if ($domain = variable_get("webserver_auth_domain", "")) {
54 if ($account->name) {
55 $account->mail = $account->name. "@$domain";
56 }
57 }
58 }
59
60 function webserver_auth_settings() {
61 $form["webserver_auth_domain"] = array(
62 '#type' => 'textfield',
63 '#title' => t("Email Domain"),
64 '#default_value' => variable_get("webserver_auth_domain", ""),
65 '#size' => 30,
66 '#maxlength' => 55,
67 '#description' => t("Append this domain name to each new user in order generate his email address."),
68 );
69 return $form;
70 }
71
72 function webserver_auth_help($section) {
73 $output ="";
74
75 switch ($section) {
76 case 'admin/help#webserver_auth':
77 break;
78 case 'admin/modules#description':
79 $output .= t("Use web server authentication instead of Drupal");
80 break;
81 }
82
83 return $output;
84 }

  ViewVC Help
Powered by ViewVC 1.1.2