0

I'ld like to make a sub admin be able to change other user's passwords depending on other user's role or uid.

The sub admin should be able to type the password by himself. Emailing a generated password is unfortunatley no optionn since the aimed user accounts will be used by a quite loose group of people (teachers and pupils, sub admin wants to change password every school year).

Until now there are only very few different accounts where that needs to happen. So can I maybe do that with uids?

Is it maybe possible to build a block that provides a form with password fields of the desired users? What hooks or forms would I need to use or alter then?

Any idea and/or explanation is very much appreciated!

  • 3
    I don't think that sharing account between many people will ever be a good idea. I've seen quite a lot of teenage drama when one person that was using it posted something abusive and teacher punished everybody for it (as no one wanted to take the blame personally). Ever considered Organic Groups approach and one user per, well, one user? Anyway, writing own module with Form API form for new password should be relatively easy, and then you could set permissions whatever way you want. – Mołot Oct 11 '13 at 14:08
  • 1
    I understand your consideration. In the present case these accounts ain't able to do anything except accessing one restricted page to download papers for homework (pupils) and upload papers for homework (teachers). – leymannx Oct 11 '13 at 14:38
  • 1
    So the pupil password is basically unneeded, as after a week it'll be known by pupils, their parents, siblings, everybody and their dog ;) and teachers are able to upload, so problem of responsibility still exists. – Mołot Oct 11 '13 at 14:40
  • Might be possible, but since in this case it's a school for advanced age adult education it's not very likely. They just want to have it easy. Neither pupils nor teachers are very much used to the internet. – leymannx Oct 11 '13 at 14:50
1

How about creating a custom block with content as a form.The form may have three fields password,confirm password and a select list of users for whom the sub admin wants to change the password.

How you will get users as options in the form?

  • You have to narrow down "certain" word may with a user role,if so this link will be helpful in getting user by roles.Once you get them use uid as key and user name as value for select list option in the form.

How you will make this block accessible to sub admin only?

  • I guess block access module can be helpful here.
  • OR if you want to go for coding way you can define a permission using hook_permission() and can then check permission using user_access() inside hook_block_vew().

How to update the user password with this form?

  • Your form submit handler will be picking uid of the selected user and password and then have to call user_save() with required function parameters.You can cehck this link
  • I don't recommend doing this because of security issues. The user with this power will also be able to modify the list itself nad change any password. – jmary Nov 17 '16 at 13:51
2

Thanks to arpitr and my coworker J., I finally did it with a form on a page which is accessible only to selected roles via hook_permission(). The desired array() of uid=>name of that certain role to pass on as select list #option comes from db_select(), which definitely was the most difficult thing to get:

function _get_users_by_role($role_name) {
  $query = db_select('users', 'u')
    ->fields('u', array('uid', 'name'));

  $query->innerJoin('users_roles', 'ur', 'u.uid = ur.uid');
  $query->innerJoin('role', 'r', 'ur.rid = r.rid');
  $query->condition('r.name', $role_name);

  $result = $query->execute()->fetchAllKeyed();

  return ($result) ? $result : array();
}

For those interested in the custom block approach arpitr proposed, check the accepted answer on How can I display a change password form on its own? for a even more detailed description.

-1

Take a look http://drupal-create-sub-administrators.blogspot.com/ .. this may meet your needs. Allows creation of sub-admins that can manage other lower level sub-admins or regular users including editing of user info (just like the user herself can).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.