[gelöst]User soll nur sein Passwort ändern dürfen
am 10.10.2012 - 08:16 Uhr in
Moin zusammen,
ich möchte gerne das die User nur ihr Passwort ändern dürfen, wenn sie in ihre Kontenbearbeitung gehen (Admin und Rolle EDV ausgenommen).
Ich habe dann das Modul restrict_password_change gefunden. Dies hatte kleinere Fehlermeldungen und hat nicht ganz das gemacht was ich wollte.
Also habe ich den Code etwas modifiziert...soweit passt alles, der User kann aber immer noch Spracheinstellungen und die Regionaleinstellungen ändern.
Letzteres dachte ich unter "timezone" abschalten zu können, aber das geht nicht. Hat hier jemand eine Idee...hier mal der Quellcode wie er aktuell aussieht
(bissl was experimentelles ist noch drin)
<?php
// $Id: restrict_password_change.module,v 1.4.2.1 2009/09/10 04:26:07 jrglasgow Exp $
// by James Glasgow - Tribute Media - http://www.tributemedia.com
/**
* Implementation of hook_permission().
*/
function restrict_password_change_permission() {
return array(
'change other users password' => array(
'title' => t('Change user\'s password'),
'description' => t('Change the passwords of users of the site.'),
),
'change other users username' => array(
'title' => t('Change user\'s user name'),
'description' => t('Change another user\'s user name.'),
),
'change other users email' => array(
'title' => t('Change user\'s e-mail'),
'description' => t('Change the e-mail address of any of the site\'s users.'),
),
'delete other users' => array(
'title' => t('Delete users'),
'description' => t('Delete the accounts of other users.'),
),
'block other users' => array(
'title' => t('Block users'),
'description' => t('Block users from the site.'),
),
);
}
/**
* Implementation of hook_form_alter().
*/
function restrict_password_change_form_alter(&$form, &$form_state, $form_id) {
global $user;
switch ($form_id) {
case 'user_profile_form':
if ($user->uid != $form['#user']->uid) {
if (!user_access('change other users password')) {
// password cannot be changed
$form['account']['pass']['#access'] = FALSE;
}
if (!user_access('change other users username')) {
// username cannot be changed
$form['account']['name']['#access'] = FALSE;
}
if (!user_access('block other users')) {
// user cannot be blocked
$form['account']['status']['#access'] = FALSE;
}
if (!user_access('change other users email')) {
// e-mail address cannot be changed
$form['account']['mail']['#access'] = FALSE;
}
if (!user_access('delete other users')) {
// user cannot be deleted
$form['delete']['#access'] = FALSE;
}
}
if($user->uid == $form['#user']->uid) {
$form['account']['name']['#access'] = FALSE;
$form['account']['status']['#access'] = FALSE;
$form['account']['mail']['#access'] = FALSE;
$form['picture']['#access'] = FALSE;
$form['account']['timezone']['#access'] = FALSE;
$form['delete']['#access'] = FALSE;
}
// check to see if the form is for the current user or if they have permission
// check if user 1 - if not, prevent changing user 1 account
// regardless of permission to 'change other users password'
if (($user->uid != 1) &&
($form['#user']->uid == 1)) {
$form['account']['#access'] = FALSE;
$form['theme_select']['#access'] = FALSE;
$form['contact']['#access'] = FALSE;
$form['submit']['#access'] = FALSE;
$form['timezone']['#access'] = FALSE;
$form['messaging']['#access'] = FALSE;
$form['delete']['#access'] = FALSE;
} // protect admin usr 1
break;
}
}Auch wenn ich die Zeile
$form['account']['timezone']['#access'] = FALSE;
in
$form['timezone']['#access'] = FALSE;
ändere bleibt die Regionaleinstellungen änderbar.
- Anmelden oder Registrieren um Kommentare zu schreiben

Hmm die Regiopnaleinstellung
am 10.10.2012 - 08:53 Uhr
Hmm die Regiopnaleinstellung kann man unter admin/config/regional/settings ändern.
Die Spracheinstellungen kann man z.B. mit
unset($form['locale']);ausschalten