* Admin/Preferences: changepassword hook was called twice

fixed by calling in now from API and not on every location in application code changing a password
This commit is contained in:
Ralf Becker 2013-10-25 19:24:01 +00:00
parent dd2465b317
commit e94502515d
5 changed files with 35 additions and 48 deletions

View File

@ -57,19 +57,6 @@ class admin_cmd_change_pw extends admin_cmd
// as long as the auth class is not throwing itself ...
throw new Exception(lang('Error changing the password for % !!!',$this->account),99);
}
$GLOBALS['hook_values']['account_id'] = $account_id;
$GLOBALS['hook_values']['account_lid'] = $this->account;
if (is_numeric($this->account))
{
admin_cmd::_instanciate_accounts();
$GLOBALS['hook_values']['account_lid'] = admin_cmd::$accounts->id2name($this->account);
}
$GLOBALS['hook_values']['old_passwd'] = null;
$GLOBALS['hook_values']['new_passwd'] = $this->password;
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => 'changepassword'
),False,True); // called for every app now, not only enabled ones)
return lang('Password updated');
}

View File

@ -398,14 +398,6 @@
$auth = new auth();
if ($auth->change_password('', $passwd, $_userData['account_id']))
{
$GLOBALS['hook_values']['account_id'] = $_userData['account_id'];
$GLOBALS['hook_values']['old_passwd'] = '';
$GLOBALS['hook_values']['new_passwd'] = $passwd;
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => 'changepassword'
),False,True); // called for every app now, not only enabled ones)
if ($_userData['account_lastpwd_change']==0 || // AD requires to activate account AFTER setting pw
$new_account && $_userData['account_status'] == 'A' && $GLOBALS['egw']->accounts->require_password_for_enable())
{

View File

@ -230,14 +230,29 @@ class auth
{
throw new egw_exception_wrong_userinput($err);
}
if (($ret = $this->backend->change_password($old_passwd, $new_passwd, $account_id)) &&
($account_id == $GLOBALS['egw_info']['user']['account_id']))
if (($ret = $this->backend->change_password($old_passwd, $new_passwd, $account_id)))
{
if ($account_id == $GLOBALS['egw_info']['user']['account_id'])
{
// need to change current users password in session
egw_cache::setSession('phpgwapi', 'password', base64_encode($new_passwd));
$GLOBALS['egw_info']['user']['passwd'] = $new_passwd;
$GLOBALS['egw_info']['user']['account_lastpwd_change'] = egw_time::to('now','ts');
// invalidate EGroupware session, as password is stored in egw_info in session
egw::invalidate_session_cache();
}
accounts::cache_invalidate($account_id);
// run changepwasswd hook
$GLOBALS['hook_values'] = array(
'account_id' => $account_id,
'account_lid' => accounts::id2name($account_id),
'old_passwd' => $old_passwd,
'new_passwd' => $new_passwd,
);
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => 'changepassword'
),False,True); // called for every app now, not only enabled ones)
}
return $ret;
}

View File

@ -33,6 +33,12 @@
{
if (($ret = $GLOBALS['egw']->auth->change_password($old, $new, $GLOBALS['egw_info']['user']['account_id'])))
{
$GLOBALS['egw']->session->appsession('password','phpgwapi',base64_encode($new));
$GLOBALS['egw_info']['user']['passwd'] = $new;
$GLOBALS['egw_info']['user']['account_lastpwd_change'] = egw_time::to('now','ts');
accounts::cache_invalidate($GLOBALS['egw_info']['user']['account_id']);
egw::invalidate_session_cache();
//_debug_array( $GLOBALS['egw_info']['user']);
$GLOBALS['hook_values']['account_id'] = $GLOBALS['egw_info']['user']['account_id'];
$GLOBALS['hook_values']['old_passwd'] = $old;
$GLOBALS['hook_values']['new_passwd'] = $new;

View File

@ -97,7 +97,8 @@ class uipassword
if (!$errors)
{
try {
$passwd_changed = $this->bo->changepass($o_passwd, $n_passwd);
$passwd_changed = $GLOBALS['egw']->auth->change_password($o_passwd, $n_passwd,
$GLOBALS['egw_info']['user']['account_id']);
}
catch (Exception $e) {
$errors[] = $e->getMessage();
@ -117,20 +118,6 @@ class uipassword
}
else
{
$GLOBALS['egw']->session->appsession('password','phpgwapi',base64_encode($n_passwd));
$GLOBALS['egw_info']['user']['passwd'] = $n_passwd;
$GLOBALS['egw_info']['user']['account_lastpwd_change'] = egw_time::to('now','ts');
accounts::cache_invalidate($GLOBALS['egw_info']['user']['account_id']);
egw::invalidate_session_cache();
//_debug_array( $GLOBALS['egw_info']['user']);
$GLOBALS['hook_values']['account_id'] = $GLOBALS['egw_info']['user']['account_id'];
$GLOBALS['hook_values']['old_passwd'] = $o_passwd;
$GLOBALS['hook_values']['new_passwd'] = $n_passwd;
// called for every app now, not only for the ones enabled for the user
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => 'changepassword',
),False,True);
if ($GLOBALS['egw_info']['user']['apps']['preferences'])
{
egw::redirect_link('/preferences/index.php','cd=18');