-
Notifications
You must be signed in to change notification settings - Fork 0
/
authnamer.module
133 lines (125 loc) · 3.97 KB
/
authnamer.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
// $Id$
/**
* @file
* Allow existing Drupal users to be authorized by a different authorization system
* look for the option to
* 'Allow existing Drupal users to be authorized by a different authorization system'
* under the Update options popup at admin/user/user.
* specify the authorizaton module at admin/settings/authnamer.
*/
/**
* system settings form page
* @return form allows setting the name of the authorization system
*/
function authnamer_admin() {
$form = array();
$form['authnamer_auth_module'] = array(
'#type' => 'textfield',
'#title' => t('Authorization module name'),
'#default_value' => variable_get('authnamer_auth_module', ''),
'#size' => 40,
'#maxlength' => 80,
'#description' => t("The 'machine name' of the authorization module (eg. simplesamlphp_auth)."),
'#required' => TRUE,
);
return system_settings_form($form);
}
/**
* Implements hook_admin_validate()
* @param form $form authnamer_admin form
* @param form_state $form_state state of the form
* @return none sets form error it problems arise
*/
function authnamer_admin_validate($form, &$form_state) {
$module = $form_state['values']['authnamer_auth_module'];
if (!module_exists($module)) {
form_set_error('authnamer_auth_module', t('You must enter the machine name of a module enabled on this site.'));
}
}
/**
* Implements hook_menu()
* @return array menu items
*/
function authnamer_menu() {
$items = array();
$items['admin/config/people/authnamer'] = array(
'title' => 'Authmap authnamer module settings',
'description' => 'Name the module an existing user can authorize with.',
'page callback' => 'drupal_get_form',
'page arguments' => array('authnamer_admin'),
'access arguments' => array('administer authnamer settings'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_permission()
* @return array permission info
*/
function authnamer_permission() {
return array(
'administer authnamer settings' => array(
'title' => t('Access Authmap authnamer settings'),
'description' => t('Name the module an existing user can authenticate with.'),
),
);
}
/**
* Implements hook_action_info().
*/
function authnamer_action_info() {
return array(
'authnamer_set_authentication_module' => array(
'type' => 'user',
'label' => t('Allow existing Drupal users to be authorized by a different authorization system'),
'behavior' => array('changes_property'),
'configurable' => FALSE,
'vbo_configurable' => FALSE,
'triggers' => array('any'),
),
);
}
/**
* Implements hook_user().
* ONLY IN DRUPAL 6
*/
function authnamer_user_OLD($op, &$edit, &$account, $category = NULL) { }
/**
* Implements hook_user_operations().
*/
function authnamer_user_operations() {
$module = variable_get('authnamer_auth_module', '');
if (empty($module)) {
return array();
}
return array(
'authnamer' => array(
'label' => t('Change user authentication module to @module.', array('@module' => $module)),
'callback' => 'authnamer_claim_user',
),
);
}
/**
* Mark the user for some modules authentication
* @param array $accounts
*/
function authnamer_claim_user($users) {
// see http://api.drupal.org/api/drupal/modules--user--user.module/function/user_external_login_register/6
$module = variable_get('authnamer_auth_module', '');
if (empty($module)) {
drupal_set_message(t('First specify an authentication module at admin/settings/authnamer.'), 'status', FALSE);
}
else {
foreach ($users as $uid) {
// TODO Convert "user_load" to "user_load_multiple" if "$uid" is other than a uid.
// To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent.
// Example: array_shift(user_load_multiple(array(), $uid))
$auser = user_load($uid);
$authmaps = array(
"authname_$module" => $auser->name,
);
user_set_authmaps($auser, $authmaps);
}
}
}