Add a new event: CanUserChangeField
This commit is contained in:
parent
22310d17a4
commit
3be1205714
|
@ -489,6 +489,10 @@ ChangePassword: Handle a password change request
|
||||||
- $newpassword: the desired new password
|
- $newpassword: the desired new password
|
||||||
- &$errormsg: set this to an error message if the password could not be changed. If the password was changed, leave this as false
|
- &$errormsg: set this to an error message if the password could not be changed. If the password was changed, leave this as false
|
||||||
|
|
||||||
|
CanUserChangeField: Determines if a user is allowed to change a specific profile field
|
||||||
|
- $nickname: nickname of the user who would like to know which of their profile fields are mutable
|
||||||
|
- $field: name of the field the user wants to change (nickname, fullname, password, avatar, etc)
|
||||||
|
|
||||||
UserDeleteRelated: Specify additional tables to delete entries from when deleting users
|
UserDeleteRelated: Specify additional tables to delete entries from when deleting users
|
||||||
- $user: User object
|
- $user: User object
|
||||||
- &$related: array of DB_DataObject class names to delete entries on matching user_id.
|
- &$related: array of DB_DataObject class names to delete entries on matching user_id.
|
||||||
|
|
|
@ -58,6 +58,19 @@ class PasswordsettingsAction extends AccountSettingsAction
|
||||||
return _('Change password');
|
return _('Change password');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prepare($args){
|
||||||
|
parent::prepare($args);
|
||||||
|
|
||||||
|
$user = common_current_user();
|
||||||
|
|
||||||
|
Event::handle('CanUserChangeField', array($user->nickname, 'password'));
|
||||||
|
|
||||||
|
if(! $fields['password']){
|
||||||
|
//user is not allowed to change his password
|
||||||
|
$this->clientError(_('You are not allowed to change your password'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instructions for use
|
* Instructions for use
|
||||||
*
|
*
|
||||||
|
@ -86,6 +99,7 @@ class PasswordsettingsAction extends AccountSettingsAction
|
||||||
function showContent()
|
function showContent()
|
||||||
{
|
{
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
|
||||||
$this->elementStart('form', array('method' => 'POST',
|
$this->elementStart('form', array('method' => 'POST',
|
||||||
'id' => 'form_password',
|
'id' => 'form_password',
|
||||||
'class' => 'form_settings',
|
'class' => 'form_settings',
|
||||||
|
|
|
@ -102,26 +102,31 @@ class AccountSettingsNav extends Widget
|
||||||
$this->action->elementStart('ul', array('class' => 'nav'));
|
$this->action->elementStart('ul', array('class' => 'nav'));
|
||||||
|
|
||||||
if (Event::handle('StartAccountSettingsNav', array(&$this->action))) {
|
if (Event::handle('StartAccountSettingsNav', array(&$this->action))) {
|
||||||
|
$user = common_current_user();
|
||||||
|
|
||||||
$menu =
|
$menu = array();
|
||||||
array('profilesettings' =>
|
$menu['profilesettings'] =
|
||||||
array(_('Profile'),
|
array(_('Profile'),
|
||||||
_('Change your profile settings')),
|
_('Change your profile settings'));
|
||||||
'avatarsettings' =>
|
if(Event::handle('CanUserChangeField', array($user->nickname, 'avatar'))){
|
||||||
array(_('Avatar'),
|
$menu['avatarsettings'] =
|
||||||
_('Upload an avatar')),
|
array(_('Avatar'),
|
||||||
'passwordsettings' =>
|
_('Upload an avatar'));
|
||||||
array(_('Password'),
|
}
|
||||||
_('Change your password')),
|
if(Event::handle('CanUserChangeField', array($user->nickname, 'password'))){
|
||||||
'emailsettings' =>
|
$menu['passwordsettings'] =
|
||||||
|
array(_('Password'),
|
||||||
|
_('Change your password'));
|
||||||
|
}
|
||||||
|
$menu['emailsettings'] =
|
||||||
array(_('Email'),
|
array(_('Email'),
|
||||||
_('Change email handling')),
|
_('Change email handling'));
|
||||||
'userdesignsettings' =>
|
$menu['userdesignsettings'] =
|
||||||
array(_('Design'),
|
array(_('Design'),
|
||||||
_('Design your profile')),
|
_('Design your profile'));
|
||||||
'othersettings' =>
|
$menu['othersettings'] =
|
||||||
array(_('Other'),
|
array(_('Other'),
|
||||||
_('Other options')));
|
_('Other options'));
|
||||||
|
|
||||||
foreach ($menu as $menuaction => $menudesc) {
|
foreach ($menu as $menuaction => $menudesc) {
|
||||||
$this->action->menuItem(common_local_url($menuaction),
|
$this->action->menuItem(common_local_url($menuaction),
|
||||||
|
|
|
@ -102,4 +102,15 @@ class LdapPlugin extends Plugin
|
||||||
//return false, indicating that the event has been handled
|
//return false, indicating that the event has been handled
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCanUserChangeField($nickname, $field)
|
||||||
|
{
|
||||||
|
switch($field)
|
||||||
|
{
|
||||||
|
case 'password':
|
||||||
|
case 'nickname':
|
||||||
|
case 'email':
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user