I made this module from another forum topic. The purpose is to disable the changing of a user name and password. It does a great job at that. The only problem I have is when I want to create a new user as an administrator I have to disable this module. It is blocking any of the form fields included in the userchange module code, these fields are obviously crucial for making a user.

Does anyone know any drupal speficic code that can make this module be null for an administrator on the site? If not, does anyone know how to automatically disable this code when an administrator logs in?

<?php
function userchange_help($section) {
  switch ($section) {
    case 'admin/modules#description':
           return t('This prevents office users from changing their user name and password.');
  }
}

function userchange_user($op, &$edit, &$user, $category = NULL) {
  switch ($op) {
    case 'validate':
      //lets validate the user info
      if ($_POST['edit']['name'] != $user->name) {
          form_set_error('name', t('You cannot change your user name right now. Only an administrator can perform that task.'));
      }
	if ($_POST['edit']['pass1'] != $user->pass1) {
          form_set_error('pass1', t('You cannot change your password right now. Only an administrator can perform that task.'));
      }
	if ($_POST['edit']['pass2'] != $user->pass2) {
     }
      break;
  }
}
?>

Comments

blackburnandrew’s picture

My issue is fixed. I eventually figured out how to do it myself.

<?php
// $Id: userchange.module,v 1.0.1.0 2006/06/13 20:02:36 blackburnandrew Exp $

function userchange_help($section) {
  switch ($section) {
    case 'admin/modules#description':
           return t('Allows certain roles access to change user credentials.');
  }
}

function userchange_perm() {
  return array('perform credential change');
}

if (!user_access('perform credential change')) {
function userchange_user($op, &$edit, &$user, $category = NULL) {
  switch ($op) {
    case 'validate':
      if ($_POST['edit']['name'] != $user->name) {
          form_set_error('name', t('You do not have the permissions to change your user name <i>(%name)</i>. Only a site administrator can perform a credential change.', array('%name' => theme('placeholder', $user->name))));
      }
	if ($_POST['edit']['mail'] != $user->mail) {
          form_set_error('mail', t('You do not have the permissions to change your email address <i>(%mail)</i>. Only a site administrator can perform a credential change.', array('%mail' => theme('placeholder', $user->mail))));
      }
	if ($_POST['edit']['pass1'] != $user->pass1) {
          form_set_error('pass1', t('You do not have the permissions to change your password. Only a site administrator can perform a credential change.'));
      }
   break;
  }
 }
}
?>