Added a events for the settings menu items
This commit is contained in:
parent
53c86c43c4
commit
91332cdadc
40
EVENTS.txt
40
EVENTS.txt
@ -162,6 +162,42 @@ StartAccountSettingsNav: Before showing the account settings menu
|
|||||||
EndAccountSettingsNav: After showing the account settings menu
|
EndAccountSettingsNav: After showing the account settings menu
|
||||||
- $action: the current action
|
- $action: the current action
|
||||||
|
|
||||||
|
StartAccountSettingsProfileMenuItem: Before showing the Profile menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
EndAccountSettingsProfileMenuItem: After showing the Profile menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
StartAccountSettingsAvatarMenuItem: Before showing the Avatar menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
EndAccountSettingsAvatarMenuItem: After showing the Avatar menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
StartAccountSettingsPasswordMenuItem: Before showing the Password menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
EndAccountSettingsPasswordMenuItem: After showing the Password menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
StartAccountSettingsEmailMenuItem: Before showing the Email menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
EndAccountSettingsEmailMenuItem: After showing the Email menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
StartAccountSettingsDesignMenuItem: Before showing the Design menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
EndAccountSettingsDesignMenuItem: After showing the Design menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
StartAccountSettingsOtherMenuItem: Before showing the Other menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
|
EndAccountSettingsOtherMenuItem: After showing the Other menu item
|
||||||
|
- $widget: AccountSettingsNav instance being shown
|
||||||
|
|
||||||
Autoload: When trying to autoload a class
|
Autoload: When trying to autoload a class
|
||||||
- $cls: the class being sought. A plugin might require_once the file for the class.
|
- $cls: the class being sought. A plugin might require_once the file for the class.
|
||||||
|
|
||||||
@ -499,10 +535,6 @@ StartChangePassword: Before changing a password
|
|||||||
EndChangePassword: After changing a password
|
EndChangePassword: After changing a password
|
||||||
- $nickname: user's nickname
|
- $nickname: user's nickname
|
||||||
|
|
||||||
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.
|
||||||
|
@ -104,35 +104,29 @@ class AccountSettingsNav extends Widget
|
|||||||
if (Event::handle('StartAccountSettingsNav', array(&$this->action))) {
|
if (Event::handle('StartAccountSettingsNav', array(&$this->action))) {
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
|
||||||
$menu = array();
|
if(Event::handle('StartAccountSettingsProfileMenuItem', array($this, &$menu))){
|
||||||
$menu['profilesettings'] =
|
$this->showMenuItem('profilesettings',_('Profile'),_('Change your profile settings'));
|
||||||
array(_('Profile'),
|
Event::handle('EndAccountSettingsProfileMenuItem', array($this, &$menu));
|
||||||
_('Change your profile settings'));
|
|
||||||
if(Event::handle('CanUserChangeField', array($user->nickname, 'avatar'))){
|
|
||||||
$menu['avatarsettings'] =
|
|
||||||
array(_('Avatar'),
|
|
||||||
_('Upload an avatar'));
|
|
||||||
}
|
}
|
||||||
if(Event::handle('CanUserChangeField', array($user->nickname, 'password'))){
|
if(Event::handle('StartAccountSettingsAvatarMenuItem', array($this, &$menu))){
|
||||||
$menu['passwordsettings'] =
|
$this->showMenuItem('avatarsettings',_('Avatar'),_('Upload an avatar'));
|
||||||
array(_('Password'),
|
Event::handle('EndAccountSettingsAvatarMenuItem', array($this, &$menu));
|
||||||
_('Change your password'));
|
|
||||||
}
|
}
|
||||||
$menu['emailsettings'] =
|
if(Event::handle('StartAccountSettingsPasswordMenuItem', array($this, &$menu))){
|
||||||
array(_('Email'),
|
$this->showMenuItem('passwordsettings',_('Password'),_('Change your password'));
|
||||||
_('Change email handling'));
|
Event::handle('EndAccountSettingsPasswordMenuItem', array($this, &$menu));
|
||||||
$menu['userdesignsettings'] =
|
}
|
||||||
array(_('Design'),
|
if(Event::handle('StartAccountSettingsEmailMenuItem', array($this, &$menu))){
|
||||||
_('Design your profile'));
|
$this->showMenuItem('emailsettings',_('Email'),_('Change email handling'));
|
||||||
$menu['othersettings'] =
|
Event::handle('EndAccountSettingsEmailMenuItem', array($this, &$menu));
|
||||||
array(_('Other'),
|
}
|
||||||
_('Other options'));
|
if(Event::handle('StartAccountSettingsDesignMenuItem', array($this, &$menu))){
|
||||||
|
$this->showMenuItem('userdesignsettings',_('Design'),_('Design your profile'));
|
||||||
foreach ($menu as $menuaction => $menudesc) {
|
Event::handle('EndAccountSettingsDesignMenuItem', array($this, &$menu));
|
||||||
$this->action->menuItem(common_local_url($menuaction),
|
}
|
||||||
$menudesc[0],
|
if(Event::handle('StartAccountSettingsOtherMenuItem', array($this, &$menu))){
|
||||||
$menudesc[1],
|
$this->showMenuItem('othersettings',_('Other'),_('Other options'));
|
||||||
$action_name === $menuaction);
|
Event::handle('EndAccountSettingsOtherMenuItem', array($this, &$menu));
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::handle('EndAccountSettingsNav', array(&$this->action));
|
Event::handle('EndAccountSettingsNav', array(&$this->action));
|
||||||
@ -140,4 +134,13 @@ class AccountSettingsNav extends Widget
|
|||||||
|
|
||||||
$this->action->elementEnd('ul');
|
$this->action->elementEnd('ul');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showMenuItem($menuaction, $desc1, $desc2)
|
||||||
|
{
|
||||||
|
$action_name = $this->action->trimmed('action');
|
||||||
|
$this->action->menuItem(common_local_url($menuaction),
|
||||||
|
$desc1,
|
||||||
|
$desc2,
|
||||||
|
$action_name === $menuaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,17 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|||||||
abstract class AuthPlugin extends Plugin
|
abstract class AuthPlugin extends Plugin
|
||||||
{
|
{
|
||||||
//is this plugin authoritative for authentication?
|
//is this plugin authoritative for authentication?
|
||||||
protected $authn_authoritative = false;
|
public $authn_authoritative = false;
|
||||||
|
|
||||||
//should accounts be automatically created after a successful login attempt?
|
//should accounts be automatically created after a successful login attempt?
|
||||||
protected $autoregistration = false;
|
public $autoregistration = false;
|
||||||
|
|
||||||
|
//can the user change their email address
|
||||||
|
public $email_changeable=true;
|
||||||
|
|
||||||
|
//can the user change their email address
|
||||||
|
public $password_changeable=true;
|
||||||
|
|
||||||
//------------Auth plugin should implement some (or all) of these methods------------\\
|
//------------Auth plugin should implement some (or all) of these methods------------\\
|
||||||
/**
|
/**
|
||||||
* Check if a nickname/password combination is valid
|
* Check if a nickname/password combination is valid
|
||||||
@ -102,44 +108,65 @@ abstract class AuthPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
function StartCheckPassword($nickname, $password, &$authenticatedUser){
|
function StartCheckPassword($nickname, $password, &$authenticatedUser){
|
||||||
$authenticated = $this->checkPassword($nickname, $password);
|
if($this->password_changeable){
|
||||||
if($authenticated){
|
$authenticated = $this->checkPassword($nickname, $password);
|
||||||
$authenticatedUser = User::staticGet('nickname', $nickname);
|
if($authenticated){
|
||||||
if(!$authenticatedUser && $this->autoregistration){
|
$authenticatedUser = User::staticGet('nickname', $nickname);
|
||||||
if($this->autoregister($nickname)){
|
if(!$authenticatedUser && $this->autoregistration){
|
||||||
$authenticatedUser = User::staticGet('nickname', $nickname);
|
if($this->autoregister($nickname)){
|
||||||
|
$authenticatedUser = User::staticGet('nickname', $nickname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
if($this->authn_authoritative){
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
//we're not authoritative, so let other handlers try
|
||||||
}else{
|
}else{
|
||||||
if($this->authn_authoritative){
|
if($this->authn_authoritative){
|
||||||
return false;
|
//since we're authoritative, no other plugin could do this
|
||||||
|
throw new Exception(_('Password changing is not allowed'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//we're not authoritative, so let other handlers try
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStartChangePassword($nickname,$oldpassword,$newpassword)
|
function onStartChangePassword($nickname,$oldpassword,$newpassword)
|
||||||
{
|
{
|
||||||
$authenticated = $this->checkPassword($nickname, $oldpassword);
|
if($this->password_changeable){
|
||||||
if($authenticated){
|
$authenticated = $this->checkPassword($nickname, $oldpassword);
|
||||||
$result = $this->changePassword($nickname,$oldpassword,$newpassword);
|
if($authenticated){
|
||||||
if($result){
|
$result = $this->changePassword($nickname,$oldpassword,$newpassword);
|
||||||
//stop handling of other handlers, because what was requested was done
|
if($result){
|
||||||
return false;
|
//stop handling of other handlers, because what was requested was done
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
throw new Exception(_('Password changing failed'));
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
throw new Exception(_('Password changing failed'));
|
if($this->authn_authoritative){
|
||||||
|
//since we're authoritative, no other plugin could do this
|
||||||
|
throw new Exception(_('Password changing failed'));
|
||||||
|
}else{
|
||||||
|
//let another handler try
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if($this->authn_authoritative){
|
if($this->authn_authoritative){
|
||||||
//since we're authoritative, no other plugin could do this
|
//since we're authoritative, no other plugin could do this
|
||||||
throw new Exception(_('Password changing failed'));
|
throw new Exception(_('Password changing is not allowed'));
|
||||||
}else{
|
|
||||||
//let another handler try
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onStartAccountSettingsPasswordMenuItem($widget)
|
||||||
|
{
|
||||||
|
if($this->authn_authoritative && !$this->password_changeable){
|
||||||
|
//since we're authoritative, no other plugin could change passwords, so do render the menu item
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,17 @@ require_once 'Net/LDAP2.php';
|
|||||||
|
|
||||||
class LdapPlugin extends AuthPlugin
|
class LdapPlugin extends AuthPlugin
|
||||||
{
|
{
|
||||||
|
public $host=null;
|
||||||
|
public $port=null;
|
||||||
|
public $version=null;
|
||||||
|
public $starttls=null;
|
||||||
|
public $binddn=null;
|
||||||
|
public $bindpw=null;
|
||||||
|
public $basedn=null;
|
||||||
|
public $options=null;
|
||||||
|
public $filter=null;
|
||||||
|
public $scope=null;
|
||||||
|
public $attributes=array();
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
@ -125,7 +136,7 @@ class LdapPlugin extends AuthPlugin
|
|||||||
$keys = array('host','port','version','starttls','binddn','bindpw','basedn','options','filter','scope');
|
$keys = array('host','port','version','starttls','binddn','bindpw','basedn','options','filter','scope');
|
||||||
foreach($keys as $key){
|
foreach($keys as $key){
|
||||||
$value = $this->$key;
|
$value = $this->$key;
|
||||||
if($value!==false){
|
if($value!==null){
|
||||||
$config[$key]=$value;
|
$config[$key]=$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ Installation
|
|||||||
============
|
============
|
||||||
add "addPlugin('ldap', array('setting'=>'value', 'setting2'=>'value2', ...);" to the bottom of your config.php
|
add "addPlugin('ldap', array('setting'=>'value', 'setting2'=>'value2', ...);" to the bottom of your config.php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Settings
|
Settings
|
||||||
========
|
========
|
||||||
authn_authoritative: Set to true if LDAP's responses are authoritative (meaning if LDAP fails, do check the any other plugins or the internal password database).
|
authn_authoritative (false): Set to true if LDAP's responses are authoritative (meaning if LDAP fails, do check the any other plugins or the internal password database).
|
||||||
autoregistration: Set to true if users should be automatically created when they attempt to login.
|
autoregistration (false): Set to true if users should be automatically created when they attempt to login.
|
||||||
|
email_changeable (true): Are users allowed to change their email address? (true or false)
|
||||||
|
password_changeable (true): Are users allowed to change their passwords? (true or false)
|
||||||
|
|
||||||
host*: LDAP server name to connect to. You can provide several hosts in an array in which case the hosts are tried from left to right.. See http://pear.php.net/manual/en/package.networking.net-ldap2.connecting.php
|
host*: LDAP server name to connect to. You can provide several hosts in an array in which case the hosts are tried from left to right.. See http://pear.php.net/manual/en/package.networking.net-ldap2.connecting.php
|
||||||
port: Port on the server. See http://pear.php.net/manual/en/package.networking.net-ldap2.connecting.php
|
port: Port on the server. See http://pear.php.net/manual/en/package.networking.net-ldap2.connecting.php
|
||||||
@ -30,12 +30,15 @@ attributes: an array with the key being the StatusNet user attribute name, and t
|
|||||||
location
|
location
|
||||||
|
|
||||||
* required
|
* required
|
||||||
|
default values are in (parenthesis)
|
||||||
|
|
||||||
Example
|
Example
|
||||||
=======
|
=======
|
||||||
Here's an example of an LDAP plugin configuration that connects to Microsoft Active Directory.
|
Here's an example of an LDAP plugin configuration that connects to Microsoft Active Directory.
|
||||||
|
|
||||||
addPlugin('ldap', array(
|
addPlugin('ldap', array(
|
||||||
|
'authn_authoritative'=>true,
|
||||||
|
'autoregistration'=>true,
|
||||||
'binddn'=>'username',
|
'binddn'=>'username',
|
||||||
'bindpw'=>'password',
|
'bindpw'=>'password',
|
||||||
'basedn'=>'OU=Users,OU=StatusNet,OU=US,DC=americas,DC=global,DC=loc',
|
'basedn'=>'OU=Users,OU=StatusNet,OU=US,DC=americas,DC=global,DC=loc',
|
||||||
|
Loading…
Reference in New Issue
Block a user