You are here

function roleassign_user in RoleAssign 6

Same name and namespace in other branches
  1. 5 roleassign.module \roleassign_user()

Implementation of hook_user().

Replace the validation of the user form field 'roles' by using another user form field 'roleassign_roles'. Copies the form field roleassign_roles into form field roles on insert or submit.

File

./roleassign.module, line 210
Allows site administrators to further delegate the task of managing user's roles.

Code

function roleassign_user($type, &$edit, &$user, $category = NULL) {

  // If this isn't the account category, or there is no roleassign_roles
  // field, there isn't much to do.
  if ($category != 'account' || !isset($edit['roleassign_roles'])) {
    return;
  }

  // If someone is trying to update user's roles, it's a malicious
  // attempt to alter user's roles.
  if ($type == 'validate' && !user_access('assign roles')) {
    watchdog('security', 'Detected malicious attempt to alter user\'s roles.', array(), WATCHDOG_WARNING);
    form_set_error('category', t('Detected malicious attempt to alter user\'s roles.'));
  }

  // On submit, copy sticky and assigned roles from 'roleassign_roles'
  // to 'roles'.
  if ($type == 'insert' || $type == 'submit') {
    $edit['roles'] = array_filter(_roleassign_sticky_roles() + $edit['roleassign_roles']);
  }
}