Jag vet att detta varit uppe tidigare, men jag måste ställa frågan igen
(för jag lyckas inte få till det jag vill göra)
Denna gång gäller det D7. Jag ska bygga en ny hemsida för en förening och den ska vara så pass enkel (statisk) att jag väljer att göra den i D7.
Men jag har en speciell sak jag vill göra och det är följande:
Det skall finnas ett antal inloggningsprofiler och en av dem ska användas av många.
Då vill jag hindra möjligheten att byta lösenord och e-post på denna profil.
Alltså inte heller profilen själv skall kunna ändra.
Har läst och försökt förstått flera beskrivningar av detta och då nämns modulen 'userprotect' ofta.
Men det funkar inte som jag vill.
Så, är det någon som har den där självklara lösningen på detta? :-)
För det är säkert tokenkelt, men jag har inte lyckats lösa det.
Tack på förhand
/Thomas
Comments
Jag har testat lite
Jag hittade denna lösning som jag provar med. Den verkar ju fungera, men jag får en del felmeddelanden som någon kanske kan hjälpa mig tyda.
* Notice: Undefined index: _account i restrict_password_change_form_alter() (rad 40 av /home/musikpal/public_html/dpsite/sites/all/modules/restrict_password_change/restrict_password_change.module).* Notice: Trying to get property of non-object i restrict_password_change_form_alter() (rad 40 av /home/musikpal/public_html/dpsite/sites/all/modules/restrict_password_change/restrict_password_change.module).
* Notice: Undefined index: _account i restrict_password_change_form_alter() (rad 66 av /home/musikpal/public_html/dpsite/sites/all/modules/restrict_password_change/restrict_password_change.module).
* Notice: Trying to get property of non-object i restrict_password_change_form_alter() (rad 66 av /home/musikpal/public_html/dpsite/sites/all/modules/restrict_password_change/restrict_password_change.module).
Koden/modulen jag använder ser ut så här:
<?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['_account']['#value']->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;
}
}
// 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['_account']['#value']->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;
}
}
Lägg upp detta som ett issue
Lägg upp detta som ett issue i Issue-kön för modulen. Kolla hur formuläret ser ut, stämmer verkligen koden som addresserar lösenord etc i form_alter? $form['account']['pass']['#access'] = FALSE;
//Pontus Nilsson, Digitalist
En kommentar jag glömde
En väldigt enkel lösning vore ju att inte visa medlemssidan alls för denna profil.
För mig skulle det fungera bra.
Kanske finns ngn lösning för det??
Hoppas på ett enkelt tips :-)
/Thomas