forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authlib.php
380 lines (339 loc) · 10.5 KB
/
authlib.php
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php // $Id$
/**
* @author Martin Dougiamas
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodle multiauth
*
* Multiple plugin authentication
* Support library
*
* 2006-08-28 File created, AUTH return values defined.
*/
/**
* Returned when the login was successful.
*/
define('AUTH_OK', 0);
/**
* Returned when the login was unsuccessful.
*/
define('AUTH_FAIL', 1);
/**
* Returned when the login was denied (a reason for AUTH_FAIL).
*/
define('AUTH_DENIED', 2);
/**
* Returned when some error occurred (a reason for AUTH_FAIL).
*/
define('AUTH_ERROR', 4);
/**
* Authentication - error codes for user confirm
*/
define('AUTH_CONFIRM_FAIL', 0);
define('AUTH_CONFIRM_OK', 1);
define('AUTH_CONFIRM_ALREADY', 2);
define('AUTH_CONFIRM_ERROR', 3);
# MDL-14055
define('AUTH_REMOVEUSER_KEEP', 0);
define('AUTH_REMOVEUSER_SUSPEND', 1);
define('AUTH_REMOVEUSER_FULLDELETE', 2);
/**
* Abstract authentication plugin.
*/
class auth_plugin_base {
/**
* The configuration details for the plugin.
*/
var $config;
/**
* Authentication plugin type - the same as db field.
*/
var $authtype;
/*
* The fields we can lock and update from/to external authentication backends
*/
var $userfields = array(
'firstname',
'lastname',
'email',
'city',
'country',
'lang',
'description',
'url',
'idnumber',
'institution',
'department',
'phone1',
'phone2',
'address'
);
/**
* This is the primary method that is used by the authenticate_user_login()
* function in moodlelib.php. This method should return a boolean indicating
* whether or not the username and password authenticate successfully.
*
* Returns true if the username and password work and false if they are
* wrong or don't exist.
*
* @param string $username The username (with system magic quotes)
* @param string $password The password (with system magic quotes)
*
* @return bool Authentication success or failure.
*/
function user_login($username, $password) {
print_error('mustbeoveride', 'debug', '', 'user_login()' );
}
/**
* Returns true if this authentication plugin can change the users'
* password.
*
* @return bool
*/
function can_change_password() {
//override if needed
return false;
}
/**
* Returns the URL for changing the users' passwords, or empty if the default
* URL can be used. This method is used if can_change_password() returns true.
* This method is called only when user is logged in, it may use global $USER.
*
* @return string
*/
function change_password_url() {
//override if needed
return '';
}
/**
* Returns true if this authentication plugin is "internal" (which means that
* Moodle stores the users' passwords and other details in the local Moodle
* database).
*
* @return bool
*/
function is_internal() {
//override if needed
return true;
}
/**
* Updates the user's password. In previous versions of Moodle, the function
* auth_user_update_password accepted a username as the first parameter. The
* revised function expects a user object.
*
* @param object $user User table object
* @param string $newpassword Plaintext password
*
* @return bool True on success
*/
function user_update_password($user, $newpassword) {
//override if needed
return true;
}
/**
* Called when the user record is updated.
* Modifies user in external database. It takes olduser (before changes) and newuser (after changes)
* conpares information saved modified information to external db.
*
* @param mixed $olduser Userobject before modifications (without system magic quotes)
* @param mixed $newuser Userobject new modified userobject (without system magic quotes)
* @return boolean true if updated or update ignored; false if error
*
*/
function user_update($olduser, $newuser) {
//override if needed
return true;
}
/**
* User delete requested - internal user record is mared as deleted already, username not present anymore.
* Do any action in external database.
* @param object $user Userobject before delete (without system magic quotes)
*/
function user_delete($olduser) {
//override if needed
return;
}
/**
* Returns true if plugin allows resetting of internal password.
*
* @return bool
*/
function can_reset_password() {
//override if needed
return false;
}
/**
* Returns true if plugin allows resetting of internal password.
*
* @return bool
*/
function can_signup() {
//override if needed
return false;
}
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify=true) {
//override when can signup
print_error('mustbeoveride', 'debug', '', 'user_signup()' );
}
/**
* Returns true if plugin allows confirming of new users.
*
* @return bool
*/
function can_confirm() {
//override if needed
return false;
}
/**
* Confirm the new user as registered.
*
* @param string $username
* @param string $confirmsecret
*/
function user_confirm($username, $confirmsecret) {
//override when can confirm
print_error('mustbeoveride', 'debug', '', 'user_confirm()' );
}
/**
* Checks if user exists in external db
*
* @param string $username (with system magic quotes)
* @return bool
*/
function user_exists() {
//override if needed
return false;
}
/**
* return number of days to user password expires
*
* If userpassword does not expire it should return 0. If password is already expired
* it should return negative value.
*
* @param mixed $username username (with system magic quotes)
* @return integer
*/
function password_expire($username) {
return 0;
}
/**
* Sync roles for this user - usually creator
*
* @param $user object user object (without system magic quotes)
*/
function sync_roles($user) {
//override if needed
}
/**
* Read user information from external database and returns it as array().
* Function should return all information available. If you are saving
* this information to moodle user-table you should honor syncronization flags
*
* @param string $username username
*
* @return mixed array with no magic quotes or false on error
*/
function get_userinfo($username) {
//override if needed
return array();
}
/**
* Prints a form for configuring this authentication plugin.
*
* This function is called from admin/auth.php, and outputs a full page with
* a form for configuring this plugin.
*/
function config_form($config, $err, $user_fields) {
//override if needed
}
/**
* A chance to validate form data, and last chance to
* do stuff before it is inserted in config_plugin
* @param object object with submitted configuration settings (without system magic quotes)
* @param array $err array of error messages
*/
function validate_form(&$form, &$err) {
//override if needed
}
/**
* Processes and stores configuration data for this authentication plugin.
*
* @param object object with submitted configuration settings (without system magic quotes)
*/
function process_config($config) {
//override if needed
return true;
}
/**
* Hook for overriding behavior of login page.
* This method is called from login/index.php page for all enabled auth plugins.
*/
function loginpage_hook() {
global $frm; // can be used to override submitted login form
global $user; // can be used to replace authenticate_user_login()
//override if needed
}
/**
* Post authentication hook.
* This method is called from authenticate_user_login() for all enabled auth plugins.
*
* @param object $user user object, later used for $USER
* @param string $username (with system magic quotes)
* @param string $password plain text password (with system magic quotes)
*/
function user_authenticated_hook(&$user, $username, $password) {
//override if needed
}
/**
* Pre logout hook.
* This method is called from require_logout() for all enabled auth plugins,
*/
function prelogout_hook() {
global $USER; // use $USER->auth to find the plugin used for login
//override if needed
}
/**
* Hook for overriding behavior of logout page.
* This method is called from login/logout.php page for all enabled auth plugins.
*/
function logoutpage_hook() {
global $USER; // use $USER->auth to find the plugin used for login
global $redirect; // can be used to override redirect after logout
//override if needed
}
/**
* Return the properly translated human-friendly title of this auth plugin
*/
function get_title() {
$authtitle = get_string("auth_{$this->authtype}title", "auth");
if ($authtitle == "[[auth_{$this->authtype}title]]") {
$authtitle = get_string("auth_{$this->authtype}title", "auth_{$this->authtype}");
}
return $authtitle;
}
/**
* Get the auth description (from core or own auth lang files)
*/
function get_description() {
$authdescription = get_string("auth_{$this->authtype}description", "auth");
if ($authdescription == "[[auth_{$this->authtype}description]]") {
$authdescription = get_string("auth_{$this->authtype}description", "auth_{$this->authtype}");
}
return $authdescription;
}
/**
* Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements.
* @abstract Implement in child classes
* @return bool
*/
function is_captcha_enabled() {
return false;
}
}
?>