| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
define('USERNAME_MAX_LENGTH', 60);
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
define('EMAIL_MAX_LENGTH', 64);
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
function user_module_invoke($type, &$edit, $account, $category = NULL) {
|
| 27 |
foreach (module_implements('user_' . $type) as $module) {
|
| 28 |
$function = $module . '_user_' . $type;
|
| 29 |
$function($edit, $account, $category);
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
function user_theme() {
|
| 37 |
|
| 38 |
|
| 39 |
'arguments' => array('account' => NULL),
|
| 40 |
'template' => 'user-picture',
|
| 41 |
),
|
| 42 |
|
| 43 |
'arguments' => array('elements' => NULL),
|
| 44 |
'template' => 'user-profile',
|
| 45 |
'file' => 'user.pages.inc',
|
| 46 |
),
|
| 47 |
|
| 48 |
'arguments' => array('element' => NULL),
|
| 49 |
'template' => 'user-profile-category',
|
| 50 |
'file' => 'user.pages.inc',
|
| 51 |
),
|
| 52 |
|
| 53 |
'arguments' => array('element' => NULL),
|
| 54 |
'template' => 'user-profile-item',
|
| 55 |
'file' => 'user.pages.inc',
|
| 56 |
),
|
| 57 |
|
| 58 |
'arguments' => array('users' => NULL, 'title' => NULL),
|
| 59 |
),
|
| 60 |
|
| 61 |
'arguments' => array('form' => NULL),
|
| 62 |
'file' => 'user.admin.inc',
|
| 63 |
),
|
| 64 |
|
| 65 |
'arguments' => array('form' => NULL),
|
| 66 |
'file' => 'user.admin.inc',
|
| 67 |
),
|
| 68 |
|
| 69 |
'arguments' => array('form' => NULL),
|
| 70 |
'file' => 'user.admin.inc',
|
| 71 |
),
|
| 72 |
|
| 73 |
'arguments' => array('form' => NULL),
|
| 74 |
'file' => 'user.admin.inc',
|
| 75 |
),
|
| 76 |
|
| 77 |
'arguments' => array('form' => NULL),
|
| 78 |
'file' => 'user.admin.inc',
|
| 79 |
),
|
| 80 |
|
| 81 |
'arguments' => array('signature' => NULL),
|
| 82 |
),
|
| 83 |
);
|
| 84 |
}
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
function user_fieldable_info() {
|
| 90 |
|
| 91 |
|
| 92 |
'label' => t('User'),
|
| 93 |
|
| 94 |
'id' => 'uid',
|
| 95 |
),
|
| 96 |
|
| 97 |
|
| 98 |
'label' => t('User'),
|
| 99 |
|
| 100 |
'path' => 'admin/settings/user',
|
| 101 |
'access arguments' => array('administer users'),
|
| 102 |
),
|
| 103 |
),
|
| 104 |
),
|
| 105 |
),
|
| 106 |
);
|
| 107 |
return $return;
|
| 108 |
}
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
function user_field_build_modes($obj_type) {
|
| 114 |
$modes = array();
|
| 115 |
if ($obj_type == 'user') {
|
| 116 |
|
| 117 |
'full' => t('User account'),
|
| 118 |
);
|
| 119 |
}
|
| 120 |
return $modes;
|
| 121 |
}
|
| 122 |
|
| 123 |
function user_external_load($authname) {
|
| 124 |
$uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchField();
|
| 125 |
|
| 126 |
if ($uid) {
|
| 127 |
return user_load($uid);
|
| 128 |
}
|
| 129 |
|
| 130 |
return FALSE;
|
| 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 |
function user_load_multiple($uids = array(), $conditions = array(), $reset = FALSE) {
|
| 157 |
static $user_cache = array();
|
| 158 |
if ($reset) {
|
| 159 |
$user_cache = array();
|
| 160 |
}
|
| 161 |
|
| 162 |
$users = array();
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
$passed_uids = !empty($uids) ? array_flip($uids) : FALSE;
|
| 170 |
|
| 171 |
|
| 172 |
if ($user_cache) {
|
| 173 |
if ($uids && !$conditions) {
|
| 174 |
$users += array_intersect_key($user_cache, $passed_uids);
|
| 175 |
|
| 176 |
$uids = array_keys(array_diff_key($passed_uids, $users));
|
| 177 |
}
|
| 178 |
}
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
if ($uids || ($conditions && !$passed_uids)) {
|
| 183 |
$query = db_select('users', 'u')->fields('u');
|
| 184 |
|
| 185 |
|
| 186 |
if ($uids) {
|
| 187 |
$query->condition('u.uid', $uids, 'IN');
|
| 188 |
}
|
| 189 |
|
| 190 |
if ($conditions) {
|
| 191 |
|
| 192 |
|
| 193 |
if (isset($conditions['name'])) {
|
| 194 |
$query->condition('u.name', $conditions['name'], 'LIKE');
|
| 195 |
unset($conditions['name']);
|
| 196 |
}
|
| 197 |
if (isset($conditions['mail'])) {
|
| 198 |
$query->condition('u.mail', $conditions['mail'], 'LIKE');
|
| 199 |
unset($conditions['mail']);
|
| 200 |
}
|
| 201 |
foreach ($conditions as $field => $value) {
|
| 202 |
$query->condition('u.' . $field, $value);
|
| 203 |
}
|
| 204 |
}
|
| 205 |
$result = $query->execute();
|
| 206 |
|
| 207 |
$queried_users = array();
|
| 208 |
|
| 209 |
$picture_fids = array();
|
| 210 |
foreach ($result as $record) {
|
| 211 |
$picture_fids[] = $record->picture;
|
| 212 |
$queried_users[$record->uid] = drupal_unpack($record);
|
| 213 |
$queried_users[$record->uid]->roles = array();
|
| 214 |
if ($record->uid) {
|
| 215 |
$queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
|
| 216 |
}
|
| 217 |
|
| 218 |
$queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
|
| 219 |
|
| 220 |
}
|
| 221 |
|
| 222 |
if (!empty($queried_users)) {
|
| 223 |
|
| 224 |
$result = db_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(':uids' => array_keys($queried_users)));
|
| 225 |
foreach ($result as $record) {
|
| 226 |
$queried_users[$record->uid]->roles[$record->rid] = $record->name;
|
| 227 |
}
|
| 228 |
|
| 229 |
|
| 230 |
if (!empty($picture_fids) && variable_get('user_pictures', 1) == 1) {
|
| 231 |
$pictures = file_load_multiple($picture_fids);
|
| 232 |
foreach ($queried_users as $account) {
|
| 233 |
if (!empty($account->picture) && isset($pictures[$account->picture])) {
|
| 234 |
$account->picture = $pictures[$account->picture];
|
| 235 |
}
|
| 236 |
|
| 237 |
$account->picture = NULL;
|
| 238 |
|
| 239 |
}
|
| 240 |
}
|
| 241 |
|
| 242 |
field_attach_load('user', $queried_users);
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
foreach (module_implements('user_load') as $module) {
|
| 247 |
$function = $module . '_user_load';
|
| 248 |
$function($queried_users);
|
| 249 |
}
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
$users = $users + $queried_users;
|
| 254 |
$user_cache = $user_cache + $queried_users;
|
| 255 |
}
|
| 256 |
}
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
if ($passed_uids) {
|
| 261 |
|
| 262 |
$passed_uids = array_intersect_key($passed_uids, $users);
|
| 263 |
foreach ($users as $user) {
|
| 264 |
$passed_uids[$user->uid] = $user;
|
| 265 |
}
|
| 266 |
$users = $passed_uids;
|
| 267 |
}
|
| 268 |
|
| 269 |
return $users;
|
| 270 |
}
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
function user_load($uid, $reset = FALSE) {
|
| 287 |
$users = user_load_multiple(array($uid), array(), $reset);
|
| 288 |
return reset($users);
|
| 289 |
}
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
function user_load_by_mail($mail) {
|
| 303 |
$users = user_load_multiple(array(), array('mail' => $mail));
|
| 304 |
return reset($users);
|
| 305 |
}
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
function user_load_by_name($name) {
|
| 319 |
$users = user_load_multiple(array(), array('name' => $name));
|
| 320 |
return reset($users);
|
| 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 |
function user_save($account, $edit = array(), $category = 'account') {
|
| 347 |
$table = drupal_get_schema('users');
|
| 348 |
$user_fields = $table['fields'];
|
| 349 |
|
| 350 |
if (!empty($edit['pass'])) {
|
| 351 |
|
| 352 |
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
|
| 353 |
$edit['pass'] = user_hash_password(trim($edit['pass']));
|
| 354 |
|
| 355 |
if (!$edit['pass']) {
|
| 356 |
return FALSE;
|
| 357 |
}
|
| 358 |
}
|
| 359 |
|
| 360 |
|
| 361 |
unset($edit['pass']);
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
$field_form = array();
|
| 367 |
$field_form_state = array();
|
| 368 |
$edit = (object) $edit;
|
| 369 |
field_attach_form('user', $edit, $field_form, $field_form_state);
|
| 370 |
|
| 371 |
|
| 372 |
field_attach_presave('user', $edit);
|
| 373 |
|
| 374 |
$edit = (array) $edit;
|
| 375 |
|
| 376 |
if (!isset($account->is_new)) {
|
| 377 |
$account->is_new = empty($account->uid);
|
| 378 |
}
|
| 379 |
if (is_object($account) && !$account->is_new) {
|
| 380 |
user_module_invoke('update', $edit, $account, $category);
|
| 381 |
$data = unserialize(db_query('SELECT data FROM {users} WHERE uid = :uid', array(':uid' => $account->uid))->fetchField());
|
| 382 |
|
| 383 |
|
| 384 |
if (empty($edit['access']) && empty($account->access) && user_access('administer users')) {
|
| 385 |
$edit['access'] = REQUEST_TIME;
|
| 386 |
}
|
| 387 |
foreach ($edit as $key => $value) {
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
if (!in_array($key, array('roles', 'is_new')) && empty($user_fields[$key]) && empty($field_form[$key])) {
|
| 392 |
if ($value === NULL) {
|
| 393 |
unset($data[$key]);
|
| 394 |
}
|
| 395 |
|
| 396 |
$data[$key] = $value;
|
| 397 |
|
| 398 |
}
|
| 399 |
}
|
| 400 |
|
| 401 |
|
| 402 |
if (!empty($edit['picture']->fid)) {
|
| 403 |
$picture = $edit['picture'];
|
| 404 |
|
| 405 |
|
| 406 |
if (($picture->status & FILE_STATUS_PERMANENT) == 0) {
|
| 407 |
$info = image_get_info($picture->filepath);
|
| 408 |
$destination = file_create_path(variable_get('user_picture_path', 'pictures') . '/picture-' . $account->uid . '.' . $info['extension']);
|
| 409 |
if ($picture = file_move($picture, $destination, FILE_EXISTS_REPLACE)) {
|
| 410 |
$picture->status |= FILE_STATUS_PERMANENT;
|
| 411 |
$edit['picture'] = file_save($picture);
|
| 412 |
}
|
| 413 |
}
|
| 414 |
}
|
| 415 |
$edit['picture'] = empty($edit['picture']->fid) ? 0 : $edit['picture']->fid;
|
| 416 |
|
| 417 |
$edit['data'] = $data;
|
| 418 |
|
| 419 |
$edit['uid'] = $account->uid;
|
| 420 |
|
| 421 |
$success = drupal_write_record('users', $edit, 'uid');
|
| 422 |
if (!$success) {
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
}
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
if (!empty($account->picture->fid) && ($edit['picture'] != $account->picture->fid)) {
|
| 437 |
file_delete($account->picture);
|
| 438 |
}
|
| 439 |
|
| 440 |
|
| 441 |
if (isset($edit['roles']) && is_array($edit['roles'])) {
|
| 442 |
db_delete('users_roles')
|
| 443 |
->condition('uid', $account->uid)
|
| 444 |
->execute();
|
| 445 |
|
| 446 |
$query = db_insert('users_roles')->fields(array('uid', 'rid'));
|
| 447 |
foreach (array_keys($edit['roles']) as $rid) {
|
| 448 |
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
|
| 449 |
$query->values(array(
|
| 450 |
'uid' => $account->uid,
|
| 451 |
'rid' => $rid,
|
| 452 |
));
|
| 453 |
}
|
| 454 |
}
|
| 455 |
$query->execute();
|
| 456 |
}
|
| 457 |
|
| 458 |
|
| 459 |
if (isset($edit['status']) && $edit['status'] == 0) {
|
| 460 |
drupal_session_destroy_uid($account->uid);
|
| 461 |
}
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
if (!empty($edit['pass'])) {
|
| 466 |
drupal_session_destroy_uid($account->uid);
|
| 467 |
if ($account->uid == $GLOBALS['user']->uid) {
|
| 468 |
drupal_session_regenerate();
|
| 469 |
}
|
| 470 |
}
|
| 471 |
|
| 472 |
|
| 473 |
$object = (object) $edit;
|
| 474 |
field_attach_update('user', $object);
|
| 475 |
|
| 476 |
|
| 477 |
$user = user_load($account->uid, TRUE);
|
| 478 |
|
| 479 |
|
| 480 |
if (isset($edit['status']) && $edit['status'] != $account->status) {
|
| 481 |
|
| 482 |
$op = $edit['status'] == 1 ? 'status_activated' : 'status_blocked';
|
| 483 |
_user_mail_notify($op, $user);
|
| 484 |
}
|
| 485 |
|
| 486 |
user_module_invoke('after_update', $edit, $user, $category);
|
| 487 |
}
|
| 488 |
|
| 489 |
|
| 490 |
if (!isset($edit['created'])) {
|
| 491 |
$edit['created'] = REQUEST_TIME;
|
| 492 |
}
|
| 493 |
|
| 494 |
|
| 495 |
if (empty($edit['access']) && user_access('administer users')) {
|
| 496 |
$edit['access'] = REQUEST_TIME;
|
| 497 |
}
|
| 498 |
|
| 499 |
$edit['mail'] = trim($edit['mail']);
|
| 500 |
$success = drupal_write_record('users', $edit);
|
| 501 |
if (!$success) {
|
| 502 |
|
| 503 |
|
| 504 |
return FALSE;
|
| 505 |
}
|
| 506 |
|
| 507 |
|
| 508 |
$user = user_load($edit['uid'], TRUE);
|
| 509 |
|
| 510 |
$object = (object) $edit;
|
| 511 |
field_attach_insert('user', $object);
|
| 512 |
|
| 513 |
user_module_invoke('insert', $edit, $user, $category);
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
$data = array();
|
| 518 |
foreach ($edit as $key => $value) {
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
if ((!in_array($key, array('roles', 'is_new'))) && (empty($user_fields[$key]) && empty($field_form[$key])) && ($value !== NULL)) {
|
| 523 |
$data[$key] = $value;
|
| 524 |
}
|
| 525 |
}
|
| 526 |
if (!empty($data)) {
|
| 527 |
$data_array = array('uid' => $user->uid, 'data' => $data);
|
| 528 |
drupal_write_record('users', $data_array, 'uid');
|
| 529 |
}
|
| 530 |
|
| 531 |
|
| 532 |
if (isset($edit['roles']) && is_array($edit['roles'])) {
|
| 533 |
db_delete('users_roles')
|
| 534 |
->condition('uid', $edit['uid'])
|
| 535 |
->execute();
|
| 536 |
$query = db_insert('users_roles')->fields(array('uid', 'rid'));
|
| 537 |
foreach (array_keys($edit['roles']) as $rid) {
|
| 538 |
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
|
| 539 |
$query->values(array(
|
| 540 |
'uid' => $edit['uid'],
|
| 541 |
'rid' => $rid,
|
| 542 |
));
|
| 543 |
}
|
| 544 |
}
|
| 545 |
$query->execute();
|
| 546 |
}
|
| 547 |
|
| 548 |
|
| 549 |
$user = user_load($edit['uid'], TRUE);
|
| 550 |
|
| 551 |
|
| 552 |
return $user;
|
| 553 |
}
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
function user_validate_name($name) {
|
| 559 |
if (!$name) {
|
| 560 |
return t('You must enter a username.');
|
| 561 |
}
|
| 562 |
if (substr($name, 0, 1) == ' ') {
|
| 563 |
return t('The username cannot begin with a space.');
|
| 564 |
}
|
| 565 |
if (substr($name, -1) == ' ') {
|
| 566 |
return t('The username cannot end with a space.');
|
| 567 |
}
|
| 568 |
if (strpos($name, ' ') !== FALSE) {
|
| 569 |
return t('The username cannot contain multiple spaces in a row.');
|
| 570 |
}
|
| 571 |
if (preg_match('/[^\x{80}-\x{F7} a-z0-9@_.\'-]/i', $name)) {
|
| 572 |
return t('The username contains an illegal character.');
|
| 573 |
}
|
| 574 |
if (preg_match('/[\x{80}-\x{A0}' . // Non-printable ISO-8859-1 + NBSP
|
| 575 |
'\x{AD}' . // Soft-hyphen
|
| 576 |
'\x{2000}-\x{200F}' . // Various space characters
|
| 577 |
'\x{2028}-\x{202F}' . // Bidirectional text overrides
|
| 578 |
'\x{205F}-\x{206F}' . // Various text hinting characters
|
| 579 |
'\x{FEFF}' . // Byte order mark
|
| 580 |
'\x{FF01}-\x{FF60}' . // Full-width latin
|
| 581 |
'\x{FFF9}-\x{FFFD}' . // Replacement characters
|
| 582 |
'\x{0}-\x{1F}]/u', // NULL byte and control characters
|
| 583 |
$name)) {
|
| 584 |
return t('The username contains an illegal character.');
|
| 585 |
}
|
| 586 |
if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {
|
| 587 |
return t('The username %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));
|
| 588 |
}
|
| 589 |
}
|
| 590 |
|
| 591 |
function user_validate_mail($mail) {
|
| 592 |
$mail = trim($mail);
|
| 593 |
if (!$mail) {
|
| 594 |
return t('You must enter an e-mail address.');
|
| 595 |
}
|
| 596 |
if (!valid_email_address($mail)) {
|
| 597 |
return t('The e-mail address %mail is not valid.', array('%mail' => $mail));
|
| 598 |
}
|
| 599 |
}
|
| 600 |
|
| 601 |
function user_validate_picture(&$form, &$form_state) {
|
| 602 |
|
| 603 |
|
| 604 |
'file_validate_is_image' => array(),
|
| 605 |
'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
|
| 606 |
'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
|
| 607 |
);
|
| 608 |
|
| 609 |
|
| 610 |
$file = file_save_upload('picture_upload', $validators);
|
| 611 |
if ($file === FALSE) {
|
| 612 |
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => variable_get('user_picture_path', 'pictures'))));
|
| 613 |
}
|
| 614 |
elseif ($file !== NULL) {
|
| 615 |
$form_state['values']['picture_upload'] = $file;
|
| 616 |
}
|
| 617 |
}
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
function user_password($length = 10) {
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
$allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
| 628 |
|
| 629 |
|
| 630 |
$len = strlen($allowable_characters) - 1;
|
| 631 |
|
| 632 |
|
| 633 |
$pass = '';
|
| 634 |
|
| 635 |
|
| 636 |
for ($i = 0; $i < $length; $i++) {
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
$pass .= $allowable_characters[mt_rand(0, $len)];
|
| 641 |
}
|
| 642 |
|
| 643 |
return $pass;
|
| 644 |
}
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
function user_role_permissions($roles = array(), $reset = FALSE) {
|
| 659 |
static $stored_permissions = array();
|
| 660 |
|
| 661 |
if ($reset) {
|
| 662 |
|
| 663 |
$stored_permissions = array();
|
| 664 |
}
|
| 665 |
|
| 666 |
$role_permissions = $fetch = array();
|
| 667 |
|
| 668 |
if ($roles) {
|
| 669 |
foreach ($roles as $rid => $name) {
|
| 670 |
if (isset($stored_permissions[$rid])) {
|
| 671 |
$role_permissions[$rid] = $stored_permissions[$rid];
|
| 672 |
}
|
| 673 |
|
| 674 |
|
| 675 |
$fetch[] = $rid;
|
| 676 |
|
| 677 |
$stored_permissions[$rid] = array();
|
| 678 |
|
| 679 |
}
|
| 680 |
|
| 681 |
if ($fetch) {
|
| 682 |
|
| 683 |
|
| 684 |
$result = db_query("SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)", array(':fetch' => $fetch));
|
| 685 |
|
| 686 |
foreach ($result as $row) {
|
| 687 |
$stored_permissions[$row->rid][$row->permission] = TRUE;
|
| 688 |
}
|
| 689 |
foreach ($fetch as $rid) {
|
| 690 |
|
| 691 |
$role_permissions[$rid] = $stored_permissions[$rid];
|
| 692 |
}
|
| 693 |
}
|
| 694 |
}
|
| 695 |
|
| 696 |
return $role_permissions;
|
| 697 |
}
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
function user_access($string, $account = NULL, $reset = FALSE) {
|
| 719 |
global $user;
|
| 720 |
static $perm = array();
|
| 721 |
|
| 722 |
if ($reset) {
|
| 723 |
$perm = array();
|
| 724 |
}
|
| 725 |
|
| 726 |
if (!isset($account)) {
|
| 727 |
$account = $user;
|
| 728 |
}
|
| 729 |
|
| 730 |
|
| 731 |
if ($account->uid == 1) {
|
| 732 |
return TRUE;
|
| 733 |
}
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
if (!isset($perm[$account->uid])) {
|
| 738 |
$role_permissions = user_role_permissions($account->roles, $reset);
|
| 739 |
|
| 740 |
$perms = array();
|
| 741 |
foreach ($role_permissions as $one_role) {
|
| 742 |
$perms += $one_role;
|
| 743 |
}
|
| 744 |
$perm[$account->uid] = $perms;
|
| 745 |
}
|
| 746 |
|
| 747 |
return isset($perm[$account->uid][$string]);
|
| 748 |
}
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
function user_is_blocked($name) {
|
| 756 |
$deny = db_query("SELECT name FROM {users} WHERE status = 0 AND name = LOWER(:name)", array(':name' => $name))->fetchObject();
|
| 757 |
|
| 758 |
return $deny;
|
| 759 |
}
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
function user_permission() {
|
| 765 |
|
| 766 |
|
| 767 |
'title' => t('Administer permissions'),
|
| 768 |
'description' => t('Manage the permissions assigned to user roles. %warning', array('%warning' => t('Warning: Give to trusted roles only; this permission has security implications.'))),
|
| 769 |
),
|
| 770 |
|
| 771 |
'title' => t('Administer users'),
|
| 772 |
'description' => t('Manage or block users, and manage their role assignments.'),
|
| 773 |
),
|
| 774 |
|
| 775 |
'title' => t('Access user profiles'),
|
| 776 |
'description' => t('View profiles of users on the site, which may contain personal information.'),
|
| 777 |
),
|
| 778 |
|
| 779 |
'title' => t('Change own username'),
|
| 780 |
'description' => t('Select a different username.'),
|
| 781 |
),
|
| 782 |
|
| 783 |
'title' => t('Cancel account'),
|
| 784 |
'description' => t('Remove or disable own user account and unpublish, anonymize, or remove own submissions depending on the configured <a href="@user-settings-url">user settings</a>.', array('@user-settings-url' => url('admin/settings/user'))),
|
| 785 |
),
|
| 786 |
|
| 787 |
'title' => t('Select method for cancelling own account'),
|
| 788 |
'description' => t('Select the method for cancelling own user account. %warning', array('%warning' => t('Warning: Give to trusted roles only; this permission has security implications.'))),
|
| 789 |
),
|
| 790 |
);
|
| 791 |
}
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
function user_file_download($filepath) {
|
| 799 |
if (strpos($filepath, variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
|
| 800 |
$info = image_get_info(file_create_path($filepath));
|
| 801 |
return array('Content-Type' => $info['mime_type']);
|
| 802 |
}
|
| 803 |
}
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
function user_file_references($file) {
|
| 809 |
|
| 810 |
$file_used = (bool) db_query_range('SELECT 1 FROM {users} WHERE picture = :fid', array(':fid' => $file->fid), 0, 1)->fetchField();
|
| 811 |
if ($file_used) {
|
| 812 |
|
| 813 |
return array('user' => $count);
|
| 814 |
}
|
| 815 |
}
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
function user_file_delete($file) {
|
| 821 |
|
| 822 |
db_update('users')
|
| 823 |
->fields(array('picture' => 0))
|
| 824 |
->condition('picture', $file->fid)
|
| 825 |
->execute();
|
| 826 |
}
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
|
| 832 |
|
| 833 |
case 'name':
|
| 834 |
if ($skip_access_check || user_access('access user profiles')) {
|
| 835 |
return t('Users');
|
| 836 |
}
|
| 837 |
case 'search':
|
| 838 |
if (user_access('access user profiles')) {
|
| 839 |
$find = array();
|
| 840 |
|
| 841 |
$keys = preg_replace('!\*+!', '%', $keys);
|
| 842 |
$query = db_select('users')->extend('PagerDefault');
|
| 843 |
$query->fields('users', array('name', 'uid', 'mail'));
|
| 844 |
if (user_access('administer users')) {
|
| 845 |
|
| 846 |
$query->condition(db_or()->
|
| 847 |
where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"))->
|
| 848 |
where('LOWER(mail) LIKE LOWER(:mail)', array(':mail' => "%$keys%")));
|
| 849 |
}
|
| 850 |
|
| 851 |
$query->where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"));
|
| 852 |
|
| 853 |
|
| 854 |
->limit(15)
|
| 855 |
->execute();
|
| 856 |
foreach ($result as $account) {
|
| 857 |
$find[] = array('title' => $account->name . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE)));
|
| 858 |
}
|
| 859 |
return $find;
|
| 860 |
}
|
| 861 |
}
|
| 862 |
}
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
function user_elements() {
|
| 868 |
|
| 869 |
|
| 870 |
'#theme_wrappers' => array('user_profile_category')
|
| 871 |
),
|
| 872 |
|
| 873 |
|
| 874 |
),
|
| 875 |
);
|
| 876 |
}
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
function user_user_view($account) {
|
| 882 |
$account->content['user_picture'] = array(
|
| 883 |
'#markup' => theme('user_picture', $account),
|
| 884 |
'#weight' => -10,
|
| 885 |
|
| 886 |
if (!isset($account->content['summary'])) {
|
| 887 |
$account->content['summary'] = array();
|
| 888 |
}
|
| 889 |
$account->content['summary'] += array(
|
| 890 |
'#type' => 'user_profile_category',
|
| 891 |
'#attributes' => array('class' => 'user-member'),
|
| 892 |
'#weight' => 5,
|
| 893 |
'#title' => t('History'),
|
| 894 |
|
| 895 |
$account->content['summary']['member_for'] = array(
|
| 896 |
'#type' => 'user_profile_item',
|
| 897 |
'#title' => t('Member for'),
|
| 898 |
'#markup' => format_interval(REQUEST_TIME - $account->created),
|
| 899 |
|
| 900 |
}
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
function user_user_form(&$edit, $account, $category) {
|
| 906 |
if ($category == 'account') {
|
| 907 |
$form_state = array();
|
| 908 |
return user_edit_form($form_state, (isset($account->uid) ? $account->uid : FALSE), $edit);
|
| 909 |
}
|
| 910 |
}
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
function user_user_validate(&$edit, $account, $category) {
|
| 916 |
if ($category == 'account') {
|
| 917 |
$uid = isset($account->uid) ? $account->uid : FALSE;
|
| 918 |
|
| 919 |
if (!$uid || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || user_access('administer users')) {
|
| 920 |
if ($error = user_validate_name($edit['name'])) {
|
| 921 |
form_set_error('name', $error);
|
| 922 |
}
|
| 923 |
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:name)", array(':uid' => $uid, ':name' => $edit['name']), 0, 1)->fetchField()) {
|
| 924 |
form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
|
| 925 |
}
|
| 926 |
}
|
| 927 |
|
| 928 |
|
| 929 |
if ($error = user_validate_mail($edit['mail'])) {
|
| 930 |
form_set_error('mail', $error);
|
| 931 |
}
|
| 932 |
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(mail) = LOWER(:mail)", array(':uid' => $uid, ':mail' => $edit['mail']), 0, 1)->fetchField()) {
|
| 933 |
|
| 934 |
if ($GLOBALS['user']->uid) {
|
| 935 |
form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $edit['mail'])));
|
| 936 |
}
|
| 937 |
|
| 938 |
form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $edit['mail'], '@password' => url('user/password'))));
|
| 939 |
|
| 940 |
}
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
if (isset($edit['signature'])) {
|
| 945 |
$user_schema = drupal_get_schema('users');
|
| 946 |
if (strlen($edit['signature']) > $user_schema['fields']['signature']['length']) {
|
| 947 |
form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length'])));
|
| 948 |
}
|
| 949 |
}
|
| 950 |
}
|
| 951 |
}
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
function user_user_submit(&$edit, $account, $category) {
|
| 957 |
if ($category == 'account') {
|
| 958 |
if (!empty($edit['picture_upload'])) {
|
| 959 |
$edit['picture'] = $edit['picture_upload'];
|
| 960 |
}
|
| 961 |
|
| 962 |
elseif (!empty($edit['picture_delete'])) {
|
| 963 |
$edit['picture'] = NULL;
|
| 964 |
}
|
| 965 |
|
| 966 |
$edit['picture_upload'] = NULL;
|
| 967 |
$edit['picture_delete'] = NULL;
|
| 968 |
|
| 969 |
if (isset($edit['roles'])) {
|
| 970 |
$edit['roles'] = array_filter($edit['roles']);
|
| 971 |
}
|
| 972 |
}
|
| 973 |
}
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
function user_user_categories() {
|
| 979 |
|
| 980 |
'name' => 'account',
|
| 981 |
'title' => t('Account settings'),
|
| 982 |
'weight' => 1,
|
| 983 |
));
|
| 984 |
}
|
| 985 |
|
| 986 |
function user_login_block() {
|
| 987 |
|
| 988 |
'#action' => url($_GET['q'], array('query' => drupal_get_destination())),
|
| 989 |
'#id' => 'user-login-form',
|
| 990 |
'#validate' => user_login_default_validators(),
|
| 991 |
'#submit' => array('user_login_submit'),
|
| 992 |
);
|
| 993 |
$form['name'] = array('#type' => 'textfield',
|
| 994 |
'#title' => t('Username'),
|
| 995 |
'#maxlength' => USERNAME_MAX_LENGTH,
|
| 996 |
'#size' => 15,
|
| 997 |
'#required' => TRUE,
|
| 998 |
|
| 999 |
$form['pass'] = array('#type' => 'password',
|
| 1000 |
'#title' => t('Password'),
|
| 1001 |
'#maxlength' => 60,
|
| 1002 |
'#size' => 15,
|
| 1003 |
'#required' => TRUE,
|
| 1004 |
|
| 1005 |
$form['submit'] = array('#type' => 'submit',
|
| 1006 |
'#value' => t('Log in'),
|
| 1007 |
|
| 1008 |
$items = array();
|
| 1009 |
if (variable_get('user_register', 1)) {
|
| 1010 |
$items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
|
| 1011 |
}
|
| 1012 |
$items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
|
| 1013 |
$form['links'] = array('#markup' => theme('item_list', $items));
|
| 1014 |
return $form;
|
| 1015 |
}
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
function user_block_list() {
|
| 1021 |
global $user;
|
| 1022 |
|
| 1023 |
$blocks['login']['info'] = t('User login');
|
| 1024 |
|
| 1025 |
$blocks['login']['cache'] = BLOCK_NO_CACHE;
|
| 1026 |
|
| 1027 |
$blocks['new']['info'] = t('Who\'s new');
|
| 1028 |
|
| 1029 |
|
| 1030 |
$blocks['online']['info'] = t('Who\'s online');
|
| 1031 |
$blocks['online']['cache'] = BLOCK_NO_CACHE;
|
| 1032 |
return $blocks;
|
| 1033 |
}
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
function user_block_configure($delta = '') {
|
| 1039 |
global $user;
|
| 1040 |
|
| 1041 |
|
| 1042 |
case 'new':
|
| 1043 |
$form['user_block_whois_new_count'] = array(
|
| 1044 |
'#type' => 'select',
|
| 1045 |
'#title' => t('Number of users to display'),
|
| 1046 |
'#default_value' => variable_get('user_block_whois_new_count', 5),
|
| 1047 |
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
|
| 1048 |
|
| 1049 |
return $form;
|
| 1050 |
|
| 1051 |
case 'online':
|
| 1052 |
$period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
|
| 1053 |
$form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.'));
|
| 1054 |
$form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.'));
|
| 1055 |
$form['user_block_cache'] = array('#markup' => '<p>If page caching is disabled, the block shows the number of anonymous and authenticated users, respectively. If page caching is enabled, only the number of authenticated users is displayed.</p>');
|
| 1056 |
return $form;
|
| 1057 |
}
|
| 1058 |
}
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
function user_block_save($delta = '', $edit = array()) {
|
| 1064 |
global $user;
|
| 1065 |
|
| 1066 |
|
| 1067 |
case 'new':
|
| 1068 |
variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']);
|
| 1069 |
break;
|
| 1070 |
|
| 1071 |
case 'online':
|
| 1072 |
variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);
|
| 1073 |
variable_set('user_block_max_list_count', $edit['user_block_max_list_count']);
|
| 1074 |
break;
|
| 1075 |
}
|
| 1076 |
}
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
function user_block_view($delta = '') {
|
| 1082 |
global $user;
|
| 1083 |
|
| 1084 |
$block = array();
|
| 1085 |
|
| 1086 |
|
| 1087 |
case 'login':
|
| 1088 |
|
| 1089 |
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
|
| 1090 |
|
| 1091 |
$block['subject'] = t('User login');
|
| 1092 |
$block['content'] = drupal_get_form('user_login_block');
|
| 1093 |
}
|
| 1094 |
return $block;
|
| 1095 |
|
| 1096 |
case 'new':
|
| 1097 |
if (user_access('access content')) {
|
| 1098 |
|
| 1099 |
$items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
|
| 1100 |
$output = theme('user_list', $items);
|
| 1101 |
|
| 1102 |
$block['subject'] = t('Who\'s new');
|
| 1103 |
$block['content'] = $output;
|
| 1104 |
}
|
| 1105 |
return $block;
|
| 1106 |
|
| 1107 |
case 'online':
|
| 1108 |
if (user_access('access content')) {
|
| 1109 |
|
| 1110 |
$interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900);
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
$authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField();
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) {
|
| 1119 |
$anonymous_count = drupal_session_count($interval);
|
| 1120 |
|
| 1121 |
if ($anonymous_count == 1 && $authenticated_count == 1) {
|
| 1122 |
$output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
|
| 1123 |
}
|
| 1124 |
|
| 1125 |
$output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
|
| 1126 |
|
| 1127 |
}
|
| 1128 |
|
| 1129 |
$output = format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.');
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
$max_users = variable_get('user_block_max_list_count', 10);
|
| 1134 |
if ($authenticated_count && $max_users) {
|
| 1135 |
$items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', array(':interval' => $interval), 0, $max_users)->fetchAll();
|
| 1136 |
$output .= theme('user_list', $items, t('Online users'));
|
| 1137 |
}
|
| 1138 |
|
| 1139 |
$block['subject'] = t('Who\'s online');
|
| 1140 |
$block['content'] = $output;
|
| 1141 |
}
|
| 1142 |
return $block;
|
| 1143 |
}
|
| 1144 |
}
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
function template_preprocess_user_picture(&$variables) {
|
| 1156 |
$variables['user_picture'] = '';
|
| 1157 |
if (variable_get('user_pictures', 0)) {
|
| 1158 |
$account = $variables['account'];
|
| 1159 |
if (!empty($account->picture)) {
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if (is_numeric($account->picture)) {
|
| 1168 |
$account->picture = file_load($account->picture);
|
| 1169 |
}
|
| 1170 |
if (!empty($account->picture->filepath)) {
|
| 1171 |
$filepath = $account->picture->filepath;
|
| 1172 |
}
|
| 1173 |
}
|
| 1174 |
elseif (variable_get('user_picture_default', '')) {
|
| 1175 |
$filepath = variable_get('user_picture_default', '');
|
| 1176 |
}
|
| 1177 |
if (isset($filepath)) {
|
| 1178 |
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
|
| 1179 |
if (module_exists('image') && $style = variable_get('user_picture_style', '')) {
|
| 1180 |
$variables['user_picture'] = theme('image_style', $style, $filepath, $alt, $alt, array(), FALSE);
|
| 1181 |
}
|
| 1182 |
|
| 1183 |
$variables['user_picture'] = theme('image', $filepath, $alt, $alt, array(), FALSE);
|
| 1184 |
|
| 1185 |
if (!empty($account->uid) && user_access('access user profiles')) {
|
| 1186 |
$attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
|
| 1187 |
$variables['user_picture'] = l($variables['user_picture'], "user/$account->uid", $attributes);
|
| 1188 |
}
|
| 1189 |
}
|
| 1190 |
}
|
| 1191 |
}
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
function theme_user_list($users, $title = NULL) {
|
| 1204 |
if (!empty($users)) {
|
| 1205 |
foreach ($users as $user) {
|
| 1206 |
$items[] = theme('username', $user);
|
| 1207 |
}
|
| 1208 |
}
|
| 1209 |
return theme('item_list', $items, $title);
|
| 1210 |
}
|
| 1211 |
|
| 1212 |
function user_is_anonymous() {
|
| 1213 |
|
| 1214 |
return !$GLOBALS['user']->uid || !empty($GLOBALS['menu_admin']);
|
| 1215 |
}
|
| 1216 |
|
| 1217 |
function user_is_logged_in() {
|
| 1218 |
return (bool)$GLOBALS['user']->uid;
|
| 1219 |
}
|
| 1220 |
|
| 1221 |
function user_register_access() {
|
| 1222 |
return user_is_anonymous() && variable_get('user_register', 1);
|
| 1223 |
}
|
| 1224 |
|
| 1225 |
function user_view_access($account) {
|
| 1226 |
return $account && $account->uid &&
|
| 1227 |
|
| 1228 |
|
| 1229 |
($GLOBALS['user']->uid == $account->uid) ||
|
| 1230 |
|
| 1231 |
user_access('administer users') ||
|
| 1232 |
|
| 1233 |
($account->access && $account->status && user_access('access user profiles'))
|
| 1234 |
);
|
| 1235 |
}
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
function user_edit_access($account) {
|
| 1241 |
return (($GLOBALS['user']->uid == $account->uid) || user_access('administer users')) && $account->uid > 0;
|
| 1242 |
}
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
function user_cancel_access($account) {
|
| 1251 |
return ((($GLOBALS['user']->uid == $account->uid) && user_access('cancel account')) || user_access('administer users')) && $account->uid > 0;
|
| 1252 |
}
|
| 1253 |
|
| 1254 |
function user_load_self($arg) {
|
| 1255 |
$arg[1] = user_load($GLOBALS['user']->uid);
|
| 1256 |
return $arg;
|
| 1257 |
}
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
function user_menu() {
|
| 1263 |
$items['user/autocomplete'] = array(
|
| 1264 |
'title' => 'User autocomplete',
|
| 1265 |
'page callback' => 'user_autocomplete',
|
| 1266 |
'access callback' => 'user_access',
|
| 1267 |
'access arguments' => array('access user profiles'),
|
| 1268 |
'type' => MENU_CALLBACK,
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
$items['user'] = array(
|
| 1273 |
'title' => 'User account',
|
| 1274 |
'page callback' => 'user_page',
|
| 1275 |
'access callback' => TRUE,
|
| 1276 |
'type' => MENU_CALLBACK,
|
| 1277 |
|
| 1278 |
|
| 1279 |
$items['user/login'] = array(
|
| 1280 |
'title' => 'Log in',
|
| 1281 |
'access callback' => 'user_is_anonymous',
|
| 1282 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 1283 |
|
| 1284 |
|
| 1285 |
$items['user/register'] = array(
|
| 1286 |
'title' => 'Create new account',
|
| 1287 |
'page callback' => 'drupal_get_form',
|
| 1288 |
'page arguments' => array('user_register'),
|
| 1289 |
'access callback' => 'user_register_access',
|
| 1290 |
'type' => MENU_LOCAL_TASK,
|
| 1291 |
|
| 1292 |
|
| 1293 |
$items['user/password'] = array(
|
| 1294 |
'title' => 'Request new password',
|
| 1295 |
'page callback' => 'drupal_get_form',
|
| 1296 |
'page arguments' => array('user_pass'),
|
| 1297 |
'access callback' => 'user_is_anonymous',
|
| 1298 |
'type' => MENU_LOCAL_TASK,
|
| 1299 |
|
| 1300 |
$items['user/reset/%/%/%'] = array(
|
| 1301 |
'title' => 'Reset password',
|
| 1302 |
'page callback' => 'drupal_get_form',
|
| 1303 |
'page arguments' => array('user_pass_reset', 2, 3, 4),
|
| 1304 |
'access callback' => TRUE,
|
| 1305 |
'type' => MENU_CALLBACK,
|
| 1306 |
|
| 1307 |
|
| 1308 |
$items['user/logout'] = array(
|
| 1309 |
'title' => 'Log out',
|
| 1310 |
'access callback' => 'user_is_logged_in',
|
| 1311 |
'page callback' => 'user_logout',
|
| 1312 |
'weight' => 10,
|
| 1313 |
'menu_name' => 'user-menu',
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
$items['admin/people'] = array(
|
| 1318 |
'title' => 'People',
|
| 1319 |
'page callback' => 'user_admin',
|
| 1320 |
'page arguments' => array('list'),
|
| 1321 |
'access arguments' => array('administer users'),
|
| 1322 |
'weight' => -4,
|
| 1323 |
|
| 1324 |
$items['admin/people/list'] = array(
|
| 1325 |
'title' => 'List',
|
| 1326 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 1327 |
'weight' => -10,
|
| 1328 |
|
| 1329 |
$items['admin/people/create'] = array(
|
| 1330 |
'title' => 'Add user',
|
| 1331 |
'page arguments' => array('create'),
|
| 1332 |
'access arguments' => array('administer users'),
|
| 1333 |
'type' => MENU_LOCAL_TASK,
|
| 1334 |
|
| 1335 |
$items['admin/settings/user'] = array(
|
| 1336 |
'title' => 'Users',
|
| 1337 |
'description' => 'Configure default behavior of users, including registration requirements, e-mails, and user pictures.',
|
| 1338 |
'page callback' => 'drupal_get_form',
|
| 1339 |
'page arguments' => array('user_admin_settings'),
|
| 1340 |
'access arguments' => array('administer users'),
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
$items['admin/settings/permissions'] = array(
|
| 1345 |
'title' => 'Permissions',
|
| 1346 |
'description' => 'Determine access to features by selecting permissions for roles.',
|
| 1347 |
'page callback' => 'drupal_get_form',
|
| 1348 |
'page arguments' => array('user_admin_permissions'),
|
| 1349 |
'access arguments' => array('administer permissions'),
|
| 1350 |
|
| 1351 |
$items['admin/settings/roles'] = array(
|
| 1352 |
'title' => 'Roles',
|
| 1353 |
'description' => 'List, edit, or add user roles.',
|
| 1354 |
'page callback' => 'drupal_get_form',
|
| 1355 |
'page arguments' => array('user_admin_new_role'),
|
| 1356 |
'access arguments' => array('administer permissions'),
|
| 1357 |
|
| 1358 |
$items['admin/settings/roles/edit'] = array(
|
| 1359 |
'title' => 'Edit role',
|
| 1360 |
'page arguments' => array('user_admin_role'),
|
| 1361 |
'access arguments' => array('administer permissions'),
|
| 1362 |
'type' => MENU_CALLBACK,
|
| 1363 |
|
| 1364 |
|
| 1365 |
$items['user/%user_uid_optional'] = array(
|
| 1366 |
'title' => 'My account',
|
| 1367 |
'title callback' => 'user_page_title',
|
| 1368 |
'title arguments' => array(1),
|
| 1369 |
'page callback' => 'user_view',
|
| 1370 |
'page arguments' => array(1),
|
| 1371 |
'access callback' => 'user_view_access',
|
| 1372 |
'access arguments' => array(1),
|
| 1373 |
'weight' => -10,
|
| 1374 |
'menu_name' => 'user-menu',
|
| 1375 |
|
| 1376 |
|
| 1377 |
$items['user/%user/view'] = array(
|
| 1378 |
'title' => 'View',
|
| 1379 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 1380 |
'weight' => -10,
|
| 1381 |
|
| 1382 |
|
| 1383 |
$items['user/%user/cancel'] = array(
|
| 1384 |
'title' => 'Cancel account',
|
| 1385 |
'page callback' => 'drupal_get_form',
|
| 1386 |
'page arguments' => array('user_cancel_confirm_form', 1),
|
| 1387 |
'access callback' => 'user_cancel_access',
|
| 1388 |
'access arguments' => array(1),
|
| 1389 |
'type' => MENU_CALLBACK,
|
| 1390 |
|
| 1391 |
|
| 1392 |
$items['user/%user/cancel/confirm/%/%'] = array(
|
| 1393 |
'title' => 'Confirm account cancellation',
|
| 1394 |
'page callback' => 'user_cancel_confirm',
|
| 1395 |
'page arguments' => array(1, 4, 5),
|
| 1396 |
'access callback' => 'user_cancel_access',
|
| 1397 |
'access arguments' => array(1),
|
| 1398 |
'type' => MENU_CALLBACK,
|
| 1399 |
|
| 1400 |
|
| 1401 |
$items['user/%user/edit'] = array(
|
| 1402 |
'title' => 'Edit',
|
| 1403 |
'page callback' => 'user_edit',
|
| 1404 |
'page arguments' => array(1),
|
| 1405 |
'access callback' => 'user_edit_access',
|
| 1406 |
'access arguments' => array(1),
|
| 1407 |
'type' => MENU_LOCAL_TASK,
|
| 1408 |
|
| 1409 |
|
| 1410 |
$items['user/%user_category/edit/account'] = array(
|
| 1411 |
'title' => 'Account',
|
| 1412 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 1413 |
'load arguments' => array('%map', '%index'),
|
| 1414 |
|
| 1415 |
|
| 1416 |
if (($categories = _user_categories()) && (count($categories) > 1)) {
|
| 1417 |
foreach ($categories as $key => $category) {
|
| 1418 |
|
| 1419 |
if ($category['name'] != 'account') {
|
| 1420 |
$items['user/%user_category/edit/' . $category['name']] = array(
|
| 1421 |
'title callback' => 'check_plain',
|
| 1422 |
'title arguments' => array($category['title']),
|
| 1423 |
'page callback' => 'user_edit',
|
| 1424 |
'page arguments' => array(1, 3),
|
| 1425 |
'access callback' => isset($category['access callback']) ? $category['access callback'] : 'user_edit_access',
|
| 1426 |
'access arguments' => isset($category['access arguments']) ? $category['access arguments'] : array(1),
|
| 1427 |
'type' => MENU_LOCAL_TASK,
|
| 1428 |
'weight' => $category['weight'],
|
| 1429 |
'load arguments' => array('%map', '%index'),
|
| 1430 |
'tab_parent' => 'user/%/edit',
|
| 1431 |
|
| 1432 |
}
|
| 1433 |
}
|
| 1434 |
}
|
| 1435 |
return $items;
|
| 1436 |
}
|
| 1437 |
|
| 1438 |
function user_init() {
|
| 1439 |
drupal_add_css(drupal_get_path('module', 'user') . '/user.css');
|
| 1440 |
}
|
| 1441 |
|
| 1442 |
function user_uid_optional_load($arg) {
|
| 1443 |
return user_load(isset($arg) ? $arg : $GLOBALS['user']->uid);
|
| 1444 |
}
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
function user_category_load($uid, &$map, $index) {
|
| 1450 |
static $user_categories, $accounts;
|
| 1451 |
|
| 1452 |
|
| 1453 |
if (!isset($accounts[$uid])) {
|
| 1454 |
$accounts[$uid] = user_load($uid);
|
| 1455 |
}
|
| 1456 |
$valid = TRUE;
|
| 1457 |
if ($account = $accounts[$uid]) {
|
| 1458 |
|
| 1459 |
|
| 1460 |
$category_index = $index + 2;
|
| 1461 |
|
| 1462 |
$category_path = implode('/', array_slice($map, $category_index));
|
| 1463 |
if ($category_path) {
|
| 1464 |
|
| 1465 |
$valid = FALSE;
|
| 1466 |
if (!isset($user_categories)) {
|
| 1467 |
$user_categories = _user_categories();
|
| 1468 |
}
|
| 1469 |
foreach ($user_categories as $category) {
|
| 1470 |
if ($category['name'] == $category_path) {
|
| 1471 |
$valid = TRUE;
|
| 1472 |
|
| 1473 |
$map = array_slice($map, 0, $category_index);
|
| 1474 |
|
| 1475 |
$map[$category_index] = $category_path;
|
| 1476 |
break;
|
| 1477 |
}
|
| 1478 |
}
|
| 1479 |
}
|
| 1480 |
}
|
| 1481 |
return $valid ? $account : FALSE;
|
| 1482 |
}
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
function user_uid_optional_to_arg($arg) {
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
return empty($arg) || $arg == '%' ? $GLOBALS['user']->uid : $arg;
|
| 1492 |
}
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
function user_page_title($account) {
|
| 1498 |
if ($account->uid == $GLOBALS['user']->uid) {
|
| 1499 |
return t('My account');
|
| 1500 |
}
|
| 1501 |
return $account->name;
|
| 1502 |
}
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
function user_get_authmaps($authname = NULL) {
|
| 1513 |
$authmaps = db_query("SELECT authname, module FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchAllKeyed();
|
| 1514 |
return count($authmaps) ? $authmaps : 0;
|
| 1515 |
}
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
function user_set_authmaps($account, $authmaps) {
|
| 1530 |
foreach ($authmaps as $key => $value) {
|
| 1531 |
$module = explode('_', $key, 2);
|
| 1532 |
if ($value) {
|
| 1533 |
db_merge('authmap')
|
| 1534 |
->key(array(
|
| 1535 |
'uid' => $account->uid,
|
| 1536 |
'module' => $module[1],
|
| 1537 |
))
|
| 1538 |
->fields(array('authname' => $value))
|
| 1539 |
->execute();
|
| 1540 |
}
|
| 1541 |
|
| 1542 |
db_delete('authmap')
|
| 1543 |
->condition('uid', $account->uid)
|
| 1544 |
->condition('module', $module[1])
|
| 1545 |
->execute();
|
| 1546 |
|
| 1547 |
}
|
| 1548 |
}
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
function user_login(&$form_state) {
|
| 1556 |
global $user;
|
| 1557 |
|
| 1558 |
|
| 1559 |
if ($user->uid) {
|
| 1560 |
drupal_goto('user/' . $user->uid);
|
| 1561 |
}
|
| 1562 |
|
| 1563 |
|
| 1564 |
$form['name'] = array('#type' => 'textfield',
|
| 1565 |
'#title' => t('Username'),
|
| 1566 |
'#size' => 60,
|
| 1567 |
'#maxlength' => USERNAME_MAX_LENGTH,
|
| 1568 |
'#required' => TRUE,
|
| 1569 |
|
| 1570 |
|
| 1571 |
$form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
|
| 1572 |
$form['pass'] = array('#type' => 'password',
|
| 1573 |
'#title' => t('Password'),
|
| 1574 |
'#description' => t('Enter the password that accompanies your username.'),
|
| 1575 |
'#required' => TRUE,
|
| 1576 |
|
| 1577 |
$form['#validate'] = user_login_default_validators();
|
| 1578 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Log in'), '#weight' => 2);
|
| 1579 |
|
| 1580 |
return $form;
|
| 1581 |
}
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
function user_login_default_validators() {
|
| 1602 |
return array('user_login_name_validate', 'user_login_authenticate_validate', 'user_login_final_validate');
|
| 1603 |
}
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
function user_login_name_validate($form, &$form_state) {
|
| 1609 |
if (isset($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) {
|
| 1610 |
|
| 1611 |
form_set_error('name', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name'])));
|
| 1612 |
}
|
| 1613 |
}
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
function user_login_authenticate_validate($form, &$form_state) {
|
| 1621 |
$password = trim($form_state['values']['pass']);
|
| 1622 |
if (!empty($form_state['values']['name']) && !empty($password)) {
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
if (!flood_is_allowed('failed_login_attempt_ip', variable_get('user_failed_login_ip_limit', 50), variable_get('user_failed_login_ip_window', 3600))) {
|
| 1629 |
$form_state['flood_control_triggered'] = 'ip';
|
| 1630 |
return;
|
| 1631 |
}
|
| 1632 |
$account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
|
| 1633 |
if ($account) {
|
| 1634 |
if (variable_get('user_failed_login_identifier_uid_only', FALSE)) {
|
| 1635 |
|
| 1636 |
|
| 1637 |
$identifier = $account->uid;
|
| 1638 |
}
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
$identifier = $account->uid . '-' . ip_address();
|
| 1644 |
|
| 1645 |
$form_state['flood_control_user_identifier'] = $identifier;
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
if (!flood_is_allowed('failed_login_attempt_user', variable_get('user_failed_login_user_limit', 5), variable_get('user_failed_login_user_window', 21600), $identifier)) {
|
| 1650 |
$form_state['flood_control_triggered'] = 'user';
|
| 1651 |
return;
|
| 1652 |
}
|
| 1653 |
}
|
| 1654 |
|
| 1655 |
|
| 1656 |
$form_state['uid'] = user_authenticate($form_state['values']['name'], $password);
|
| 1657 |
}
|
| 1658 |
}
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
function user_login_final_validate($form, &$form_state) {
|
| 1668 |
if (empty($form_state['uid'])) {
|
| 1669 |
|
| 1670 |
flood_register_event('failed_login_attempt_ip');
|
| 1671 |
|
| 1672 |
if (isset($form_state['flood_control_user_identifier'])) {
|
| 1673 |
flood_register_event('failed_login_attempt_user', $form_state['flood_control_user_identifier']);
|
| 1674 |
}
|
| 1675 |
|
| 1676 |
if (isset($form_state['flood_control_triggered'])) {
|
| 1677 |
if ($form_state['flood_control_triggered'] == 'user') {
|
| 1678 |
form_set_error('name', format_plural(variable_get('user_failed_login_user_limit', 5), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Please try again later, or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Please try again later, or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
|
| 1679 |
}
|
| 1680 |
|
| 1681 |
|
| 1682 |
form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Please try again later, or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
|
| 1683 |
|
| 1684 |
}
|
| 1685 |
|
| 1686 |
form_set_error('name', t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password'))));
|
| 1687 |
watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
|
| 1688 |
|
| 1689 |
}
|
| 1690 |
elseif (isset($form_state['flood_control_user_identifier'])) {
|
| 1691 |
|
| 1692 |
|
| 1693 |
flood_clear_event('failed_login_attempt_user', $form_state['flood_control_user_identifier']);
|
| 1694 |
}
|
| 1695 |
}
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
function user_authenticate($name, $password) {
|
| 1708 |
$uid = FALSE;
|
| 1709 |
if (!empty($name) && !empty($password)) {
|
| 1710 |
$account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $name))->fetchObject();
|
| 1711 |
if ($account) {
|
| 1712 |
|
| 1713 |
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
|
| 1714 |
if (user_check_password($password, $account)) {
|
| 1715 |
|
| 1716 |
$uid = $account->uid;
|
| 1717 |
|
| 1718 |
|
| 1719 |
if (user_needs_new_hash($account)) {
|
| 1720 |
$new_hash = user_hash_password($password);
|
| 1721 |
if ($new_hash) {
|
| 1722 |
db_update('users')
|
| 1723 |
->fields(array('pass' => $new_hash))
|
| 1724 |
->condition('uid', $account->uid)
|
| 1725 |
->execute();
|
| 1726 |
}
|
| 1727 |
}
|
| 1728 |
}
|
| 1729 |
}
|
| 1730 |
}
|
| 1731 |
return $uid;
|
| 1732 |
}
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
function user_login_finalize(&$edit = array()) {
|
| 1741 |
global $user;
|
| 1742 |
watchdog('user', 'Session opened for %name.', array('%name' => $user->name));
|
| 1743 |
|
| 1744 |
|
| 1745 |
$user->login = REQUEST_TIME;
|
| 1746 |
db_update('users')
|
| 1747 |
->fields(array('login' => $user->login))
|
| 1748 |
->condition('uid', $user->uid)
|
| 1749 |
->execute();
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
drupal_session_regenerate();
|
| 1755 |
|
| 1756 |
user_module_invoke('login', $edit, $user);
|
| 1757 |
}
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
function user_login_submit($form, &$form_state) {
|
| 1765 |
global $user;
|
| 1766 |
$user = user_load($form_state['uid']);
|
| 1767 |
user_login_finalize();
|
| 1768 |
|
| 1769 |
$form_state['redirect'] = 'user/' . $user->uid;
|
| 1770 |
}
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
function user_external_login_register($name, $module) {
|
| 1778 |
$account = user_load_by_name($name);
|
| 1779 |
if (!$account->uid) {
|
| 1780 |
|
| 1781 |
|
| 1782 |
'name' => $name,
|
| 1783 |
'pass' => user_password(),
|
| 1784 |
'init' => $name,
|
| 1785 |
'status' => 1,
|
| 1786 |
|
| 1787 |
);
|
| 1788 |
$account = user_save('', $userinfo);
|
| 1789 |
|
| 1790 |
if (!$account) {
|
| 1791 |
drupal_set_message(t("Error saving user account."), 'error');
|
| 1792 |
return;
|
| 1793 |
}
|
| 1794 |
user_set_authmaps($account, array("authname_$module" => $name));
|
| 1795 |
}
|
| 1796 |
|
| 1797 |
|
| 1798 |
$form_state['uid'] = $account->uid;
|
| 1799 |
user_login_submit(array(), $form_state);
|
| 1800 |
}
|
| 1801 |
|
| 1802 |
function user_pass_reset_url($account) {
|
| 1803 |
$timestamp = REQUEST_TIME;
|
| 1804 |
return url("user/reset/$account->uid/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login), array('absolute' => TRUE));
|
| 1805 |
}
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
function user_cancel_url($account) {
|
| 1814 |
$timestamp = REQUEST_TIME;
|
| 1815 |
return url("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login), array('absolute' => TRUE));
|
| 1816 |
}
|
| 1817 |
|
| 1818 |
function user_pass_rehash($password, $timestamp, $login) {
|
| 1819 |
return md5($timestamp . $password . $login);
|
| 1820 |
}
|
| 1821 |
|
| 1822 |
function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) {
|
| 1823 |
_user_password_dynamic_validation();
|
| 1824 |
$admin = user_access('administer users');
|
| 1825 |
|
| 1826 |
$form = array();
|
| 1827 |
|
| 1828 |
|
| 1829 |
$form['account'] = array('#type' => 'fieldset',
|
| 1830 |
'#title' => t('Account information'),
|
| 1831 |
'#weight' => -10,
|
| 1832 |
|
| 1833 |
|
| 1834 |
if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) {
|
| 1835 |
$form['account']['name'] = array('#type' => 'textfield',
|
| 1836 |
'#title' => t('Username'),
|
| 1837 |
'#default_value' => $edit['name'],
|
| 1838 |
'#maxlength' => USERNAME_MAX_LENGTH,
|
| 1839 |
'#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
|
| 1840 |
'#required' => TRUE,
|
| 1841 |
'#attributes' => array('class' => 'username'),
|
| 1842 |
|
| 1843 |
}
|
| 1844 |
$form['account']['mail'] = array('#type' => 'textfield',
|
| 1845 |
'#title' => t('E-mail address'),
|
| 1846 |
'#default_value' => $edit['mail'],
|
| 1847 |
'#maxlength' => EMAIL_MAX_LENGTH,
|
| 1848 |
'#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
|
| 1849 |
'#required' => TRUE,
|
| 1850 |
|
| 1851 |
if (!$register) {
|
| 1852 |
$form['account']['pass'] = array('#type' => 'password_confirm',
|
| 1853 |
'#description' => t('To change the current user password, enter the new password in both fields.'),
|
| 1854 |
'#size' => 25,
|
| 1855 |
|
| 1856 |
}
|
| 1857 |
elseif (!variable_get('user_email_verification', TRUE) || $admin) {
|
| 1858 |
$form['account']['pass'] = array(
|
| 1859 |
'#type' => 'password_confirm',
|
| 1860 |
'#description' => t('Provide a password for the new account in both fields.'),
|
| 1861 |
'#required' => TRUE,
|
| 1862 |
'#size' => 25,
|
| 1863 |
|
| 1864 |
}
|
| 1865 |
if ($admin) {
|
| 1866 |
$form['account']['status'] = array(
|
| 1867 |
'#type' => 'radios',
|
| 1868 |
'#title' => t('Status'),
|
| 1869 |
'#default_value' => isset($edit['status']) ? $edit['status'] : 1,
|
| 1870 |
'#options' => array(t('Blocked'), t('Active'))
|
| 1871 |
);
|
| 1872 |
}
|
| 1873 |
if (user_access('administer permissions')) {
|
| 1874 |
$roles = user_roles(TRUE);
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
'#type' => 'checkbox',
|
| 1883 |
'#title' => $roles[DRUPAL_AUTHENTICATED_RID],
|
| 1884 |
'#default_value' => TRUE,
|
| 1885 |
'#disabled' => TRUE,
|
| 1886 |
);
|
| 1887 |
|
| 1888 |
unset($roles[DRUPAL_AUTHENTICATED_RID]);
|
| 1889 |
if ($roles) {
|
| 1890 |
$default = empty($edit['roles']) ? array() : array_keys($edit['roles']);
|
| 1891 |
$form['account']['roles'] = array(
|
| 1892 |
'#type' => 'checkboxes',
|
| 1893 |
'#title' => t('Roles'),
|
| 1894 |
'#default_value' => $default,
|
| 1895 |
'#options' => $roles,
|
| 1896 |
DRUPAL_AUTHENTICATED_RID => $checkbox_authenticated,
|
| 1897 |
|
| 1898 |
}
|
| 1899 |
}
|
| 1900 |
|
| 1901 |
|
| 1902 |
if (variable_get('user_signatures', 0) && module_exists('comment') && !$register) {
|
| 1903 |
$form['signature_settings'] = array(
|
| 1904 |
'#type' => 'fieldset',
|
| 1905 |
'#title' => t('Signature settings'),
|
| 1906 |
'#weight' => 1,
|
| 1907 |
|
| 1908 |
$form['signature_settings']['signature'] = array(
|
| 1909 |
'#type' => 'textarea',
|
| 1910 |
'#title' => t('Signature'),
|
| 1911 |
'#default_value' => $edit['signature'],
|
| 1912 |
'#description' => t('Your signature will be publicly displayed at the end of your comments.'),
|
| 1913 |
|
| 1914 |
}
|
| 1915 |
|
| 1916 |
|
| 1917 |
if (variable_get('user_pictures', 0) && !$register) {
|
| 1918 |
$form['picture'] = array(
|
| 1919 |
'#type' => 'fieldset',
|
| 1920 |
'#title' => t('Picture'),
|
| 1921 |
'#weight' => 1,
|
| 1922 |
|
| 1923 |
$form['picture']['picture'] = array(
|
| 1924 |
'#type' => 'value',
|
| 1925 |
'#value' => $edit['picture'],
|
| 1926 |
|
| 1927 |
$form['picture']['picture_current'] = array(
|
| 1928 |
'#markup' => theme('user_picture', (object)$edit),
|
| 1929 |
|
| 1930 |
$form['picture']['picture_delete'] = array(
|
| 1931 |
'#type' => 'checkbox',
|
| 1932 |
'#title' => t('Delete picture'),
|
| 1933 |
'#access' => !empty($edit['picture']->fid),
|
| 1934 |
'#description' => t('Check this box to delete your current picture.'),
|
| 1935 |
|
| 1936 |
$form['picture']['picture_upload'] = array(
|
| 1937 |
'#type' => 'file',
|
| 1938 |
'#title' => t('Upload picture'),
|
| 1939 |
'#size' => 48,
|
| 1940 |
'#description' => t('Your virtual face or picture. Maximum dimensions are %dimensions pixels and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) . ' ' . variable_get('user_picture_guidelines', ''),
|
| 1941 |
|
| 1942 |
$form['#validate'][] = 'user_validate_picture';
|
| 1943 |
}
|
| 1944 |
$form['#uid'] = $uid;
|
| 1945 |
|
| 1946 |
return $form;
|
| 1947 |
}
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
function user_cancel($edit, $uid, $method) {
|
| 1966 |
global $user;
|
| 1967 |
|
| 1968 |
$account = user_load($uid);
|
| 1969 |
|
| 1970 |
if (!$account) {
|
| 1971 |
drupal_set_message(t('The user account %id does not exist.', array('%id' => $uid)), 'error');
|
| 1972 |
watchdog('user', 'Attempted to cancel non-existing user account: %id.', array('%id' => $uid), WATCHDOG_ERROR);
|
| 1973 |
return;
|
| 1974 |
}
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
'title' => t('Cancelling account'),
|
| 1979 |
'operations' => array(),
|
| 1980 |
);
|
| 1981 |
batch_set($batch);
|
| 1982 |
|
| 1983 |
|
| 1984 |
module_invoke_all('user_cancel', $edit, $account, $method);
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
'title' => t('Cancelling user account'),
|
| 1989 |
|
| 1990 |
array('_user_cancel', array($edit, $account, $method)),
|
| 1991 |
),
|
| 1992 |
);
|
| 1993 |
batch_set($batch);
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
}
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
function _user_cancel($edit, $account, $method) {
|
| 2008 |
global $user;
|
| 2009 |
|
| 2010 |
|
| 2011 |
case 'user_cancel_block':
|
| 2012 |
case 'user_cancel_block_unpublish':
|
| 2013 |
default:
|
| 2014 |
|
| 2015 |
if (!empty($edit['user_cancel_notify'])) {
|
| 2016 |
_user_mail_notify('status_blocked', $account);
|
| 2017 |
}
|
| 2018 |
db_update('users')
|
| 2019 |
->fields(array('status' => 0))
|
| 2020 |
->condition('uid', $account->uid)
|
| 2021 |
->execute();
|
| 2022 |
drupal_set_message(t('%name has been disabled.', array('%name' => $account->name)));
|
| 2023 |
watchdog('user', 'Blocked user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);
|
| 2024 |
break;
|
| 2025 |
|
| 2026 |
case 'user_cancel_reassign':
|
| 2027 |
case 'user_cancel_delete':
|
| 2028 |
|
| 2029 |
if (!empty($edit['user_cancel_notify'])) {
|
| 2030 |
_user_mail_notify('status_canceled', $account);
|
| 2031 |
}
|
| 2032 |
db_delete('users')
|
| 2033 |
->condition('uid', $account->uid)
|
| 2034 |
->execute();
|
| 2035 |
db_delete('users_roles')
|
| 2036 |
->condition('uid', $account->uid)
|
| 2037 |
->execute();
|
| 2038 |
db_delete('authmap')
|
| 2039 |
->condition('uid', $account->uid)
|
| 2040 |
->execute();
|
| 2041 |
drupal_set_message(t('%name has been deleted.', array('%name' => $account->name)));
|
| 2042 |
watchdog('user', 'Deleted user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);
|
| 2043 |
break;
|
| 2044 |
}
|
| 2045 |
|
| 2046 |
|
| 2047 |
if ($account->uid == $user->uid) {
|
| 2048 |
|
| 2049 |
session_destroy();
|
| 2050 |
}
|
| 2051 |
|
| 2052 |
drupal_session_destroy_uid($account->uid);
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
cache_clear_all();
|
| 2057 |
}
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
function user_build_content($account) {
|
| 2069 |
$account->content = array();
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
$account->content += field_attach_view('user', $account);
|
| 2074 |
|
| 2075 |
module_invoke_all('user_view', $account);
|
| 2076 |
return $account->content;
|
| 2077 |
}
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
function user_mail($key, &$message, $params) {
|
| 2083 |
$language = $message['language'];
|
| 2084 |
$variables = user_mail_tokens($params['account'], $language);
|
| 2085 |
$message['subject'] .= _user_mail_text($key . '_subject', $language, $variables);
|
| 2086 |
$message['body'][] = _user_mail_text($key . '_body', $language, $variables);
|
| 2087 |
}
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
function _user_mail_text($key, $language = NULL, $variables = array()) {
|
| 2095 |
$langcode = isset($language) ? $language->language : NULL;
|
| 2096 |
|
| 2097 |
if ($admin_setting = variable_get('user_mail_' . $key, FALSE)) {
|
| 2098 |
|
| 2099 |
return strtr($admin_setting, $variables);
|
| 2100 |
}
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
case 'register_no_approval_required_subject':
|
| 2105 |
return t('Account details for !username at !site', $variables, array('langcode' => $langcode));
|
| 2106 |
case 'register_no_approval_required_body':
|
| 2107 |
return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, array('langcode' => $langcode));
|
| 2108 |
case 'register_admin_created_subject':
|
| 2109 |
return t('An administrator created an account for you at !site', $variables, array('langcode' => $langcode));
|
| 2110 |
case 'register_admin_created_body':
|
| 2111 |
return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, array('langcode' => $langcode));
|
| 2112 |
case 'register_pending_approval_subject':
|
| 2113 |
case 'register_pending_approval_admin_subject':
|
| 2114 |
return t('Account details for !username at !site (pending admin approval)', $variables, array('langcode' => $langcode));
|
| 2115 |
case 'register_pending_approval_body':
|
| 2116 |
return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\n\n\n-- !site team", $variables, array('langcode' => $langcode));
|
| 2117 |
case 'register_pending_approval_admin_body':
|
| 2118 |
return t("!username has applied for an account.\n\n!edit_uri", $variables, array('langcode' => $langcode));
|
| 2119 |
case 'password_reset_subject':
|
| 2120 |
return t('Replacement login information for !username at !site', $variables, array('langcode' => $langcode));
|
| 2121 |
case 'password_reset_body':
|
| 2122 |
return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables, array('langcode' => $langcode));
|
| 2123 |
case 'status_activated_subject':
|
| 2124 |
return t('Account details for !username at !site (approved)', $variables, array('langcode' => $langcode));
|
| 2125 |
case 'status_activated_body':
|
| 2126 |
return t("!username,\n\nYour account at !site has been activated.\n\nYou may now log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\nOnce you have set your own password, you will be able to log in to !login_uri in the future using:\n\nusername: !username\n", $variables, array('langcode' => $langcode));
|
| 2127 |
case 'status_blocked_subject':
|
| 2128 |
return t('Account details for !username at !site (blocked)', $variables, array('langcode' => $langcode));
|
| 2129 |
case 'status_blocked_body':
|
| 2130 |
return t("!username,\n\nYour account on !site has been blocked.", $variables, array('langcode' => $langcode));
|
| 2131 |
|
| 2132 |
case 'cancel_confirm_subject':
|
| 2133 |
return t('Account cancellation request for !username at !site', $variables, array('langcode' => $langcode));
|
| 2134 |
case 'cancel_confirm_body':
|
| 2135 |
return t("!username,
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
This link expires in one day and nothing will happen if it is not used.", $variables, array('langcode' => $langcode));
|
| 2146 |
|
| 2147 |
case 'status_canceled_subject':
|
| 2148 |
return t('Account details for !username at !site (canceled)', $variables, array('langcode' => $langcode));
|
| 2149 |
case 'status_canceled_body':
|
| 2150 |
return t("!username,
|
| 2151 |
|
| 2152 |
Your account on !site has been canceled.", $variables, array('langcode' => $langcode));
|
| 2153 |
}
|
| 2154 |
|
| 2155 |
}
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
function user_roles($membersonly = FALSE, $permission = NULL) {
|
| 2173 |
|
| 2174 |
|
| 2175 |
DRUPAL_ANONYMOUS_RID => NULL,
|
| 2176 |
DRUPAL_AUTHENTICATED_RID => NULL,
|
| 2177 |
);
|
| 2178 |
|
| 2179 |
if (!empty($permission)) {
|
| 2180 |
$result = db_query("SELECT r.* FROM {role} r INNER JOIN {role_permission} p ON r.rid = p.rid WHERE p.permission = :permission ORDER BY r.name", array(':permission' => $permission));
|
| 2181 |
}
|
| 2182 |
|
| 2183 |
$result = db_query('SELECT * FROM {role} ORDER BY name');
|
| 2184 |
|
| 2185 |
|
| 2186 |
foreach ($result as $role) {
|
| 2187 |
switch ($role->rid) {
|
| 2188 |
|
| 2189 |
case DRUPAL_ANONYMOUS_RID:
|
| 2190 |
if (!$membersonly) {
|
| 2191 |
$roles[$role->rid] = t($role->name);
|
| 2192 |
}
|
| 2193 |
break;
|
| 2194 |
case DRUPAL_AUTHENTICATED_RID:
|
| 2195 |
$roles[$role->rid] = t($role->name);
|
| 2196 |
break;
|
| 2197 |
default:
|
| 2198 |
$roles[$role->rid] = $role->name;
|
| 2199 |
}
|
| 2200 |
}
|
| 2201 |
|
| 2202 |
|
| 2203 |
return array_filter($roles);
|
| 2204 |
}
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
function user_user_operations($form_state = array()) {
|
| 2210 |
|
| 2211 |
|
| 2212 |
'label' => t('Unblock the selected users'),
|
| 2213 |
'callback' => 'user_user_operations_unblock',
|
| 2214 |
),
|
| 2215 |
|
| 2216 |
'label' => t('Block the selected users'),
|
| 2217 |
'callback' => 'user_user_operations_block',
|
| 2218 |
),
|
| 2219 |
|
| 2220 |
'label' => t('Cancel the selected user accounts'),
|
| 2221 |
),
|
| 2222 |
);
|
| 2223 |
|
| 2224 |
if (user_access('administer permissions')) {
|
| 2225 |
$roles = user_roles(TRUE);
|
| 2226 |
unset($roles[DRUPAL_AUTHENTICATED_RID]); // Can't edit authenticated role.
|
| 2227 |
|
| 2228 |
$add_roles = array();
|
| 2229 |
foreach ($roles as $key => $value) {
|
| 2230 |
$add_roles['add_role-' . $key] = $value;
|
| 2231 |
}
|
| 2232 |
|
| 2233 |
$remove_roles = array();
|
| 2234 |
foreach ($roles as $key => $value) {
|
| 2235 |
$remove_roles['remove_role-' . $key] = $value;
|
| 2236 |
}
|
| 2237 |
|
| 2238 |
if (count($roles)) {
|
| 2239 |
|
| 2240 |
t('Add a role to the selected users') => array(
|
| 2241 |
'label' => $add_roles,
|
| 2242 |
),
|
| 2243 |
t('Remove a role from the selected users') => array(
|
| 2244 |
'label' => $remove_roles,
|
| 2245 |
),
|
| 2246 |
);
|
| 2247 |
|
| 2248 |
$operations += $role_operations;
|
| 2249 |
}
|
| 2250 |
}
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
if (!empty($form_state['submitted'])) {
|
| 2255 |
$operation_rid = explode('-', $form_state['values']['operation']);
|
| 2256 |
$operation = $operation_rid[0];
|
| 2257 |
if ($operation == 'add_role' || $operation == 'remove_role') {
|
| 2258 |
$rid = $operation_rid[1];
|
| 2259 |
if (user_access('administer permissions')) {
|
| 2260 |
$operations[$form_state['values']['operation']] = array(
|
| 2261 |
'callback' => 'user_multiple_role_edit',
|
| 2262 |
'callback arguments' => array($operation, $rid),
|
| 2263 |
|
| 2264 |
}
|
| 2265 |
|
| 2266 |
watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING);
|
| 2267 |
return;
|
| 2268 |
|
| 2269 |
}
|
| 2270 |
}
|
| 2271 |
|
| 2272 |
return $operations;
|
| 2273 |
}
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
function user_user_operations_unblock($accounts) {
|
| 2279 |
foreach ($accounts as $uid) {
|
| 2280 |
$account = user_load($uid);
|
| 2281 |
|
| 2282 |
if ($account !== FALSE && $account->status == 0) {
|
| 2283 |
user_save($account, array('status' => 1));
|
| 2284 |
}
|
| 2285 |
}
|
| 2286 |
}
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
function user_user_operations_block($accounts) {
|
| 2292 |
foreach ($accounts as $uid) {
|
| 2293 |
$account = user_load($uid);
|
| 2294 |
|
| 2295 |
if ($account !== FALSE && $account->status == 1) {
|
| 2296 |
user_save($account, array('status' => 0));
|
| 2297 |
}
|
| 2298 |
}
|
| 2299 |
}
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
function user_multiple_role_edit($accounts, $operation, $rid) {
|
| 2305 |
|
| 2306 |
|
| 2307 |
$role_name = db_query('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchField();
|
| 2308 |
|
| 2309 |
|
| 2310 |
case 'add_role':
|
| 2311 |
foreach ($accounts as $uid) {
|
| 2312 |
$account = user_load($uid);
|
| 2313 |
|
| 2314 |
if ($account !== FALSE && !isset($account->roles[$rid])) {
|
| 2315 |
$roles = $account->roles + array($rid => $role_name);
|
| 2316 |
user_save($account, array('roles' => $roles));
|
| 2317 |
}
|
| 2318 |
}
|
| 2319 |
break;
|
| 2320 |
case 'remove_role':
|
| 2321 |
foreach ($accounts as $uid) {
|
| 2322 |
$account = user_load($uid);
|
| 2323 |
|
| 2324 |
if ($account !== FALSE && isset($account->roles[$rid])) {
|
| 2325 |
$roles = array_diff($account->roles, array($rid => $role_name));
|
| 2326 |
user_save($account, array('roles' => $roles));
|
| 2327 |
}
|
| 2328 |
}
|
| 2329 |
break;
|
| 2330 |
}
|
| 2331 |
}
|
| 2332 |
|
| 2333 |
function user_multiple_cancel_confirm(&$form_state) {
|
| 2334 |
$edit = $form_state['input'];
|
| 2335 |
|
| 2336 |
$form['accounts'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
|
| 2337 |
|
| 2338 |
foreach (array_filter($edit['accounts']) as $uid => $value) {
|
| 2339 |
$user = db_query('SELECT name FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchField();
|
| 2340 |
$form['accounts'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '<li>', '#suffix' => check_plain($user) . "</li>\n");
|
| 2341 |
}
|
| 2342 |
|
| 2343 |
$form['operation'] = array('#type' => 'hidden', '#value' => 'cancel');
|
| 2344 |
|
| 2345 |
module_load_include('inc', 'user', 'user.pages');
|
| 2346 |
$form['user_cancel_method'] = array(
|
| 2347 |
'#type' => 'item',
|
| 2348 |
'#title' => t('When cancelling these accounts'),
|
| 2349 |
|
| 2350 |
$form['user_cancel_method'] += user_cancel_methods();
|
| 2351 |
|
| 2352 |
foreach (element_children($form['user_cancel_method']) as $element) {
|
| 2353 |
unset($form['user_cancel_method'][$element]['#description']);
|
| 2354 |
}
|
| 2355 |
|
| 2356 |
|
| 2357 |
$form['user_cancel_confirm'] = array(
|
| 2358 |
'#type' => 'checkbox',
|
| 2359 |
'#title' => t('Require e-mail confirmation to cancel account.'),
|
| 2360 |
'#default_value' => FALSE,
|
| 2361 |
'#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
|
| 2362 |
|
| 2363 |
|
| 2364 |
$form['user_cancel_notify'] = array(
|
| 2365 |
'#type' => 'checkbox',
|
| 2366 |
'#title' => t('Notify user when account is canceled.'),
|
| 2367 |
'#default_value' => FALSE,
|
| 2368 |
'#access' => variable_get('user_mail_status_canceled_notify', FALSE),
|
| 2369 |
'#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
|
| 2370 |
|
| 2371 |
|
| 2372 |
return confirm_form($form,
|
| 2373 |
t('Are you sure you want to cancel these user accounts?'),
|
| 2374 |
'admin/people', t('This action cannot be undone.'),
|
| 2375 |
t('Cancel accounts'), t('Cancel'));
|
| 2376 |
}
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
function user_multiple_cancel_confirm_submit($form, &$form_state) {
|
| 2385 |
global $user;
|
| 2386 |
|
| 2387 |
if ($form_state['values']['confirm']) {
|
| 2388 |
foreach ($form_state['values']['accounts'] as $uid => $value) {
|
| 2389 |
|
| 2390 |
if ($uid == $user->uid) {
|
| 2391 |
$admin_form_state = $form_state;
|
| 2392 |
unset($admin_form_state['values']['user_cancel_confirm']);
|
| 2393 |
$admin_form_state['values']['_account'] = $user;
|
| 2394 |
user_cancel_confirm_form_submit(array(), $admin_form_state);
|
| 2395 |
}
|
| 2396 |
|
| 2397 |
user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']);
|
| 2398 |
|
| 2399 |
}
|
| 2400 |
}
|
| 2401 |
$form_state['redirect'] = 'admin/people';
|
| 2402 |
return;
|
| 2403 |
}
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
function user_help($path, $arg) {
|
| 2409 |
global $user;
|
| 2410 |
|
| 2411 |
|
| 2412 |
case 'admin/help#user':
|
| 2413 |
$output = '<p>' . t('The user module allows users to register, login, and log out. Users benefit from being able to sign on because it associates content they create with their account and allows various permissions to be set for their roles. The user module supports user roles which establish fine grained permissions allowing each role to do only what the administrator wants them to. Each user is assigned to one or more roles. By default there are two roles <em>anonymous</em> - a user who has not logged in, and <em>authenticated</em> a user who has signed up and who has been authorized.') . '</p>';
|
| 2414 |
$output .= '<p>' . t("Users can use their own name or handle and can specify personal configuration settings through their individual <em>My account</em> page. Users must authenticate by supplying a local username and password or through their OpenID, an optional and secure method for logging into many websites with a single username and password. In some configurations, users may authenticate using a username and password from another Drupal site, or through some other site-specific mechanism.") . '</p>';
|
| 2415 |
$output .= '<p>' . t('A visitor accessing your website is assigned a unique ID, or session ID, which is stored in a cookie. The cookie does not contain personal information, but acts as a key to retrieve information from your site. Users should have cookies enabled in their web browser when using your site.') . '</p>';
|
| 2416 |
$output .= '<p>' . t('For more information, see the online handbook entry for <a href="@user">User module</a>.', array('@user' => 'http://drupal.org/handbook/modules/user/')) . '</p>';
|
| 2417 |
return $output;
|
| 2418 |
case 'admin/people/create':
|
| 2419 |
return '<p>' . t("This web page allows administrators to register new users. Users' e-mail addresses and usernames must be unique.") . '</p>';
|
| 2420 |
case 'admin/settings/permissions':
|
| 2421 |
return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href="@role">Roles</a> page to create a role). Two important roles to consider are Authenticated Users and Administrators. Any permissions granted to the Authenticated Users role will be given to any user who can log into your site. You can make any role the Administrator role for the site, meaning this will be granted all new permissions automatically. You can do this on the <a href="@settings">User Settings</a> page. You should be careful to ensure that only trusted users are given this access and level of control of your site.', array('@role' => url('admin/settings/roles'), '@settings' => url('admin/settings/user'))) . '</p>';
|
| 2422 |
case 'admin/settings/roles':
|
| 2423 |
return t('<p>Roles allow you to fine tune the security and administration of Drupal. A role defines a group of users that have certain privileges as defined in <a href="@permissions">user permissions</a>. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on. In this area you will define the <em>role names</em> of the various roles. To delete a role choose "edit".</p><p>By default, Drupal comes with two user roles:</p>
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
</ul>', array('@permissions' => url('admin/settings/permissions')));
|
| 2428 |
case 'admin/people/search':
|
| 2429 |
return '<p>' . t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda@example.com".') . '</p>';
|
| 2430 |
}
|
| 2431 |
}
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
function _user_categories() {
|
| 2437 |
$categories = module_invoke_all('user_categories');
|
| 2438 |
usort($categories, '_user_sort');
|
| 2439 |
|
| 2440 |
return $categories;
|
| 2441 |
}
|
| 2442 |
|
| 2443 |
function _user_sort($a, $b) {
|
| 2444 |
$a = (array)$a + array('weight' => 0, 'title' => '');
|
| 2445 |
$b = (array)$b + array('weight' => 0, 'title' => '');
|
| 2446 |
return $a['weight'] < $b['weight'] ? -1 : ($a['weight'] > $b['weight'] ? 1 : ($a['title'] < $b['title'] ? -1 : 1));
|
| 2447 |
}
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
function user_filters() {
|
| 2453 |
|
| 2454 |
$filters = array();
|
| 2455 |
$roles = user_roles(TRUE);
|
| 2456 |
unset($roles[DRUPAL_AUTHENTICATED_RID]); // Don't list authorized role.
|
| 2457 |
if (count($roles)) {
|
| 2458 |
$filters['role'] = array(
|
| 2459 |
'title' => t('role'),
|
| 2460 |
'field' => 'ur.rid',
|
| 2461 |
'options' => $roles,
|
| 2462 |
|
| 2463 |
}
|
| 2464 |
|
| 2465 |
$options = array();
|
| 2466 |
foreach (module_implements('permission') as $module) {
|
| 2467 |
$function = $module . '_permission';
|
| 2468 |
if ($permissions = $function('permission')) {
|
| 2469 |
asort($permissions);
|
| 2470 |
foreach ($permissions as $permission => $description) {
|
| 2471 |
$options[t('@module module', array('@module' => $module))][$permission] = t($permission);
|
| 2472 |
}
|
| 2473 |
}
|
| 2474 |
}
|
| 2475 |
ksort($options);
|
| 2476 |
$filters['permission'] = array(
|
| 2477 |
'title' => t('permission'),
|
| 2478 |
'options' => $options,
|
| 2479 |
|
| 2480 |
|
| 2481 |
$filters['status'] = array(
|
| 2482 |
'title' => t('status'),
|
| 2483 |
'field' => 'u.status',
|
| 2484 |
'options' => array(1 => t('active'), 0 => t('blocked')),
|
| 2485 |
|
| 2486 |
return $filters;
|
| 2487 |
}
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
function user_build_filter_query(SelectQuery $query) {
|
| 2496 |
$filters = user_filters();
|
| 2497 |
|
| 2498 |
|
| 2499 |
foreach (isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array() as $filter) {
|
| 2500 |
list($key, $value) = $filter;
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
if ($key == 'permission') {
|
| 2505 |
$account = new stdClass();
|
| 2506 |
$account->uid = 'user_filter';
|
| 2507 |
$account->roles = array(DRUPAL_AUTHENTICATED_RID => 1);
|
| 2508 |
if (user_access($value, $account)) {
|
| 2509 |
continue;
|
| 2510 |
}
|
| 2511 |
$query->leftJoin('role_permission', 'p', 'ur.rid = p.rid');
|
| 2512 |
$query->condition(db_or()->condition('u.uid', 1)->condition('p.permission', $value));
|
| 2513 |
}
|
| 2514 |
|
| 2515 |
$query->condition($filters[$key]['field'], $value);
|
| 2516 |
|
| 2517 |
}
|
| 2518 |
}
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
function user_forms() {
|
| 2524 |
$forms['user_admin_access_add_form']['callback'] = 'user_admin_access_form';
|
| 2525 |
$forms['user_admin_access_edit_form']['callback'] = 'user_admin_access_form';
|
| 2526 |
$forms['user_admin_new_role']['callback'] = 'user_admin_role';
|
| 2527 |
return $forms;
|
| 2528 |
}
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
function user_comment_view($comment) {
|
| 2534 |
if (variable_get('user_signatures', 0) && !empty($comment->signature)) {
|
| 2535 |
$comment->signature = check_markup($comment->signature, $comment->format);
|
| 2536 |
}
|
| 2537 |
|
| 2538 |
$comment->signature = '';
|
| 2539 |
|
| 2540 |
}
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
|
| 2547 |
function theme_user_signature($signature) {
|
| 2548 |
$output = '';
|
| 2549 |
if ($signature) {
|
| 2550 |
$output .= '<div class="clear">';
|
| 2551 |
$output .= '<div>—</div>';
|
| 2552 |
$output .= $signature;
|
| 2553 |
$output .= '</div>';
|
| 2554 |
}
|
| 2555 |
|
| 2556 |
return $output;
|
| 2557 |
}
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
function user_mail_tokens($account, $language) {
|
| 2571 |
global $base_url;
|
| 2572 |
|
| 2573 |
'!username' => $account->name,
|
| 2574 |
'!site' => variable_get('site_name', 'Drupal'),
|
| 2575 |
'!login_url' => user_pass_reset_url($account),
|
| 2576 |
'!cancel_url' => user_cancel_url($account),
|
| 2577 |
'!uri' => $base_url,
|
| 2578 |
'!uri_brief' => preg_replace('!^https?://!', '', $base_url),
|
| 2579 |
'!mailto' => $account->mail,
|
| 2580 |
'!date' => format_date(REQUEST_TIME, 'medium', '', NULL, $language->language),
|
| 2581 |
'!login_uri' => url('user', array('absolute' => TRUE, 'language' => $language)),
|
| 2582 |
'!edit_uri' => url('user/' . $account->uid . '/edit', array('absolute' => TRUE, 'language' => $language)),
|
| 2583 |
);
|
| 2584 |
if (!empty($account->password)) {
|
| 2585 |
$tokens['!password'] = $account->password;
|
| 2586 |
}
|
| 2587 |
return $tokens;
|
| 2588 |
}
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
function user_preferred_language($account, $default = NULL) {
|
| 2604 |
$language_list = language_list();
|
| 2605 |
if ($account->language && isset($language_list[$account->language])) {
|
| 2606 |
return $language_list[$account->language];
|
| 2607 |
}
|
| 2608 |
|
| 2609 |
return $default ? $default : language_default();
|
| 2610 |
|
| 2611 |
}
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
function _user_mail_notify($op, $account, $language = NULL) {
|
| 2640 |
|
| 2641 |
$default_notify = ($op != 'status_canceled' && $op != 'status_blocked');
|
| 2642 |
$notify = variable_get('user_mail_' . $op . '_notify', $default_notify);
|
| 2643 |
if ($notify) {
|
| 2644 |
$params['account'] = $account;
|
| 2645 |
$language = $language ? $language : user_preferred_language($account);
|
| 2646 |
$mail = drupal_mail('user', $op, $account->mail, $language, $params);
|
| 2647 |
if ($op == 'register_pending_approval') {
|
| 2648 |
|
| 2649 |
|
| 2650 |
drupal_mail('user', 'register_pending_approval_admin', variable_get('site_mail', ini_get('sendmail_from')), language_default(), $params);
|
| 2651 |
}
|
| 2652 |
}
|
| 2653 |
return empty($mail) ? NULL : $mail['result'];
|
| 2654 |
}
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
function _user_password_dynamic_validation() {
|
| 2664 |
static $complete = FALSE;
|
| 2665 |
global $user;
|
| 2666 |
|
| 2667 |
if (!$complete) {
|
| 2668 |
drupal_add_js(drupal_get_path('module', 'user') . '/user.js');
|
| 2669 |
|
| 2670 |
drupal_add_js(array(
|
| 2671 |
|
| 2672 |
'strengthTitle' => t('Password strength:'),
|
| 2673 |
'hasWeaknesses' => t('To make your password stronger:'),
|
| 2674 |
'tooShort' => t('Make it at least 6 characters'),
|
| 2675 |
'addLowerCase' => t('Add lowercase letters'),
|
| 2676 |
'addUpperCase' => t('Add uppercase letters'),
|
| 2677 |
'addNumbers' => t('Add numbers'),
|
| 2678 |
'addPunctuation' => t('Add punctuation'),
|
| 2679 |
'sameAsUsername' => t('Make it different from your username'),
|
| 2680 |
'confirmSuccess' => t('yes'),
|
| 2681 |
'confirmFailure' => t('no'),
|
| 2682 |
'confirmTitle' => t('Passwords match:'),
|
| 2683 |
'username' => (isset($user->name) ? $user->name : ''))),
|
| 2684 |
'setting');
|
| 2685 |
$complete = TRUE;
|
| 2686 |
}
|
| 2687 |
}
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
function user_node_load($nodes, $types) {
|
| 2693 |
|
| 2694 |
$uids = array();
|
| 2695 |
foreach ($nodes as $nid => $node) {
|
| 2696 |
$uids[$nid] = $node->uid;
|
| 2697 |
}
|
| 2698 |
|
| 2699 |
|
| 2700 |
$user_fields = db_query("SELECT uid, name, picture, data FROM {users} WHERE uid IN (:uids)", array(':uids' => $uids))->fetchAllAssoc('uid');
|
| 2701 |
|
| 2702 |
|
| 2703 |
foreach ($uids as $nid => $uid) {
|
| 2704 |
$nodes[$nid]->name = $user_fields[$uid]->name;
|
| 2705 |
$nodes[$nid]->picture = $user_fields[$uid]->picture;
|
| 2706 |
$nodes[$nid]->data = $user_fields[$uid]->data;
|
| 2707 |
}
|
| 2708 |
}
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
function user_image_style_delete($style) {
|
| 2714 |
|
| 2715 |
|
| 2716 |
user_image_style_save($style);
|
| 2717 |
}
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
function user_image_style_save($style) {
|
| 2723 |
|
| 2724 |
if (isset($style['old_name']) && $style['old_name'] == variable_get('user_picture_style', '')) {
|
| 2725 |
variable_set('user_picture_style', $style['name']);
|
| 2726 |
}
|
| 2727 |
}
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
function user_hook_info() {
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
'runs when' => t('After a user account has been created'),
|
| 2738 |
),
|
| 2739 |
|
| 2740 |
'runs when' => t("After a user's profile has been updated"),
|
| 2741 |
),
|
| 2742 |
|
| 2743 |
'runs when' => t('After a user has been deleted')
|
| 2744 |
),
|
| 2745 |
|
| 2746 |
'runs when' => t('After a user has logged in')
|
| 2747 |
),
|
| 2748 |
|
| 2749 |
'runs when' => t('After a user has logged out')
|
| 2750 |
),
|
| 2751 |
|
| 2752 |
'runs when' => t("When a user's profile is being viewed")
|
| 2753 |
),
|
| 2754 |
),
|
| 2755 |
),
|
| 2756 |
);
|
| 2757 |
}
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
function user_action_info() {
|
| 2763 |
|
| 2764 |
|
| 2765 |
'description' => t('Block current user'),
|
| 2766 |
'type' => 'user',
|
| 2767 |
'configurable' => FALSE,
|
| 2768 |
'hooks' => array(),
|
| 2769 |
),
|
| 2770 |
);
|
| 2771 |
}
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
function user_block_user_action(&$object, $context = array()) {
|
| 2778 |
if (isset($object->uid)) {
|
| 2779 |
$uid = $object->uid;
|
| 2780 |
}
|
| 2781 |
elseif (isset($context['uid'])) {
|
| 2782 |
$uid = $context['uid'];
|
| 2783 |
}
|
| 2784 |
|
| 2785 |
global $user;
|
| 2786 |
$uid = $user->uid;
|
| 2787 |
|
| 2788 |
db_update('users')
|
| 2789 |
->fields(array('status' => 0))
|
| 2790 |
->condition('uid', $uid)
|
| 2791 |
->execute();
|
| 2792 |
drupal_session_destroy_uid($uid);
|
| 2793 |
watchdog('action', 'Blocked user %name.', array('%name' => $user->name));
|
| 2794 |
}
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
function user_register_submit($form, &$form_state) {
|
| 2803 |
global $base_url;
|
| 2804 |
$admin = user_access('administer users');
|
| 2805 |
|
| 2806 |
$mail = $form_state['values']['mail'];
|
| 2807 |
$name = $form_state['values']['name'];
|
| 2808 |
if (!variable_get('user_email_verification', TRUE) || $admin) {
|
| 2809 |
$pass = $form_state['values']['pass'];
|
| 2810 |
}
|
| 2811 |
|
| 2812 |
$pass = user_password();
|
| 2813 |
|
| 2814 |
$notify = isset($form_state['values']['notify']) ? $form_state['values']['notify'] : NULL;
|
| 2815 |
$from = variable_get('site_mail', ini_get('sendmail_from'));
|
| 2816 |
if (isset($form_state['values']['roles'])) {
|
| 2817 |
|
| 2818 |
$roles = array_filter($form_state['values']['roles']);
|
| 2819 |
}
|
| 2820 |
|
| 2821 |
$roles = array();
|
| 2822 |
|
| 2823 |
|
| 2824 |
if (!$admin && array_intersect(array_keys($form_state['values']), array('uid', 'roles', 'init', 'session', 'status'))) {
|
| 2825 |
watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING);
|
| 2826 |
$form_state['redirect'] = 'user/register';
|
| 2827 |
return;
|
| 2828 |
}
|
| 2829 |
|
| 2830 |
|
| 2831 |
unset($form_state['values']['form_token'], $form_state['values']['submit'], $form_state['values']['op'], $form_state['values']['notify'], $form_state['values']['form_id'], $form_state['values']['affiliates'], $form_state['values']['destination'], $form_state['values']['form_build_id']);
|
| 2832 |
|
| 2833 |
$merge_data = array('pass' => $pass, 'init' => $mail, 'roles' => $roles);
|
| 2834 |
if (!$admin) {
|
| 2835 |
|
| 2836 |
$merge_data['status'] = variable_get('user_register', 1) == 1;
|
| 2837 |
}
|
| 2838 |
$account = user_save('', array_merge($form_state['values'], $merge_data));
|
| 2839 |
|
| 2840 |
if (!$account) {
|
| 2841 |
drupal_set_message(t("Error saving user account."), 'error');
|
| 2842 |
$form_state['redirect'] = '';
|
| 2843 |
return;
|
| 2844 |
}
|
| 2845 |
$form_state['user'] = $account;
|
| 2846 |
|
| 2847 |
watchdog('user', 'New user: %name (%email).', array('%name' => $name, '%email' => $mail), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));
|
| 2848 |
|
| 2849 |
|
| 2850 |
if ($account->uid == 1) {
|
| 2851 |
drupal_set_message(t('Welcome to Drupal. You are now logged in as user #1, which gives you full control over your website.'));
|
| 2852 |
if (variable_get('user_email_verification', TRUE)) {
|
| 2853 |
drupal_set_message(t('</p><p> Your password is <strong>%pass</strong>. You may change your password below.</p>', array('%pass' => $pass)));
|
| 2854 |
}
|
| 2855 |
|
| 2856 |
$form_state['values'] += $merge_data;
|
| 2857 |
user_authenticate(array_merge($form_state));
|
| 2858 |
|
| 2859 |
$form_state['redirect'] = 'user/1/edit';
|
| 2860 |
return;
|
| 2861 |
}
|
| 2862 |
|
| 2863 |
|
| 2864 |
$account->password = $pass;
|
| 2865 |
if ($admin && !$notify) {
|
| 2866 |
drupal_set_message(t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url("user/$account->uid"), '%name' => $account->name)));
|
| 2867 |
}
|
| 2868 |
elseif (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {
|
| 2869 |
|
| 2870 |
|
| 2871 |
_user_mail_notify('register_no_approval_required', $account);
|
| 2872 |
if (user_authenticate(array_merge($form_state['values'], $merge_data))) {
|
| 2873 |
drupal_set_message(t('Registration successful. You are now logged in.'));
|
| 2874 |
}
|
| 2875 |
$form_state['redirect'] = '';
|
| 2876 |
return;
|
| 2877 |
}
|
| 2878 |
elseif ($account->status || $notify) {
|
| 2879 |
|
| 2880 |
$op = $notify ? 'register_admin_created' : 'register_no_approval_required';
|
| 2881 |
_user_mail_notify($op, $account);
|
| 2882 |
if ($notify) {
|
| 2883 |
drupal_set_message(t('Password and further instructions have been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url("user/$account->uid"), '%name' => $account->name)));
|
| 2884 |
}
|
| 2885 |
|
| 2886 |
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
|
| 2887 |
$form_state['redirect'] = '';
|
| 2888 |
return;
|
| 2889 |
|
| 2890 |
}
|
| 2891 |
|
| 2892 |
|
| 2893 |
_user_mail_notify('register_pending_approval', $account);
|
| 2894 |
drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your e-mail address.'));
|
| 2895 |
$form_state['redirect'] = '';
|
| 2896 |
return;
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
}
|
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
function user_register() {
|
| 2910 |
global $user;
|
| 2911 |
|
| 2912 |
$admin = user_access('administer users');
|
| 2913 |
|
| 2914 |
|
| 2915 |
if (!$admin && $user->uid) {
|
| 2916 |
drupal_goto('user/' . $user->uid);
|
| 2917 |
}
|
| 2918 |
|
| 2919 |
|
| 2920 |
$form = user_edit_form($form_state, NULL, NULL, TRUE);
|
| 2921 |
if ($admin) {
|
| 2922 |
$form['account']['notify'] = array(
|
| 2923 |
'#type' => 'checkbox',
|
| 2924 |
'#title' => t('Notify user of new account')
|
| 2925 |
);
|
| 2926 |
|
| 2927 |
|
| 2928 |
$form['destination'] = array('#type' => 'hidden', '#value' => $_GET['q']);
|
| 2929 |
}
|
| 2930 |
|
| 2931 |
|
| 2932 |
$null = NULL;
|
| 2933 |
$extra = _user_forms($null, NULL, NULL, 'register');
|
| 2934 |
if ($extra) {
|
| 2935 |
$form = array_merge_recursive($form, $extra);
|
| 2936 |
}
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
if (count(element_children($form)) == 1) {
|
| 2943 |
$form['account']['#type'] = 'markup';
|
| 2944 |
}
|
| 2945 |
|
| 2946 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
|
| 2947 |
$form['#validate'][] = 'user_register_validate';
|
| 2948 |
|
| 2949 |
return $form;
|
| 2950 |
}
|
| 2951 |
|
| 2952 |
function user_register_validate($form, &$form_state) {
|
| 2953 |
user_module_invoke('validate', $form_state['values'], $form_state['values'], 'account');
|
| 2954 |
}
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
function _user_forms(&$edit, $account, $category, $hook = 'form') {
|
| 2960 |
$groups = array();
|
| 2961 |
foreach (module_implements('user_' . $hook) as $module) {
|
| 2962 |
$function = $module . '_user_' . $hook;
|
| 2963 |
if ($data = $function($edit, $account, $category)) {
|
| 2964 |
$groups = array_merge_recursive($data, $groups);
|
| 2965 |
}
|
| 2966 |
}
|
| 2967 |
uasort($groups, '_user_sort');
|
| 2968 |
|
| 2969 |
return empty($groups) ? FALSE : $groups;
|
| 2970 |
}
|
| 2971 |
|
| 2972 |
|