Skip to content

Commit

Permalink
Move password change handling to authenticaton plugins
Browse files Browse the repository at this point in the history
We should not care about plugin type while changing password, we should
just notify it and the plugin should be responsible for anything needed.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 12, 2014
1 parent 209390c commit bd4cccc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
12 changes: 12 additions & 0 deletions libraries/plugins/AuthenticationPlugin.class.php
Expand Up @@ -79,5 +79,17 @@ public function getErrorMessage()
}
}
}

/**
* Callback when user changes password.
*
* @param string $password New password to set
*
* @return array Additional URL parameters.
*/
public function handlePasswordChange($password)
{
return array();
}
}
?>
13 changes: 13 additions & 0 deletions libraries/plugins/auth/AuthenticationCookie.class.php
Expand Up @@ -787,6 +787,19 @@ public function setIV($vector)
$this->_cookie_iv = $vector;
}

/**
* Callback when user changes password.
*
* @param string $password New password to set
*
* @return array Additional URL parameters.
*/
public function handlePasswordChange($password)
{
$this->storePasswordCookie($password);
return array();
}

/**
* This method is called when any PluginManager to which the observer
* is attached calls PluginManager::notify()
Expand Down
12 changes: 12 additions & 0 deletions libraries/plugins/auth/AuthenticationHttp.class.php
Expand Up @@ -250,6 +250,18 @@ public function authFails()
}
}

/**
* Callback when user changes password.
*
* @param string $password New password to set
*
* @return array Additional URL parameters.
*/
public function handlePasswordChange($password)
{
return array('old_usr' => 'relog');
}

/**
* This method is called when any PluginManager to which the observer
* is attached calls PluginManager::notify()
Expand Down
40 changes: 4 additions & 36 deletions user_password.php
Expand Up @@ -128,6 +128,8 @@ function PMA_setChangePasswordMsg()
*/
function PMA_changePassword($password, $message, $change_password_message)
{
global $auth_plugin;

// Defines the url to return to in case of error in the sql statement
$_url_params = array();
$hashing_function = PMA_changePassHashingFunction();
Expand All @@ -137,9 +139,9 @@ function PMA_changePassword($password, $message, $change_password_message)
$password, $_url_params, $sql_query, $hashing_function
);

$new_url_params = PMA_changePassAuthType($_url_params, $password);
$url_params = $auth_plugin->handlePasswordChange($password);
PMA_getChangePassMessage($change_password_message, $sql_query);
PMA_changePassDisplayPage($message, $sql_query, $new_url_params);
PMA_changePassDisplayPage($message, $sql_query, $url_params);
}

/**
Expand Down Expand Up @@ -179,40 +181,6 @@ function PMA_changePassUrlParamsAndSubmitQuery(
}
}

/**
* Change password authentication type
*
* @param array $_url_params URL parameters
* @param string $password Password
*
* @return array $_url_params
*/
function PMA_changePassAuthType($_url_params, $password)
{
/**
* Changes password cookie if required
* Duration = till the browser is closed for password
* (we don't want this to be saved)
*/

// include_once "libraries/plugins/auth/AuthenticationCookie.class.php";
// $auth_plugin = new AuthenticationCookie();
// the $auth_plugin is already defined in common.inc.php when this is used
global $auth_plugin;

if ($GLOBALS['cfg']['Server']['auth_type'] == 'cookie') {
$auth_plugin->storePasswordCookie($password);
}
/**
* For http auth. mode, the "back" link will also enforce new
* authentication
*/
if ($GLOBALS['cfg']['Server']['auth_type'] == 'http') {
$_url_params['old_usr'] = 'relog';
}
return $_url_params;
}

/**
* Display the page
*
Expand Down

0 comments on commit bd4cccc

Please sign in to comment.